You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by James Howarth <ja...@gmail.com> on 2016/05/28 19:53:14 UTC

How to determine the length of received data in a GATT callback

Hi,

Looking at the peripheral callback gatt_svr_chr_access_gatt, is there a way
to determine the length of data received?

Here's the whole function definition.

static int
gatt_svr_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle,
uint8_t op,
                         union ble_gatt_access_ctxt *ctxt, void *arg)

Cheers
James

Re: How to determine the length of received data in a GATT callback

Posted by James Howarth <ja...@gmail.com>.
Ahh, thanks Chris.  Much appreciated.

On Sat, May 28, 2016 at 3:53 PM, Christopher Collins <cc...@apache.org>
wrote:

> Hi James,
>
> On Sat, May 28, 2016 at 12:53:14PM -0700, James Howarth wrote:
> > Hi,
> >
> > Looking at the peripheral callback gatt_svr_chr_access_gatt, is there a
> way
> > to determine the length of data received?
> >
> > Here's the whole function definition.
> >
> > static int
> > gatt_svr_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle,
> > uint8_t op,
> >                          union ble_gatt_access_ctxt *ctxt, void *arg)
>
> The length of the received data is contained in the ctxt->chr_access.len
> field.  For example, bleprph handles an incoming write of the
> gap-reconnect-address characteristic as follows:
>
>     case BLE_GAP_CHR_UUID16_RECONNECT_ADDR:
>         assert(op == BLE_GATT_ACCESS_OP_WRITE_CHR);
>         if (ctxt->chr_access.len != sizeof bleprph_reconnect_addr) {
>             return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
>         }
>         memcpy(bleprph_reconnect_addr, ctxt->chr_access.data,
>                sizeof bleprph_reconnect_addr);
>         break;
>
> The code validates the length of the incoming data immediately after the
> assert() invocation.
>
> Chris
>

Re: How to determine the length of received data in a GATT callback

Posted by Christopher Collins <cc...@apache.org>.
Hi James,

On Sat, May 28, 2016 at 12:53:14PM -0700, James Howarth wrote:
> Hi,
> 
> Looking at the peripheral callback gatt_svr_chr_access_gatt, is there a way
> to determine the length of data received?
> 
> Here's the whole function definition.
> 
> static int
> gatt_svr_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle,
> uint8_t op,
>                          union ble_gatt_access_ctxt *ctxt, void *arg)

The length of the received data is contained in the ctxt->chr_access.len
field.  For example, bleprph handles an incoming write of the
gap-reconnect-address characteristic as follows:

    case BLE_GAP_CHR_UUID16_RECONNECT_ADDR:
        assert(op == BLE_GATT_ACCESS_OP_WRITE_CHR);
        if (ctxt->chr_access.len != sizeof bleprph_reconnect_addr) {
            return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
        }
        memcpy(bleprph_reconnect_addr, ctxt->chr_access.data,
               sizeof bleprph_reconnect_addr);
        break;

The code validates the length of the incoming data immediately after the
assert() invocation.

Chris