static void connected(struct bt_conn *conn, uint8_t conn_err) { char addr[BT_ADDR_LE_STR_LEN]; int err; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); if (conn_err) { printk("Failed to connect to %s (%u)\n", addr, conn_err); return; } printk("Connected: %s\n", addr); if (conn == default_conn) { uuid.val = BT_UUID_HRS_VAL; discover_params.uuid = &uuid.uuid; discover_params.func = discover_func; discover_params.start_handle = 0x0001; discover_params.end_handle = 0xffff; discover_params.type = BT_GATT_DISCOVER_PRIMARY; err = bt_gatt_discover(default_conn, &discover_params); if (err) { printk("Discover failed(err %d)\n", err); return; } } }
static void auth_cancel(struct bt_conn *conn) { char addr[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); printk("Pairing cancelled: %s\n", addr); }
static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) { char addr[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); printk("Passkey for %s: %u\n", addr, passkey); }
static void security_changed(struct bt_conn *conn, bt_security_t level) { char addr[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); printk("Security changed: %s level %u\n", addr, level); }
static void disconnected(struct bt_conn *conn, uint8_t reason) { char addr[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); printk("Disconnected from %s (reason %u)\n", addr, reason); }
uint8_t BLECharacteristicImp::discoverResponseProc(bt_conn_t *conn, const bt_gatt_attr_t *attr, bt_gatt_discover_params_t *params) { const bt_addr_le_t* dst_addr = bt_conn_get_dst(conn); BLEDevice device(dst_addr); uint8_t retVal = BT_GATT_ITER_STOP; pr_debug(LOG_MODULE_BLE, "%s-%d: type-%d", __FUNCTION__, __LINE__, params->type); // Process the service switch (params->type) { case BT_GATT_DISCOVER_DESCRIPTOR: { if (NULL != attr) { retVal = BT_GATT_ITER_CONTINUE; const bt_uuid_t* desc_uuid = attr->uuid; uint16_t desc_handle = attr->handle; pr_debug(LOG_MODULE_BLE, "%s-%d:handle-%d:%d", __FUNCTION__, __LINE__,attr->handle, desc_handle); if (isClientCharacteristicConfigurationDescriptor(desc_uuid)) { setCCCDHandle(desc_handle); } else if (bt_uuid_cmp(BLEServiceImp::getPrimayUuid(), desc_uuid) == 0 || bt_uuid_cmp(getCharacteristicAttributeUuid(), desc_uuid) == 0 ) { retVal = BT_GATT_ITER_STOP; } else { int retval = (int)addDescriptor(desc_uuid, attr->perm, desc_handle); if (BLE_STATUS_SUCCESS != retval) { pr_error(LOG_MODULE_BLE, "%s-%d: Error-%d", __FUNCTION__, __LINE__, retval); errno = ENOMEM; retVal = BT_GATT_ITER_STOP; } } } break; } default: { break; } } return retVal; }
static void le_disconnected(struct bt_conn *conn, uint8_t reason) { struct gap_device_disconnected_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); memcpy(ev.address, addr->a.val, sizeof(ev.address)); ev.address_type = addr->type; tester_send(BTP_SERVICE_ID_GAP, GAP_EV_DEVICE_DISCONNECTED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); }
static void auth_passkey_entry(struct bt_conn *conn) { struct gap_passkey_entry_req_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); memcpy(ev.address, addr->a.val, sizeof(ev.address)); ev.address_type = addr->type; tester_send(BTP_SERVICE_ID_GAP, GAP_EV_PASSKEY_ENTRY_REQ, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); }
static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) { struct gap_passkey_display_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); memcpy(ev.address, addr->a.val, sizeof(ev.address)); ev.address_type = addr->type; ev.passkey = sys_cpu_to_le32(passkey); tester_send(BTP_SERVICE_ID_GAP, GAP_EV_PASSKEY_DISPLAY, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); }
BLEPeripheralHelper* BLECentralRole::peripheral(bt_conn_t *conn) { BLEPeripheralHelper* temp = NULL; const bt_addr_le_t *addr = bt_conn_get_dst(conn); // Find free peripheral Items for (int i = 0; i < BLE_MAX_CONN_CFG; i++) { temp = _peripherial[i]; if (*temp == *addr) { return temp; } } return NULL; }
static void connected(struct bt_conn *conn, uint8_t err) { char addr[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); if (err) { printk("Failed to connect to %s (%u)\n", addr, err); return; } printk("Connected %s\n", addr); if (bt_conn_security(conn, BT_SECURITY_FIPS)) { printk("Failed to set security\n"); } }
bool BLECharacteristicImp::subscribe(void) { int retval = 0; bt_conn_t* conn = NULL; if (true == BLEUtils::isLocalBLE(_ble_device)) { // GATT server can't subscribe return false; } if (_gatt_chrc.properties & BT_GATT_CHRC_NOTIFY) { _sub_params.value |= BT_GATT_CCC_NOTIFY; } if (_gatt_chrc.properties & BT_GATT_CHRC_INDICATE) { _sub_params.value |= BT_GATT_CCC_INDICATE; } if (_sub_params.value == 0) { return false; } conn = bt_conn_lookup_addr_le(_ble_device.bt_le_address()); if (NULL == conn) { return false; } bt_addr_le_copy(&_sub_params._peer, bt_conn_get_dst(conn)); _sub_params.ccc_handle = _cccd_handle; _sub_params.value_handle = _value_handle; // Enable CCCD to allow peripheral send Notification/Indication retval = bt_gatt_subscribe(conn, &_sub_params); bt_conn_unref(conn); if (0 == retval) { _subscribed = true; } return _subscribed; }
// GATT client only uint8_t profile_notify_process (bt_conn_t *conn, bt_gatt_subscribe_params_t *params, const void *data, uint16_t length) { //BLEPeripheralHelper* peripheral = BLECentralRole::instance()->peripheral(conn);// Find peripheral by bt_conn //BLEAttribute* notifyatt = peripheral->attribute(params); // Find attribute by params BLECharacteristicImp* chrc = NULL; BLEDevice bleDevice(bt_conn_get_dst(conn)); chrc = BLEProfileManager::instance()->characteristic(bleDevice, params->value_handle); //assert(notifyatt->type() == BLETypeCharacteristic); pr_debug(LOG_MODULE_APP, "%s1", __FUNCTION__); if (NULL != chrc) { chrc->setValue((const unsigned char *)data, length); } return BT_GATT_ITER_CONTINUE; }
static void on_disconnected(struct bt_conn *conn, uint8_t reason) { int i; const bt_addr_le_t *dst; dst = bt_conn_get_dst(conn); if (!dst) { return; } /* This is a specific behaviour: we are discarding CCCD value for the * measurement characteristic -> forces the peer to resubscribe */ for (i = 0; i < ARRAY_SIZE(rsc_measurement_ccc_cfg); i++) { if (!bt_addr_le_cmp(dst, &rsc_measurement_ccc_cfg[i].peer)) { rsc_measurement_ccc_cfg[i].value = 0; } } }
static void disconnected(struct bt_conn *conn, u8_t reason) { #if defined(CONFIG_NET_DEBUG_L2_BLUETOOTH) char addr[BT_ADDR_LE_STR_LEN]; #endif if (conn != default_conn) { return; } #if defined(CONFIG_NET_DEBUG_L2_BLUETOOTH) bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); NET_DBG("Disconnected: %s (reason %u)\n", addr, reason); #endif bt_conn_unref(default_conn); default_conn = NULL; }
static void connected(struct bt_conn *conn, u8_t err) { if (err) { #if defined(CONFIG_NET_DEBUG_L2_BLUETOOTH) char addr[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); NET_ERR("Failed to connect to %s (%u)\n", addr, err); #endif return; } if (conn != default_conn) { return; } bt_l2cap_chan_connect(conn, &bt_context_data.ipsp_chan.chan, L2CAP_IPSP_PSM); }
// GATT Client only uint8_t profile_read_rsp_process(bt_conn_t *conn, int err, bt_gatt_read_params_t *params, const void *data, uint16_t length) { if (NULL == data) { return BT_GATT_ITER_STOP; } BLECharacteristicImp *chrc = NULL; BLEDevice bleDevice(bt_conn_get_dst(conn)); // Get characteristic by handle params->single.handle chrc = BLEProfileManager::instance()->characteristic(bleDevice, params->single.handle); if (chrc) // KW issue: may be NULL and will be dereferenced chrc->setValue((const unsigned char *)data, length); pr_debug(LOG_MODULE_BLE, "%s-%d", __FUNCTION__, __LINE__); return BT_GATT_ITER_STOP; }
static void disconnected(struct bt_conn *conn, uint8_t reason) { char addr[BT_ADDR_LE_STR_LEN]; int err; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); printk("Disconnected: %s (reason %u)\n", addr, reason); if (default_conn != conn) { return; } bt_conn_unref(default_conn); default_conn = NULL; /* This demo doesn't require active scan */ err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err) { printk("Scanning failed to start (err %d)\n", err); } }
uint8_t profile_descriptor_read_rsp_process(bt_conn_t *conn, int err, bt_gatt_read_params_t *params, const void *data, uint16_t length) { if (NULL == data) { return BT_GATT_ITER_STOP; } BLEDescriptorImp *descriptor = NULL; BLEDevice bleDevice(bt_conn_get_dst(conn)); // Get characteristic by handle params->single.handle descriptor = BLEProfileManager::instance()->descriptor(bleDevice, params->single.handle); //pr_debug(LOG_MODULE_BLE, "%s-%d", __FUNCTION__, __LINE__); if (descriptor) { descriptor->writeValue((const unsigned char *)data, length, params->single.offset); } //pr_debug(LOG_MODULE_BLE, "%s-%d: desc len-%d", __FUNCTION__, __LINE__, descriptor->valueLength()); return BT_GATT_ITER_STOP; }