Exemplo n.º 1
0
uint32_t ble_gap_whitelist_set_req_enc(ble_gap_addr_t const * const * const pp_wl_addrs,
                                       uint8_t const                        len,
                                       uint8_t * const                      p_buf,
                                       uint32_t * const                     p_buf_len)
{
    SER_REQ_ENC_BEGIN(SD_BLE_GAP_WHITELIST_SET);

    uint8_t presence;
    SER_PUSH_uint8(&len);

    if (pp_wl_addrs)
    {
        presence = SER_FIELD_PRESENT;
        SER_PUSH_uint8(&presence);

        for (uint32_t i = 0; i < len; ++i)
        {
            SER_PUSH_COND(pp_wl_addrs[i], ble_gap_addr_t_enc);
        }
    }
    else
    {
        presence = SER_FIELD_NOT_PRESENT;
        SER_PUSH_uint8(&presence);
    }

    SER_REQ_ENC_END;
}
Exemplo n.º 2
0
uint32_t ble_gap_rssi_start_req_enc(uint16_t         conn_handle,
                                    uint8_t          threshold_dbm,
                                    uint8_t          skip_count,
                                    uint8_t * const  p_buf,
                                    uint32_t * const p_buf_len)
{
    SER_REQ_ENC_BEGIN(SD_BLE_GAP_RSSI_START);

    SER_PUSH_uint16(&conn_handle);
    SER_PUSH_uint8(&threshold_dbm);
    SER_PUSH_uint8(&skip_count);

    SER_REQ_ENC_END;
}
uint32_t ble_gatts_char_pf_t_enc(void const * const p_void_struct,
                                 uint8_t * const    p_buf,
                                 uint32_t           buf_len,
                                 uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatts_char_pf_t);

    SER_PUSH_uint8(&p_struct->format);
    SER_PUSH_int8(&p_struct->exponent);
    SER_PUSH_uint16(&p_struct->unit);
    SER_PUSH_uint8(&p_struct->name_space);
    SER_PUSH_uint16(&p_struct->desc);

    SER_STRUCT_ENC_END;
}
uint32_t ble_gatts_evt_rw_authorize_request_t_enc(void const * const p_void_struct,
                                                  uint8_t * const    p_buf,
                                                  uint32_t           buf_len,
                                                  uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatts_evt_rw_authorize_request_t);

    SER_PUSH_uint8(&p_struct->type);

    switch (p_struct->type)
    {
        case BLE_GATTS_AUTHORIZE_TYPE_READ:
            SER_PUSH_FIELD(&p_struct->request.read, ble_gatts_evt_read_t_enc);
            break;

        case BLE_GATTS_AUTHORIZE_TYPE_WRITE:
            SER_PUSH_FIELD(&p_struct->request.write, ble_gatts_evt_write_t_enc);
            break;

        default:
        case BLE_GATTS_AUTHORIZE_TYPE_INVALID:
            err_code = NRF_ERROR_INVALID_PARAM;
            break;
    }

    SER_STRUCT_ENC_END;
}
Exemplo n.º 5
0
uint32_t ble_gap_auth_key_reply_req_enc(uint16_t              conn_handle,
                                        uint8_t               key_type,
                                        uint8_t const * const p_key,
                                        uint8_t * const       p_buf,
                                        uint32_t * const      p_buf_len)
{
    SER_REQ_ENC_BEGIN(SD_BLE_GAP_AUTH_KEY_REPLY);
    
    uint8_t key_len;
    switch (key_type)
    {
        case BLE_GAP_AUTH_KEY_TYPE_NONE:
            key_len = 0;
            break;

        case BLE_GAP_AUTH_KEY_TYPE_PASSKEY:
            key_len = 6;
            break;

        case BLE_GAP_AUTH_KEY_TYPE_OOB:
            key_len = 16;
            break;

        default:
            return NRF_ERROR_INVALID_PARAM;
    }

    SER_PUSH_uint16(&conn_handle);
    SER_PUSH_uint8(&key_type);
    SER_PUSH_buf(p_key, key_len);

    SER_REQ_ENC_END;
}
uint32_t ble_gatts_evt_write_t_enc(void const * const p_void_struct,
                                   uint8_t * const    p_buf,
                                   uint32_t           buf_len,
                                   uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatts_evt_write_t);

    SER_PUSH_uint16(&p_struct->handle);
    SER_PUSH_FIELD(&p_struct->uuid, ble_uuid_t_enc);
    SER_PUSH_uint8(&p_struct->op);
    SER_PUSH_uint8(&p_struct->auth_required);
    SER_PUSH_uint16(&p_struct->offset);
    SER_PUSH_uint16(&p_struct->len);
    SER_PUSH_uint8array(p_struct->data, p_struct->len);

    SER_STRUCT_ENC_END;
}
uint32_t ble_gatts_evt_sys_attr_missing_t_enc(void const * const p_void_struct,
                                              uint8_t * const    p_buf,
                                              uint32_t           buf_len,
                                              uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatts_evt_sys_attr_missing_t);
    SER_PUSH_uint8(&p_struct->hint);
    SER_STRUCT_ENC_END;
}
uint32_t ble_gatts_evt_timeout_t_enc(void const * const p_void_struct,
                                     uint8_t * const    p_buf,
                                     uint32_t           buf_len,
                                     uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatts_evt_timeout_t);
    SER_PUSH_uint8(&p_struct->src);
    SER_STRUCT_ENC_END;
}
uint32_t ble_gatts_conn_cfg_t_enc(void const * const p_void_struct,
                                     uint8_t * const    p_buf,
                                     uint32_t           buf_len,
                                     uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatts_conn_cfg_t);
    SER_PUSH_uint8(&p_struct->hvn_tx_queue_size);
    SER_STRUCT_ENC_END;
}
Exemplo n.º 10
0
uint32_t ble_gap_device_identities_set_req_enc(ble_gap_id_key_t const * const * const pp_id_keys,
                                               ble_gap_irk_t const * const * const    pp_local_irks,
                                               uint8_t const                          len,
                                               uint8_t * const                        p_buf,
                                               uint32_t * const                       p_buf_len)
{
    SER_REQ_ENC_BEGIN(SD_BLE_GAP_DEVICE_IDENTITIES_SET);
    uint8_t presence;
    SER_PUSH_uint8(&len);

    if (pp_id_keys)
    {
        presence = SER_FIELD_PRESENT;
        SER_PUSH_uint8(&presence);
        
        for (uint32_t i = 0; i < len; ++i)
        {
            SER_PUSH_COND(pp_id_keys[i], ble_gap_id_key_t_enc);
        }
    }
    else
    {
        presence = SER_FIELD_NOT_PRESENT;
        SER_PUSH_uint8(&presence);
    }

    if (pp_local_irks)
    {
        presence = SER_FIELD_PRESENT;
        SER_PUSH_uint8(&presence);
        
        for (uint32_t i = 0; i < len; ++i)
        {
            SER_PUSH_COND(pp_local_irks[i], ble_gap_irk_t_enc);
        }
    }
    else
    {
        presence = SER_FIELD_NOT_PRESENT;
        SER_PUSH_uint8(&presence);
    }

    SER_REQ_ENC_END;
}
uint32_t ble_gatts_cfg_service_changed_t_enc(void const * const p_void_struct,
                                     uint8_t * const    p_buf,
                                     uint32_t           buf_len,
                                     uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatts_cfg_service_changed_t);
    uint8_t service_changed = p_struct->service_changed;
    SER_PUSH_uint8(&service_changed);
    SER_STRUCT_ENC_END;
}
Exemplo n.º 12
0
uint32_t ble_gap_keypress_notify_req_enc(uint16_t                           conn_handle,
                                          uint8_t                           kp_not,
                                          uint8_t * const                   p_buf,
                                          uint32_t * const                  p_buf_len)
{
    SER_REQ_ENC_BEGIN(SD_BLE_GAP_KEYPRESS_NOTIFY);

    SER_PUSH_uint16(&conn_handle);
    SER_PUSH_uint8(&kp_not);

    SER_REQ_ENC_END;
}
Exemplo n.º 13
0
uint32_t ble_gap_disconnect_req_enc(uint16_t         conn_handle,
                                    uint8_t          hci_status_code,
                                    uint8_t * const  p_buf,
                                    uint32_t * const p_buf_len)
{
    SER_REQ_ENC_BEGIN(SD_BLE_GAP_DISCONNECT);

    SER_PUSH_uint16(&conn_handle);
    SER_PUSH_uint8(&hci_status_code);

    SER_REQ_ENC_END;
}
Exemplo n.º 14
0
uint32_t ble_gap_evt_auth_key_request_enc(ble_evt_t const * const p_event,
                                          uint32_t                event_len,
                                          uint8_t * const         p_buf,
                                          uint32_t * const        p_buf_len)
{
    SER_EVT_ENC_BEGIN(BLE_GAP_EVT_AUTH_KEY_REQUEST);

    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_uint8(&p_event->evt.gap_evt.params.auth_key_request.key_type);

    SER_EVT_ENC_END;
}
Exemplo n.º 15
0
uint32_t ble_gap_evt_timeout_enc(ble_evt_t const * const p_event,
                                 uint32_t                event_len,
                                 uint8_t * const         p_buf,
                                 uint32_t * const        p_buf_len)
{
    SER_EVT_ENC_BEGIN(BLE_GAP_EVT_TIMEOUT);

    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_uint8(&p_event->evt.gap_evt.params.timeout.src);

    SER_EVT_ENC_END;
}
Exemplo n.º 16
0
uint32_t ble_gap_evt_key_pressed_enc(ble_evt_t const * const p_event,
                                   uint32_t                event_len,
                                   uint8_t * const         p_buf,
                                   uint32_t * const        p_buf_len)
{
    SER_EVT_ENC_BEGIN(BLE_GAP_EVT_KEY_PRESSED);

    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_uint8(&p_event->evt.gap_evt.params.key_pressed.kp_not);

    SER_EVT_ENC_END;
}
uint32_t ble_gatt_char_ext_props_t_enc(void const * const p_void_struct,
                              uint8_t * const    p_buf,
                              uint32_t           buf_len,
                              uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatt_char_ext_props_t);

    uint8_t ser_data = (p_struct->reliable_wr & 0x01)
                       | ((p_struct->wr_aux   & 0x01) << 1);
    SER_PUSH_uint8(&ser_data);

    SER_STRUCT_ENC_END;
}
uint32_t ble_gatts_enable_params_t_enc(void const * const p_void_struct,
                                       uint8_t * const    p_buf,
                                       uint32_t           buf_len,
                                       uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatts_enable_params_t);

    uint8_t ser_data = p_struct->service_changed & 0x01;
    SER_PUSH_uint8(&ser_data);
    SER_PUSH_uint32(&p_struct->attr_tab_size);

    SER_STRUCT_ENC_END;
}
Exemplo n.º 19
0
uint32_t ble_gattc_evt_write_cmd_tx_complete_enc(ble_evt_t const * const p_event,
                                                 uint32_t                event_len,
                                                 uint8_t * const         p_buf,
                                                 uint32_t * const        p_buf_len)
{
    SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE);

    SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
    SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
    SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
    SER_PUSH_uint8(&p_event->evt.gattc_evt.params.write_cmd_tx_complete.count);

    SER_EVT_ENC_END;
}
Exemplo n.º 20
0
uint32_t ble_gap_evt_passkey_display_enc(ble_evt_t const * const p_event,
                                         uint32_t                event_len,
                                         uint8_t * const         p_buf,
                                         uint32_t * const        p_buf_len)
{
    SER_EVT_ENC_BEGIN(BLE_GAP_EVT_PASSKEY_DISPLAY);

    uint8_t ser_data = p_event->evt.gap_evt.params.passkey_display.match_request & 0x01;
    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_uint8array(p_event->evt.gap_evt.params.passkey_display.passkey, BLE_GAP_PASSKEY_LEN);
    SER_PUSH_uint8(&ser_data);

    SER_EVT_ENC_END;
}
Exemplo n.º 21
0
uint32_t ble_gap_adv_start_req_enc(ble_gap_adv_params_t const * const p_adv_params,
#if NRF_SD_BLE_API_VERSION >= 4
                                   uint8_t                            conn_cfg_tag,
#endif
                                   uint8_t * const                    p_buf,
                                   uint32_t * const                   p_buf_len)
{
    SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_START);
    SER_PUSH_COND(p_adv_params, ble_gap_adv_params_t_enc);
