Example #1
0
uint32_t ble_gap_evt_auth_status_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_STATUS);

    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_FIELD(&p_event->evt.gap_evt.params.auth_status, ble_gap_evt_auth_status_t_enc);

    // keyset is an extension of standard event data - used to synchronize keys at application
    uint32_t conn_index;
    err_code = conn_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index);
    if (err_code == NRF_SUCCESS)
    {
        SER_PUSH_FIELD(&(m_conn_keys_table[conn_index].keyset), ble_gap_sec_keyset_t_enc);

        err_code = conn_ble_gap_sec_context_destroy(p_event->evt.gap_evt.conn_handle);
        SER_ASSERT(err_code == NRF_SUCCESS, err_code);
    }
    else
    {
        err_code = NRF_SUCCESS;
    }

    SER_EVT_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;
}
Example #3
0
uint32_t ble_version_get_rsp_enc(uint32_t                    return_code,
                                 uint8_t * const             p_buf,
                                 uint32_t * const            p_buf_len,
                                 ble_version_t const * const p_version)
{
    SER_RSP_ENC_BEGIN(SD_BLE_VERSION_GET);
    SER_PUSH_FIELD(p_version, ble_version_t_enc);
    SER_RSP_ENC_END;
}
uint32_t ble_gatts_char_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_char_md_t);

    SER_PUSH_FIELD(&p_struct->char_props, ble_gatt_char_props_t_enc);
    SER_PUSH_FIELD(&p_struct->char_ext_props, ble_gatt_char_ext_props_t_enc);
    SER_PUSH_uint16(&p_struct->char_user_desc_max_size);
    SER_ERROR_CHECK(p_struct->char_user_desc_size <= BLE_GATTS_VAR_ATTR_LEN_MAX,
                    NRF_ERROR_INVALID_PARAM);
    SER_PUSH_len16data(p_struct->p_char_user_desc, p_struct->char_user_desc_size);
    SER_PUSH_COND(p_struct->p_char_pf, ble_gatts_char_pf_t_enc);
    SER_PUSH_COND(p_struct->p_user_desc_md, ble_gatts_attr_md_t_enc);
    SER_PUSH_COND(p_struct->p_cccd_md, ble_gatts_attr_md_t_enc);
    SER_PUSH_COND(p_struct->p_sccd_md, ble_gatts_attr_md_t_enc);

    SER_STRUCT_ENC_END;
}
Example #5
0
uint32_t ble_gap_evt_conn_sec_update_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_CONN_SEC_UPDATE);

    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_FIELD(&p_event->evt.gap_evt.params.conn_sec_update, ble_gap_evt_conn_sec_update_t_enc);

    SER_EVT_ENC_END;
}
Example #6
0
uint32_t ble_gap_evt_adv_report_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_ADV_REPORT);

    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_FIELD(&p_event->evt.gap_evt.params.adv_report, ble_gap_evt_adv_report_t_enc);

    SER_EVT_ENC_END;
}
Example #7
0
uint32_t ble_gap_evt_sec_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_SEC_REQUEST);

    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_FIELD(&p_event->evt.gap_evt.params.sec_request, ble_gap_evt_sec_request_t_enc);

    SER_EVT_ENC_END;
}
Example #8
0
uint32_t ble_gap_evt_connected_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_CONNECTED);

    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_FIELD(&p_event->evt.gap_evt.params.connected, ble_gap_evt_connected_t_enc);

    SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_read_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_read_t);

    SER_PUSH_uint16(&p_struct->handle);
    SER_PUSH_FIELD(&p_struct->uuid, ble_uuid_t_enc);
    SER_PUSH_uint16(&p_struct->offset);

    SER_STRUCT_ENC_END;
}
Example #10
0
uint32_t ble_gap_evt_scan_req_report_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_SCAN_REQ_REPORT);

    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_FIELD(&p_event->evt.gap_evt.params.scan_req_report.peer_addr, ble_gap_addr_t_enc);
    SER_PUSH_int8(&p_event->evt.gap_evt.params.scan_req_report.rssi);

    SER_EVT_ENC_END;
}
Example #11
0
uint32_t ble_gap_evt_conn_param_update_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_CONN_PARAM_UPDATE_REQUEST);

    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_FIELD(&p_event->evt.gap_evt.params.conn_param_update_request,
                   ble_gap_evt_conn_param_update_request_t_enc);

    SER_EVT_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;
}
Example #13
0
uint32_t ble_gattc_evt_hvx_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_HVX);

    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_FIELD(&p_event->evt.gattc_evt.params.hvx, ble_gattc_evt_hvx_t_enc);

    SER_EVT_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;
}
Example #15
0
uint32_t ble_gattc_evt_exchange_mtu_rsp_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_EXCHANGE_MTU_RSP);

    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_FIELD(&p_event->evt.gattc_evt.params.exchange_mtu_rsp,
                   ble_gattc_evt_exchange_mtu_rsp_t_enc);

    SER_EVT_ENC_END;
}
Example #16
0
uint32_t ble_gattc_evt_char_vals_read_rsp_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_CHAR_VALS_READ_RSP);

    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_FIELD(&p_event->evt.gattc_evt.params.char_vals_read_rsp,
                   ble_gattc_evt_char_vals_read_rsp_t_enc);

    SER_EVT_ENC_END;
}
Example #17
0
uint32_t ble_gattc_evt_attr_info_disc_rsp_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_ATTR_INFO_DISC_RSP);

    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_FIELD(&p_event->evt.gattc_evt.params.attr_info_disc_rsp,
                   ble_gattc_evt_attr_info_disc_rsp_t_enc);

    SER_EVT_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;
}
Example #19
0
uint32_t ble_gap_evt_disconnected_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_DISCONNECTED);

    SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
    SER_PUSH_FIELD(&p_event->evt.gap_evt.params.disconnected, ble_gap_evt_disconnected_t_enc);

    // If disconnected and context is not yet destroyed, destroy it now
    uint32_t conn_index;
	err_code = conn_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index);
	if (err_code == NRF_SUCCESS)
	{
		err_code = conn_ble_gap_sec_context_destroy(p_event->evt.gap_evt.conn_handle);
		SER_ASSERT(err_code == NRF_SUCCESS, err_code);
	}
    err_code = NRF_SUCCESS;

    SER_EVT_ENC_END;
}
Example #20
0
uint32_t ble_opt_get_rsp_enc(uint32_t                return_code,
                             uint8_t * const         p_buf,
                             uint32_t * const        p_buf_len,
                             uint32_t                opt_id,
                             ble_opt_t const * const p_opt)
{
    SER_RSP_ENC_BEGIN(SD_BLE_OPT_GET);

    SER_ASSERT_NOT_NULL(p_opt);
    SER_ASSERT(((opt_id == BLE_COMMON_OPT_CONN_BW)           ||
                (opt_id == BLE_COMMON_OPT_PA_LNA)            ||
                (opt_id == BLE_COMMON_OPT_CONN_EVT_EXT)      ||
                (opt_id == BLE_GAP_OPT_CH_MAP)               ||
                (opt_id == BLE_GAP_OPT_LOCAL_CONN_LATENCY)   ||
                (opt_id == BLE_GAP_OPT_PASSKEY)              ||
                (opt_id == BLE_GAP_OPT_SCAN_REQ_REPORT)      ||
                (opt_id == BLE_GAP_OPT_COMPAT_MODE)          ||
                (opt_id == BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT) ||
                (opt_id == BLE_GAP_OPT_EXT_LEN)), NRF_ERROR_INVALID_PARAM);

    SER_PUSH_uint32(&opt_id);

    field_encoder_handler_t fp_encoder = NULL;
    void const *            p_struct = NULL;

    switch (opt_id)
    {
        case BLE_COMMON_OPT_CONN_BW:
            fp_encoder = ble_common_opt_conn_bw_t_enc;
            p_struct   = &p_opt->common_opt.conn_bw;
        break;
        case BLE_COMMON_OPT_PA_LNA:
            fp_encoder = ble_common_opt_pa_lna_t_enc;
            p_struct   = &p_opt->common_opt.pa_lna;
        break;
        case BLE_COMMON_OPT_CONN_EVT_EXT:
            fp_encoder = ble_common_opt_conn_evt_ext_t_enc;
            p_struct   = &p_opt->common_opt.conn_evt_ext;
        break;
        case BLE_GAP_OPT_CH_MAP:
            fp_encoder = ble_gap_opt_ch_map_t_enc;
            p_struct   = &p_opt->gap_opt.ch_map;
        break;
        case BLE_GAP_OPT_LOCAL_CONN_LATENCY:
            fp_encoder = ble_gap_opt_local_conn_latency_t_enc;
            p_struct   = &p_opt->gap_opt.local_conn_latency;
        break;
        case BLE_GAP_OPT_PASSKEY:
            fp_encoder = ble_gap_opt_passkey_t_enc;
            p_struct   = &p_opt->gap_opt.passkey;
        break;
        case BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT:
            fp_encoder = ble_gap_opt_auth_payload_timeout_t_enc;
            p_struct   = &p_opt->gap_opt.auth_payload_timeout;
        break;
        case BLE_GAP_OPT_EXT_LEN:
            fp_encoder = ble_gap_opt_ext_len_t_enc;
            p_struct   = &p_opt->gap_opt.ext_len;
        break;
        case BLE_GAP_OPT_SCAN_REQ_REPORT:
            fp_encoder = ble_gap_opt_scan_req_report_t_enc;
            p_struct   = &p_opt->gap_opt.scan_req_report;
        break;
        case BLE_GAP_OPT_COMPAT_MODE:
            fp_encoder = ble_gap_opt_compat_mode_t_enc;
            p_struct   = &p_opt->gap_opt.compat_mode;
        break;
        default:
            SER_ASSERT(NRF_ERROR_INVALID_PARAM, NRF_ERROR_INVALID_PARAM);
        break;
    }

    SER_PUSH_FIELD(p_struct, fp_encoder);

    SER_RSP_ENC_END;
}