| 58 | } |
| 59 | |
| 60 | int BluetoothHelper::FindSDPChannel(const std::string &deviceAddr, uint8_t *uuid) { |
| 61 | bdaddr_t address; |
| 62 | if(str2ba(deviceAddr.c_str(), &address) != 0) { |
| 63 | spdlog::error("Invalid Bluetooth address format: {}", deviceAddr); |
| 64 | return -1; |
| 65 | } |
| 66 | |
| 67 | bdaddr_t bdAny = {{0, 0, 0, 0, 0, 0}}; |
| 68 | sdp_session_t *session = sdp_connect(&bdAny, &address, SDP_RETRY_IF_BUSY); |
| 69 | if(!session) { |
| 70 | spdlog::error("sdp_connect() failed. (Code={})", errno); |
| 71 | return -1; |
| 72 | } |
| 73 | |
| 74 | uuid_t uuid128; |
| 75 | sdp_uuid128_create(&uuid128, uuid); |
| 76 | uint32_t range = 0x0000ffff; |
| 77 | sdp_list_t *responseList = nullptr; |
| 78 | sdp_list_t *searchList = sdp_list_append(nullptr, &uuid128); |
| 79 | sdp_list_t *attrIdList = sdp_list_append(nullptr, &range); |
| 80 | |
| 81 | int success = sdp_service_search_attr_req(session, searchList, SDP_ATTR_REQ_RANGE, attrIdList, &responseList); |
| 82 | sdp_list_free(searchList, nullptr); |
| 83 | sdp_list_free(attrIdList, nullptr); |
| 84 | if(success != 0) { |
| 85 | spdlog::error("sdp_service_search_attr_req() failed. (Code={})", errno); |
| 86 | sdp_close(session); |
| 87 | return -1; |
| 88 | } |
| 89 | |
| 90 | success = sdp_list_len(responseList); |
| 91 | if(success <= 0) { |
| 92 | spdlog::error("sdp_list_len() failed. (Code={})", success); |
| 93 | sdp_close(session); |
| 94 | return -1; |
| 95 | } |
| 96 | |
| 97 | int channel = 0; |
| 98 | sdp_list_t *responses = responseList; |
| 99 | while(responses) { |
| 100 | auto record = (sdp_record_t *)responses->data; |
| 101 | sdp_list_t *protoList = nullptr; |
| 102 | success = sdp_get_access_protos(record, &protoList); |
| 103 | if(success != 0) { |
| 104 | spdlog::error("sdp_get_access_protos() failed. (Code={})", success); |
| 105 | sdp_close(session); |
| 106 | sdp_list_free(responseList, nullptr); |
| 107 | return -1; |
| 108 | } |
| 109 | |
| 110 | sdp_list_t *protocol = protoList; |
| 111 | while(protocol) { |
| 112 | auto pds = (sdp_list_t *)protocol->data; |
| 113 | int protocolCount = 0; |
| 114 | while(pds) { |
| 115 | auto d = (sdp_data_t *)pds->data; |
| 116 | while(d) { |
| 117 | switch(d->dtd) { |
nothing calls this directly
no outgoing calls
no test coverage detected