linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arman Uguray <armansito@chromium.org>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: BlueZ development <linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCH v1 01/10] src/shared/att: Introduce struct bt_att.
Date: Tue, 13 May 2014 11:44:08 -0700	[thread overview]
Message-ID: <CAHrH25RubNJx89MabHvHQc8ZsymcdDB2VoNVxwEooHEDv2=ybA@mail.gmail.com> (raw)
In-Reply-To: <01CD59B6-44C7-425A-8686-82C428F41C87@holtmann.org>

Hi Marcel,

>> +static bool match_request_opcode(const void *a, const void *b)
>> +{
>> +     const struct bt_att_request *request =3D a;
>> +     const uint8_t *opcode =3D b;
>
> I think what you are looking for here is PTR_TO_UINT and UINT_TO_PRT magi=
c. Please use that.

Will do.

>> +static bool handle_exchange_mtu_rsp(struct bt_att *att, const uint8_t *=
pdu,
>> +                                                     uint16_t pdu_lengt=
h)
>> +{
>> +     struct bt_att_exchange_mtu_rsp_param param;
>> +
>> +     if (pdu_length !=3D 3)
>> +             return false;
>> +
>> +     param.server_rx_mtu =3D get_le16(pdu + 1);
>> +
>> +     request_complete(att, ATT_OP_EXCHANGE_MTU_REQ, pdu[0],
>> +                                                     &param, sizeof(par=
am));
>> +
>> +     return true;
>> +}
>
> So I wonder if we want to do this internally in att.c or not. My current =
thinking is that we might just provide an bt_att_set_mtu function that allo=
ws changing of the MTU and then then the MTU exchange itself becomes a GATT=
 problem. This means we keep ATT inside att.c pretty stupid to just being a=
 transport.

This is exactly the idea. This function above simply propagates the
received Server Rx MTU to the upper layer through the callback. The
upper layer is then expected to appropriately set the MTU using
bt_att_set_mtu, which is already introduced in this patch (I realize
now that it doesn't properly resize the buffer; I'll fix this in v2).

> I like this part of mgmt.c actually. It has no logic of its own besides q=
ueuing. Of course I realize that ATT is a bit silly with its one transactio=
n at a time, but then still allow bi-directional transactions.
>
> Here is what I had initially:
>
> unsigned int att_send(struct att *att, uint8_t opcode,
>                                 const void *param, uint16_t length,
>                                 const uint8_t responses[],
>                                 att_callback_func_t callback,
>                                 void *user_data, att_destroy_func_t destr=
oy);
>
> The trick is the responses[] callback which would take an array of opcode=
s that are valid responses for a transaction that is currently in progress.=
 Everything else would be treated as notifications. So all the logic is the=
n in GATT as an user of ATT.
>
> We did a similar style of handling with our AT command parser inside oFon=
o ad that worked out pretty nicely. For commands without response, the arra=
y could be just empty. Might want to check if the error response should be =
included by default if the array is not empty.

Actually what I have in mind is even simpler than this. For outgoing
operations that don't solicit a response (such as commands and
outgoing notifications) we simply send them and invoke the callback
with a special opcode such as "BT_ATT_PDU_SENT". For those outgoing
operations that do solicit a response (e.g. requests and indications),
the request remains pending until the response is received. A
responses array is not really necessary, since there is already a 1:1
mapping between ATT requests and their responses, so we know exactly
which request the received response matches (even the error response
contains the request that caused it in its PDU).

For incoming requests, we treat these as events as you said. To
respond to them, the upper layer than just needs to call bt_att_send
with the corresponding response opcode and parameters.


