| 888 | } |
| 889 | |
| 890 | static void connectEvent(void *the, void *refcon, uint8_t *message, uint16_t messageLength) |
| 891 | { |
| 892 | struct ble_gap_conn_desc *desc = (struct ble_gap_conn_desc *)message; |
| 893 | |
| 894 | if (!gBLE || gBLE->the != the) |
| 895 | return; |
| 896 | modBLE ble = gBLE; |
| 897 | xsBeginHost(the); |
| 898 | modBLEConnection connection = modBLEConnectionFindByAddressAndType(desc->peer_id_addr.val, desc->peer_id_addr.type); |
| 899 | if (!connection) { |
| 900 | // @@ workaround for https://github.com/espressif/esp-idf/issues/5693 |
| 901 | connection = modBLEConnectionGetFirst(); |
| 902 | while (NULL != connection) { |
| 903 | if (kInvalidConnectionID == connection->id) |
| 904 | break; |
| 905 | connection = modBLEConnectionGetNext(connection); |
| 906 | } |
| 907 | if (!connection) |
| 908 | xsUnknownError("connection not found"); |
| 909 | } |
| 910 | |
| 911 | if (0xFFFF != desc->conn_handle) { |
| 912 | if (kInvalidConnectionID != connection->id) { |
| 913 | LOG_GAP_MSG("Ignoring duplicate connect event"); |
| 914 | goto bail; |
| 915 | } |
| 916 | connection->id = desc->conn_handle; |
| 917 | onConnected(desc); |
| 918 | } |
| 919 | else { |
| 920 | LOG_GAP_MSG("BLE_GAP_EVENT_CONNECT failed"); |
| 921 | xsForget(connection->objConnection); |
| 922 | modBLEConnectionRemove(connection); |
| 923 | } |
| 924 | bail: |
| 925 | xsEndHost(ble->the); |
| 926 | downBLEClientUseCount(ble); |
| 927 | } |
| 928 | |
| 929 | static void disconnectEvent(void *the, void *refcon, uint8_t *message, uint16_t messageLength) |
| 930 | { |
nothing calls this directly
no test coverage detected