/* LISTING_START(HandleSDPQUeryResult): Handling query result chunks. */ static void handle_sdp_client_query_result(sdp_query_event_t * event){ sdp_query_attribute_value_event_t * ve; sdp_query_complete_event_t * ce; switch (event->type){ case SDP_QUERY_ATTRIBUTE_VALUE: ve = (sdp_query_attribute_value_event_t*) event; // handle new record if (ve->record_id != record_id){ record_id = ve->record_id; printf("\n---\nRecord nr. %u\n", record_id); } assertBuffer(ve->attribute_length); attribute_value[ve->data_offset] = ve->data; if ((uint16_t)(ve->data_offset+1) == ve->attribute_length){ printf("Attribute 0x%04x: ", ve->attribute_id); de_dump_data_element(attribute_value); } break; case SDP_QUERY_COMPLETE: ce = (sdp_query_complete_event_t*) event; printf("General query done with status %d.\n\n", ce->status); exit(0); break; } }
static void handle_sdp_parser_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ switch (packet[0]){ case SDP_EVENT_QUERY_ATTRIBUTE_VALUE: test_attribute_value_event(packet); // handle new record if (sdp_event_query_attribute_byte_get_record_id(packet) != record_id){ record_id = sdp_event_query_attribute_byte_get_record_id(packet); } // buffer data assertBuffer(sdp_event_query_attribute_byte_get_attribute_length(packet)); attribute_value[sdp_event_query_attribute_byte_get_data_offset(packet)] = sdp_event_query_attribute_byte_get_data(packet); break; case SDP_EVENT_QUERY_COMPLETE: printf("General query done with status %d.\n", sdp_event_query_complete_get_status(packet)); break; } }
/* LISTING_START(HandleSDPQUeryResult): Extracting BNEP Protcol UUID and L2CAP PSM */ static void handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ /* LISTING_PAUSE */ des_iterator_t des_list_it; des_iterator_t prot_it; char *str; switch (hci_event_packet_get_type(packet)){ case SDP_EVENT_QUERY_ATTRIBUTE_VALUE: // handle new record if (sdp_event_query_attribute_byte_get_record_id(packet) != record_id){ record_id = sdp_event_query_attribute_byte_get_record_id(packet); printf("\n---\nRecord nr. %u\n", record_id); } assertBuffer(sdp_event_query_attribute_byte_get_attribute_length(packet)); attribute_value[sdp_event_query_attribute_byte_get_data_offset(packet)] = sdp_event_query_attribute_byte_get_data(packet); if ((uint16_t)(sdp_event_query_attribute_byte_get_data_offset(packet)+1) == sdp_event_query_attribute_byte_get_attribute_length(packet)){ /* LISTING_RESUME */ /* @text The Service Class ID List is a Data Element Sequence (DES) of UUIDs. * The BNEP PAN protocol UUID is within this list. */ switch(sdp_event_query_attribute_byte_get_attribute_id(packet)){ // 0x0001 "Service Class ID List" case SDP_ServiceClassIDList: if (de_get_element_type(attribute_value) != DE_DES) break; for (des_iterator_init(&des_list_it, attribute_value); des_iterator_has_more(&des_list_it); des_iterator_next(&des_list_it)){ uint8_t * element = des_iterator_get_element(&des_list_it); if (de_get_element_type(element) != DE_UUID) continue; uint32_t uuid = de_get_uuid32(element); switch (uuid){ case PANU_UUID: case NAP_UUID: case GN_UUID: printf(" ** Attribute 0x%04x: BNEP PAN protocol UUID: %04x\n", sdp_event_query_attribute_byte_get_attribute_id(packet), uuid); break; default: break; } } break; /* LISTING_PAUSE */ // 0x0100 "Service Name" case 0x0100: // 0x0101 "Service Description" case 0x0101: str = get_string_from_data_element(attribute_value); printf(" ** Attribute 0x%04x: %s\n", sdp_event_query_attribute_byte_get_attribute_id(packet), str); free(str); break; /* LISTING_RESUME */ /* @text The Protocol Descriptor List is DES * which contains one DES for each protocol. For PAN serivces, it contains * a DES with the L2CAP Protocol UUID and a PSM, * and another DES with the BNEP UUID and the the BNEP version. */ case SDP_ProtocolDescriptorList:{ printf(" ** Attribute 0x%04x: ", sdp_event_query_attribute_byte_get_attribute_id(packet)); uint16_t l2cap_psm = 0; uint16_t bnep_version = 0; for (des_iterator_init(&des_list_it, attribute_value); des_iterator_has_more(&des_list_it); des_iterator_next(&des_list_it)){ if (des_iterator_get_type(&des_list_it) != DE_DES) continue; uint8_t * des_element = des_iterator_get_element(&des_list_it); des_iterator_init(&prot_it, des_element); uint8_t * element = des_iterator_get_element(&prot_it); if (de_get_element_type(element) != DE_UUID) continue; uint32_t uuid = de_get_uuid32(element); switch (uuid){ case SDP_L2CAPProtocol: if (!des_iterator_has_more(&prot_it)) continue; des_iterator_next(&prot_it); de_element_get_uint16(des_iterator_get_element(&prot_it), &l2cap_psm); break; case SDP_BNEPProtocol: if (!des_iterator_has_more(&prot_it)) continue; des_iterator_next(&prot_it); de_element_get_uint16(des_iterator_get_element(&prot_it), &bnep_version); break; default: break; } } printf("l2cap_psm 0x%04x, bnep_version 0x%04x\n", l2cap_psm, bnep_version); } break; /* LISTING_PAUSE */ default: break; } } break; case SDP_EVENT_QUERY_COMPLETE: printf("General query done with status %d.\n\n", sdp_event_query_complete_get_status(packet)); break; } /* LISTING_RESUME */ }