#if NRF_SD_BLE_API_VERSION >= 4
    SER_PUSH_uint8(&conn_cfg_tag);
#endif
    SER_REQ_ENC_END;
}
Exemplo n.º 22
0
uint32_t ble_gap_evt_lesc_dhkey_request_enc(ble_evt_t const * const p_event,
                                            uint32_t                event_len,
                                            uint8_t * const         p_buf,
                                            uint32_t * const        p_buf_len)
{
    SER_EVT_ENC_BEGIN(BLE_GAP_EVT_LESC_DHKEY_REQUEST);

    uint8_t ser_data = p_event->evt.gap_evt.params.lesc_dhkey_request.oobd_req & 0x01;
    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_COND(p_event->evt.gap_evt.params.lesc_dhkey_request.p_pk_peer, ble_gap_lesc_p256_pk_t_enc);
    SER_PUSH_uint8(&ser_data);

    SER_EVT_ENC_END;
}
uint32_t ble_gatts_authorize_params_t_enc(void const * const p_void_struct,
                                          uint8_t * const    p_buf,
                                          uint32_t           buf_len,
                                          uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatts_authorize_params_t);

    uint8_t ser_data = p_struct->update & 0x01;
    SER_PUSH_uint16(&p_struct->gatt_status);
    SER_PUSH_uint8(&ser_data);
    SER_PUSH_uint16(&p_struct->offset);
    SER_PUSH_len16data(p_struct->p_data, p_struct->len);

    SER_STRUCT_ENC_END;
}
Exemplo n.º 24
0
uint32_t ble_gap_sec_params_reply_req_enc(uint16_t                           conn_handle,
                                          uint8_t                            sec_status,
                                          ble_gap_sec_params_t const * const p_sec_params,
                                          ble_gap_sec_keyset_t const * const p_sec_keyset,
                                          uint8_t * const                    p_buf,
                                          uint32_t * const                   p_buf_len)
{
    SER_REQ_ENC_BEGIN(SD_BLE_GAP_SEC_PARAMS_REPLY);

    SER_PUSH_uint16(&conn_handle);
    SER_PUSH_uint8(&sec_status);
    SER_PUSH_COND(p_sec_params, ble_gap_sec_params_t_enc);
    SER_PUSH_COND(p_sec_keyset, ble_gap_sec_keyset_t_enc);

    SER_REQ_ENC_END;
}
Exemplo n.º 25
0
uint32_t ble_uuid_encode_rsp_enc(uint32_t              return_code,
                                 uint8_t * const       p_buf,
                                 uint32_t * const      p_buf_len,
                                 uint8_t               uuid_le_len,
                                 uint8_t const * const p_uuid_le)
{
    SER_RSP_ENC_BEGIN(SD_BLE_UUID_ENCODE);

    SER_PUSH_uint8(&uuid_le_len);    
    if (p_uuid_le != NULL)
    {
        SER_PUSH_uint8array(p_uuid_le, uuid_le_len);
    }

    SER_RSP_ENC_END;
}
uint32_t ble_gatt_char_props_t_enc(void const * const p_void_struct,
                              uint8_t * const    p_buf,
                              uint32_t           buf_len,
                              uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatt_char_props_t);

    uint8_t ser_data = (p_struct->broadcast         & 0x01)
                       | ((p_struct->read           & 0x01) << 1)
                       | ((p_struct->write_wo_resp  & 0x01) << 2)
                       | ((p_struct->write          & 0x01) << 3)
                       | ((p_struct->notify         & 0x01) << 4)
                       | ((p_struct->indicate       & 0x01) << 5)
                       | ((p_struct->auth_signed_wr & 0x01) << 6);
    SER_PUSH_uint8(&ser_data);

    SER_STRUCT_ENC_END;
}
uint32_t ble_gatts_hvx_params_t_enc(void const * const p_void_struct,
                                    uint8_t * const    p_buf,
                                    uint32_t           buf_len,
                                    uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatts_hvx_params_t);

    SER_PUSH_uint16(&p_struct->handle);
    SER_PUSH_uint8(&p_struct->type);
    SER_PUSH_uint16(&p_struct->offset);
    SER_PUSH_COND(p_struct->p_len, uint16_t_enc);
    if (p_struct->p_len)
    {
        SER_PUSH_buf(p_struct->p_data, *p_struct->p_len);
    }

    SER_STRUCT_ENC_END;
}
Exemplo n.º 28
0
uint32_t ble_gap_connect_req_enc(ble_gap_addr_t const * const        p_peer_addr,
                                 ble_gap_scan_params_t const * const p_scan_params,
                                 ble_gap_conn_params_t const * const p_conn_params,
#if NRF_SD_BLE_API_VERSION >= 4
                                 uint8_t                             conn_cfg_tag,
#endif
                                 uint8_t * const                     p_buf,
                                 uint32_t * const                    p_buf_len)
{
    SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONNECT);

    SER_PUSH_COND(p_peer_addr, ble_gap_addr_t_enc);
    SER_PUSH_COND(p_scan_params, ble_gap_scan_params_t_enc);
    SER_PUSH_COND(p_conn_params, ble_gap_conn_params_t_enc);
