This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

question of add my own BLE service

When I add a new server of my own service I got a problem. when I set

BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&cccd_md.write_perm);

I can send data to iOS normal,but when I connect to Android 4.4.4(Nexus7 II) it will return error 0x8 (Invalid state)

when I change it to this:

BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);

Android data sent normal,but will cause service ias(service.immediate_alert) not work and iOS ias not work too.

So please help!

Below is code of mine to add characteristic

static uint32_t my_level_char_add(ble_my_t * p_bas, const ble_my_init_t * p_bas_init)
{
    uint32_t            err_code;
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_md_t cccd_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          ble_uuid;
    ble_gatts_attr_md_t attr_md;
    uint8_t             initial_my_level;

    memset(&cccd_md, 0, sizeof(cccd_md));

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
    //BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
    BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&cccd_md.write_perm);
    cccd_md.vlen = 1;
    cccd_md.vloc       = BLE_GATTS_VLOC_STACK;


    memset(&char_md, 0, sizeof(char_md));

    char_md.char_props.read   = 1;
    char_md.char_props.notify = 1;
    char_md.p_char_user_desc  = NULL;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = &cccd_md;
    char_md.p_sccd_md         = NULL;

    BLE_UUID_BLE_ASSIGN(ble_uuid, 0xFFE1);
    memset(&attr_md, 0, sizeof(attr_md));

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
		
    attr_md.vloc = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth    = 0;
    attr_md.wr_auth    = 0;
    attr_md.vlen       = 1;

    initial_my_level = 0x0;

    memset(&attr_char_value, 0, sizeof(attr_char_value));

    attr_char_value.p_uuid    = &ble_uuid;
    attr_char_value.p_attr_md = &attr_md;
    attr_char_value.init_len  = sizeof(uint8_t);
    attr_char_value.init_offs = 0;
    attr_char_value.max_len   = sizeof(uint8_t);
    attr_char_value.p_value   = &initial_my_level;

    err_code = sd_ble_gatts_characteristic_add(p_bas->service_handle, &char_md,
                                               &attr_char_value,
                                               &p_bas->my_handles);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    return NRF_SUCCESS;
}
Parents
  • Have the same issue, from other thread we've got link to BT Core 4.2 volume 3, part G, section 3.3.3.3 (Client Characteristic Configuration) "Authentication and authorization may be required by the server to write the configuration descriptor. The Client Characteristic Configuration declaration shall be readable and writable."

    It sounds a little bit tricky, because of quote "...may be required by the server to write..." So if server requires auth from CCCD, but on device configured as BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm); or vice versa the communication will crash? In my case the mode BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&cccd_md.write_perm); needed to preserve device from enabling notifications by not authorized server. And it works on some android devices but not all. Even more it could change behaviour on same device after reconnection. Please help.

Reply
  • Have the same issue, from other thread we've got link to BT Core 4.2 volume 3, part G, section 3.3.3.3 (Client Characteristic Configuration) "Authentication and authorization may be required by the server to write the configuration descriptor. The Client Characteristic Configuration declaration shall be readable and writable."

    It sounds a little bit tricky, because of quote "...may be required by the server to write..." So if server requires auth from CCCD, but on device configured as BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm); or vice versa the communication will crash? In my case the mode BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&cccd_md.write_perm); needed to preserve device from enabling notifications by not authorized server. And it works on some android devices but not all. Even more it could change behaviour on same device after reconnection. Please help.

Children
No Data
Related