1SDP for BTstack 2 3General: 4 * Protocol: request/response, half-duplex 5 * Endianess = BIG/Network! not little endian as usual 6 * Server maintains a list of service records 7 * service (record) is instance of a service class 8 * a service record = list of service attributes 9 * service attribute = { attribute ID, attribute value } 10 * service record handle: 32 bit number (used internally) 11 * service record handle 12 * 0x00000000 used for SDP server, 13 * 0x00000001-0x0000FFFF reserved 14 * attribute ID: 16 bit (pre-defined), data element 15 * attribute value: var length field, data element 16 * service class: UUID (128 bit) stored as ServiceClassIDList attribute 17 * service classes form an inheritance tree, which each subclass specifying more attributes 18 * Bluetooth Base UUID: 00000000-0000-1000-8000- 00805F9B34FB 19 * 16 bit UUID => Bluetooth Base UUID + 16_bit_value * 2^96 20 * 32 bit UUID => Bluetooth Base UUID + 32_bit_value * 2^96 21 * Service Search Pattern: list of UUIDs required in a service record to be present for a match 22 * Browse Group UUID: all top-level services contain browse group UUID in the BrowseGroupList attribute 23 * Service Browsing Hierarchy is possible - not supported by BTstack for now 24 * Data representation: like XML 25 * PDU: PDU ID(1), Transaction ID(2), Param length(2), params* 26 * ServiceSearchRequest/ServiceSearchResponse: list of UUIDs to be matched by service record -> list of service record handles 27 * ServiceAttributeRequest/ServiceAttributeResponse: get list of attributes for a given service record handle 28 * Service SearchAttributeRequest/SearchAtrributeResponse: for all service records that match ServiceSearchPattern: return list of attributes that match AttributeIDList 29 * Transaction ID of response = ID of request 30 * param lengh in bytes 31 * Continuation state parameter: send to client to denote further data (max 16 bytes) 32 * To get RFCOMM channel, we use SDP_ServiceSearchAttributeRequest(RFCOMM service, RFCOMM type) 33 34Implementation: 35 * DataElement creation API - no extra memory 36 * helper functions: 37 * attribute ID in AttributeIDList 38 * get attributes specified by AttributeIDList 39 * service record contains UUID 40 * does service search pattern matches record 41 * get attribute value (DE) for attribute ID 42 * create service record handle (incl. ServiceRecordHandle management) 43 * visitor pattern for DES traversal 44 * call handler on every element: int handle_element(uint8_t element, void *context) - done? 45 * Dispatch packets for protocols implemented by BTdaemon 46 * add packet_handler to l2cap_service_t and l2cap_channel_t 47 * pass acl/event handler to l2cap_register_service 48 * copy acl/event handler to l2cap_channel_t 49 * if specified, call custom packet_handler instead of general one 50 * acl -> l2cap -> l2cap_channel -> acl/event handler OR daemon 51 * LinkedList of service records 52 * alloc { btstack_linked_list_item_t ; ServiceRecord } 53 * add service record: service record -> service record handle or 0 54 * remove service record: service record handle (32bit) 55 * SDP as part of stack itself 56 * Register SDP PSM=0x0001 57 * Accept incoming connections 58 * Define all SDP requests/response PDU-IDs 59 * Handle all three SDP requests by denying 60 * ServiceSearchRequest 61 * ServiceAttributeRequest 62 * ServiceSearchAttributeRequest 63 * Dynamically create denial 64 * Handle ServiceSearchAttributeRequest 65 * Handle ServiceSearchRequest 66 * Handle ServiceAttributeRequest 67 * Extract sdp_create_error_response 68 * call sdp_create_error_response when service record handle is invalid 69 * Define and implement client commands & events for SDP registry 70 * Store client connection in service record item 71 * Unregister service when client disconnects 72 * Send SDP_ErrorResponse for invalid records 73 * Implement Continuation: limited nr of ServiceRecordHandles or AttributeList(s)ByteCount 74 * ServiceSearchRequest: Iterate over all records - use record index as cont. 75 * ServiceAttributeRequest: Iterate over all attributes - use attribute index as cont. 76 * ServiceSearchAttributeRequest: Iterate over all records and attributes. Use {record, attribute} index 77 * Test continuation for all three commands 78 * add 2 records, get all data back with limited result size 79 * sdp_handle_service_search_attribute_request 80* implement SDP_sequence_traversal -> simplify traversing 81 82 * keep track of remote incoming MTU during l2cap establishment 83 * segment l2cap packets according to MTU size 84 85 * Packet for HID is shortened - bluez uses 0x0096 as MTU - segment packets 86 * String Handling in Linux SDP/sdptool probably buggy 87 88 89