Unable to disable pairing in my peripheral app

I have a simple GATT server application with two characteristics, RX and TX. In my prj.conf, I am trying to disable pairing as follows :

CONFIG_BT_BONDABLE=n
CONFIG_BT_SMP=n

I can connect to the server from a BLE scanner app. When I try to write to the TX characteristic, it asks me for a pairing code, and then disconnects if I don't have it. How to solve this? Thanks in advance. This is how I enable BLE and start advertising : 

    ret = bt_enable(NULL);
	if (ret) {
		return ret;
	}


    bt_gatt_cb_register(&gatt_callbacks);
    bt_conn_cb_register(&conn_callbacks);

    if (IS_ENABLED(CONFIG_SETTINGS)) {
		settings_load();
	}

    /* Start advertising */
    ret = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, NULL, 0, NULL, 0);
    if (ret) {
        return ret;
    }

Parents
  • Hi Paolo, 
    Most likely your TX characteristic requires the link to be encrypted to access it (write to it). You need to remove that. Please check how you declare the characteristic. 
    I would suggest to take a look at our dev academy course here: academy.nordicsemi.com/.../

  • Hi  ,

    Thanks for your response. I am defining the service and characteristics as follows which shouldn't require an encrypted link? (I believe): 

    #define CUSTOM_SERVICE_UUID 0x180A
    #define CUSTOM_CHAR_UUID_READ  0x2A01
    #define CUSTOM_CHAR_UUID_WRITE 0x2A02
    
    /* GATT Callbacks */
    static ssize_t read_callback(struct bt_conn *conn,
                                 const struct bt_gatt_attr *attr,
                                 void *buf, uint16_t len, uint16_t offset)
    {
        const uint8_t *value = attr->user_data;
        LOG_INF("GATT Read: 0x%02X", *value);
        return bt_gatt_attr_read(conn, attr, buf, len, offset, value, sizeof(*value));
    }
    
    static ssize_t write_callback(struct bt_conn *conn,
                                  const struct bt_gatt_attr *attr,
                                  const void *buf, uint16_t len, uint16_t offset,
                                  uint8_t flags)
    {
        uint8_t *value = attr->user_data;
    
        if (offset + len > sizeof(*value)) {
            return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
        }
    
        memcpy(value + offset, buf, len);
        LOG_INF("GATT Write: 0x%02X", *value);
    
        // TODO - Process data - analyse frame etc. 
    
        return len;
    }
    
    /* GATT Service Definition */
    BT_GATT_SERVICE_DEFINE(custom_svc,
        BT_GATT_PRIMARY_SERVICE(BT_UUID_DECLARE_16(CUSTOM_SERVICE_UUID)),
        BT_GATT_CHARACTERISTIC(BT_UUID_DECLARE_16(CUSTOM_CHAR_UUID_READ),
                               BT_GATT_CHRC_READ,
                               BT_GATT_PERM_READ,
                               read_callback, NULL, &read_value),
        BT_GATT_CHARACTERISTIC(BT_UUID_DECLARE_16(CUSTOM_CHAR_UUID_WRITE),
                               BT_GATT_CHRC_WRITE,
                               BT_GATT_PERM_WRITE,
                               NULL, write_callback, &write_value)
    );
    

Reply
  • Hi  ,

    Thanks for your response. I am defining the service and characteristics as follows which shouldn't require an encrypted link? (I believe): 

    #define CUSTOM_SERVICE_UUID 0x180A
    #define CUSTOM_CHAR_UUID_READ  0x2A01
    #define CUSTOM_CHAR_UUID_WRITE 0x2A02
    
    /* GATT Callbacks */
    static ssize_t read_callback(struct bt_conn *conn,
                                 const struct bt_gatt_attr *attr,
                                 void *buf, uint16_t len, uint16_t offset)
    {
        const uint8_t *value = attr->user_data;
        LOG_INF("GATT Read: 0x%02X", *value);
        return bt_gatt_attr_read(conn, attr, buf, len, offset, value, sizeof(*value));
    }
    
    static ssize_t write_callback(struct bt_conn *conn,
                                  const struct bt_gatt_attr *attr,
                                  const void *buf, uint16_t len, uint16_t offset,
                                  uint8_t flags)
    {
        uint8_t *value = attr->user_data;
    
        if (offset + len > sizeof(*value)) {
            return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
        }
    
        memcpy(value + offset, buf, len);
        LOG_INF("GATT Write: 0x%02X", *value);
    
        // TODO - Process data - analyse frame etc. 
    
        return len;
    }
    
    /* GATT Service Definition */
    BT_GATT_SERVICE_DEFINE(custom_svc,
        BT_GATT_PRIMARY_SERVICE(BT_UUID_DECLARE_16(CUSTOM_SERVICE_UUID)),
        BT_GATT_CHARACTERISTIC(BT_UUID_DECLARE_16(CUSTOM_CHAR_UUID_READ),
                               BT_GATT_CHRC_READ,
                               BT_GATT_PERM_READ,
                               read_callback, NULL, &read_value),
        BT_GATT_CHARACTERISTIC(BT_UUID_DECLARE_16(CUSTOM_CHAR_UUID_WRITE),
                               BT_GATT_CHRC_WRITE,
                               BT_GATT_PERM_WRITE,
                               NULL, write_callback, &write_value)
    );
    

Children
No Data
Related