>> +/* Error response */
>> +#define ATT_OP_ERROR_RESP            0x01
>> +struct bt_att_error_rsp_param {
>> +     uint8_t request_opcode;
>> +     uint16_t handle;
>> +     uint8_t error_code;
>> +};
>> +
>> +/* Exchange MTU */
>> +#define ATT_OP_EXCHANGE_MTU_REQ              0x02
>> +struct bt_att_exchange_mtu_req_param {
>> +     uint16_t client_rx_mtu;
>> +};
>> +
>> +#define ATT_OP_EXCHANGE_MTU_RESP     0x03
>> +struct bt_att_exchange_mtu_rsp_param {
>> +     uint16_t server_rx_mtu;
>> +};
>> +
>> +/* Error codes for Error response PDU */
>> +#define ATT_ERROR_INVALID_HANDLE                     0x01
>> +#define ATT_ERROR_READ_NOT_PERMITTED                 0x02
>> +#define ATT_ERROR_WRITE_NOT_PERMITTED                        0x03
>> +#define ATT_ERROR_INVALID_PDU                                0x04
>> +#define ATT_ERROR_AUTHENTICATION                     0x05
>> +#define ATT_ERROR_REQUEST_NOT_SUPPORTED                      0x06
>> +#define ATT_ERROR_INVALID_OFFSET                     0x07
>> +#define ATT_ERROR_AUTHORIZATION                              0x08
>> +#define ATT_ERROR_PREPARE_QUEUE_FULL                 0x09
>> +#define ATT_ERROR_ATTRIBUTE_NOT_FOUND                        0x0A
>> +#define ATT_ERROR_ATTRIBUTE_NOT_LONG                 0x0B
>> +#define ATT_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE   0x0C
>> +#define ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LEN                0x0D
>> +#define ATT_ERROR_UNLIKELY                           0x0E
>> +#define ATT_ERROR_INSUFFICIENT_ENCRYPTION            0x0F
>> +#define ATT_ERROR_UNSUPPORTED_GROUP_TYPE             0x10
>> +#define ATT_ERROR_INSUFFICIENT_RESOURCES             0x11
>
> Please prefix these with BT_ATT. Not sure if we better stick them into mo=
nitor/bt.h here.

Will do. I say we keep them here for now. On that note: is there a
pattern to which structures get the bt_ prefix and which don't? e.g.
would struct att be a better name then struct bt_att here?

Cheers,
Arman

  reply	other threads:[~2014-05-13 18:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-09 20:13 [PATCH v1 00/10] bt_att initial implementation Arman Uguray
2014-05-09 20:13 ` [PATCH v1 01/10] src/shared/att: Introduce struct bt_att Arman Uguray
2014-05-13 16:43   ` Marcel Holtmann
2014-05-13 18:44     ` Arman Uguray [this message]
2014-05-14  8:17       ` Luiz Augusto von Dentz
2014-05-14 14:54         ` Arman Uguray
2014-05-15 13:07           ` Luiz Augusto von Dentz
2014-05-15 17:22             ` Arman Uguray
2014-05-09 20:13 ` [PATCH v1 02/10] unit/test-att: Add unit tests for src/shared/att Arman Uguray
2014-05-09 20:13 ` [PATCH v1 03/10] tools/btatt: Add command-line tool for ATT protocol testing Arman Uguray
2014-05-09 20:13 ` [PATCH v1 04/10] tools/btatt: Add "exchange-mtu" command Arman Uguray
2014-05-09 20:13 ` [PATCH v1 05/10] src/shared/att: Add "Find Information" request and response Arman Uguray
2014-05-09 20:13 ` [PATCH v1 06/10] unit/test-att: Add unit test for "Find Information" request/response Arman Uguray
2014-05-09 20:13 ` [PATCH v1 07/10] tools/btatt: Add "find-information" command Arman Uguray
2014-05-09 20:13 ` [PATCH v1 08/10] src/shared/att: Add "Find By Type Value" request and response Arman Uguray
2014-05-09 20:13 ` [PATCH v1 09/10] unit/test-att: Add unit test for "Find By Type Value" request/response Arman Uguray
2014-05-09 20:14 ` [PATCH v1 10/10] tools/btatt: Add "find-by-type-value" command Arman Uguray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHrH25RubNJx89MabHvHQc8ZsymcdDB2VoNVxwEooHEDv2=ybA@mail.gmail.com' \
    --to=armansito@chromium.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).