/** * The nimble host executes this callback when a GAP event occurs. The * application associates a GAP event callback with each connection that forms. * bleuart uses the same callback for all connections. * * @param event The type of event being signalled. * @param ctxt Various information pertaining to the event. * @param arg Application-specified argument; unuesd by * bleuart. * * @return 0 if the application successfully handled the * event; nonzero on failure. The semantics * of the return code is specific to the * particular GAP event being signalled. */ static int bleuart_gap_event(struct ble_gap_event *event, void *arg) { struct ble_gap_conn_desc desc; int rc; switch (event->type) { case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ if (event->connect.status == 0) { rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); bleuart_set_conn_handle(event->connect.conn_handle); } if (event->connect.status != 0) { /* Connection failed; resume advertising. */ bleuart_advertise(); } return 0; case BLE_GAP_EVENT_DISCONNECT: /* Connection terminated; resume advertising. */ bleuart_advertise(); return 0; case BLE_GAP_EVENT_ADV_COMPLETE: /* Advertising terminated; resume advertising. */ bleuart_advertise(); return 0; case BLE_GAP_EVENT_REPEAT_PAIRING: /* We already have a bond with the peer, but it is attempting to * establish a new secure link. This app sacrifices security for * convenience: just throw away the old bond and accept the new link. */ /* Delete the old bond. */ rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc); assert(rc == 0); ble_store_util_delete_peer(&desc.peer_id_addr); /* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host should * continue with the pairing operation. */ return BLE_GAP_REPEAT_PAIRING_RETRY; } return 0; }
/** * The nimble host executes this callback when a GAP event occurs. The * application associates a GAP event callback with each connection that forms. * blesplit uses the same callback for all connections. * * @param event The type of event being signalled. * @param ctxt Various information pertaining to the event. * @param arg Application-specified argument; unuesd by * blesplit. * * @return 0 if the application successfully handled the * event; nonzero on failure. The semantics * of the return code is specific to the * particular GAP event being signalled. */ static int blesplit_gap_event(struct ble_gap_event *event, void *arg) { struct ble_gap_conn_desc desc; int rc; switch (event->type) { case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ BLESPLIT_LOG(INFO, "connection %s; status=%d ", event->connect.status == 0 ? "established" : "failed", event->connect.status); if (event->connect.status == 0) { rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); blesplit_print_conn_desc(&desc); } BLESPLIT_LOG(INFO, "\n"); if (event->connect.status != 0) { /* Connection failed; resume advertising. */ blesplit_advertise(); } return 0; case BLE_GAP_EVENT_DISCONNECT: BLESPLIT_LOG(INFO, "disconnect; reason=%d ", event->disconnect.reason); blesplit_print_conn_desc(&event->disconnect.conn); BLESPLIT_LOG(INFO, "\n"); /* Connection terminated; resume advertising. */ blesplit_advertise(); return 0; case BLE_GAP_EVENT_CONN_UPDATE: /* The central has updated the connection parameters. */ BLESPLIT_LOG(INFO, "connection updated; status=%d ", event->conn_update.status); rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); blesplit_print_conn_desc(&desc); BLESPLIT_LOG(INFO, "\n"); return 0; case BLE_GAP_EVENT_ADV_COMPLETE: BLESPLIT_LOG(INFO, "advertise complete; reason=%d\n", event->adv_complete.reason); blesplit_advertise(); return 0; case BLE_GAP_EVENT_ENC_CHANGE: /* Encryption has been enabled or disabled for this connection. */ BLESPLIT_LOG(INFO, "encryption change event; status=%d ", event->enc_change.status); rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); blesplit_print_conn_desc(&desc); BLESPLIT_LOG(INFO, "\n"); return 0; case BLE_GAP_EVENT_SUBSCRIBE: BLESPLIT_LOG(INFO, "subscribe event; conn_handle=%d attr_handle=%d " "reason=%d prevn=%d curn=%d previ=%d curi=%d\n", event->subscribe.conn_handle, event->subscribe.attr_handle, event->subscribe.reason, event->subscribe.prev_notify, event->subscribe.cur_notify, event->subscribe.prev_indicate, event->subscribe.cur_indicate); return 0; case BLE_GAP_EVENT_MTU: BLESPLIT_LOG(INFO, "mtu update event; conn_handle=%d cid=%d mtu=%d\n", event->mtu.conn_handle, event->mtu.channel_id, event->mtu.value); return 0; case BLE_GAP_EVENT_REPEAT_PAIRING: /* We already have a bond with the peer, but it is attempting to * establish a new secure link. This app sacrifices security for * convenience: just throw away the old bond and accept the new link. */ /* Delete the old bond. */ rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc); assert(rc == 0); ble_store_util_delete_peer(&desc.peer_id_addr); /* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host should * continue with the pairing operation. */ return BLE_GAP_REPEAT_PAIRING_RETRY; } return 0; }