#if NRF_SD_BLE_API_VERSION >= 4
    SER_PUSH_uint8(&conn_cfg_tag);
#endif

    SER_REQ_ENC_END;
}
uint32_t ble_gatts_attr_md_t_enc(void const * const p_void_struct,
                                 uint8_t * const    p_buf,
                                 uint32_t           buf_len,
                                 uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatts_attr_md_t);

    SER_PUSH_FIELD(&p_struct->read_perm, ble_gap_conn_sec_mode_t_enc);
    SER_PUSH_FIELD(&p_struct->write_perm, ble_gap_conn_sec_mode_t_enc);
    uint8_t ser_data = (p_struct->vlen & 0x01)
                       | ((p_struct->vloc & 0x03) << 1)
                       | ((p_struct->rd_auth & 0x01) << 3)
                       | ((p_struct->wr_auth & 0x01) << 4);
    SER_PUSH_uint8(&ser_data);

    // Serializer does not support attributes on stack.
    if (p_struct->vloc != BLE_GATTS_VLOC_STACK)
    {
        err_code = NRF_ERROR_INVALID_PARAM;
    }

    SER_STRUCT_ENC_END;
}
uint32_t ble_gatts_rw_authorize_reply_params_t_enc(void const * const p_void_struct,
                                                   uint8_t * const    p_buf,
                                                   uint32_t           buf_len,
                                                   uint32_t * const   p_index)
{
    SER_STRUCT_ENC_BEGIN(ble_gatts_rw_authorize_reply_params_t);

    SER_PUSH_uint8(&p_struct->type);
    if (p_struct->type == BLE_GATTS_AUTHORIZE_TYPE_READ)
    {
        SER_PUSH_FIELD(&p_struct->params.read, ble_gatts_authorize_params_t_enc);
    }
    else if (p_struct->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
    {
        SER_PUSH_FIELD(&p_struct->params.write, ble_gatts_authorize_params_t_enc);
    }
    else
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    SER_STRUCT_ENC_END;
}