xref: /btstack/doc/notes/SDP.txt (revision add0254b7d6c95a90f0d01ec68df2c0159c66f40)
11ca3442bSMatthias RingwaldSDP for BTstack
21ca3442bSMatthias Ringwald
31ca3442bSMatthias RingwaldGeneral:
41ca3442bSMatthias Ringwald * Protocol: request/response, half-duplex
51ca3442bSMatthias Ringwald * Endianess = BIG/Network! not little endian as usual
61ca3442bSMatthias Ringwald * Server maintains a list of service records
71ca3442bSMatthias Ringwald * service (record) is instance of a service class
81ca3442bSMatthias Ringwald * a service record = list of service attributes
91ca3442bSMatthias Ringwald * service attribute = { attribute ID, attribute value }
101ca3442bSMatthias Ringwald * service record handle: 32 bit number (used internally)
111ca3442bSMatthias Ringwald * service record handle
121ca3442bSMatthias Ringwald   * 0x00000000 used for SDP server,
131ca3442bSMatthias Ringwald   * 0x00000001-0x0000FFFF reserved
141ca3442bSMatthias Ringwald * attribute ID: 16 bit (pre-defined), data element
151ca3442bSMatthias Ringwald * attribute value: var length field, data element
161ca3442bSMatthias Ringwald * service class: UUID (128 bit) stored as ServiceClassIDList attribute
171ca3442bSMatthias Ringwald * service classes form an inheritance tree, which each subclass specifying more attributes
181ca3442bSMatthias Ringwald * Bluetooth Base UUID: 00000000-0000-1000-8000- 00805F9B34FB
191ca3442bSMatthias Ringwald * 16 bit UUID => Bluetooth Base UUID + 16_bit_value * 2^96
201ca3442bSMatthias Ringwald * 32 bit UUID => Bluetooth Base UUID + 32_bit_value * 2^96
211ca3442bSMatthias Ringwald * Service Search Pattern: list of UUIDs required in a service record to be present for a match
221ca3442bSMatthias Ringwald * Browse Group UUID: all top-level services contain browse group UUID in the BrowseGroupList attribute
231ca3442bSMatthias Ringwald * Service Browsing Hierarchy is possible - not supported by BTstack for now
241ca3442bSMatthias Ringwald * Data representation: like XML
251ca3442bSMatthias Ringwald * PDU: PDU ID(1), Transaction ID(2), Param length(2), params*
261ca3442bSMatthias Ringwald   * ServiceSearchRequest/ServiceSearchResponse: list of UUIDs to be matched by service record -> list of service record handles
271ca3442bSMatthias Ringwald   * ServiceAttributeRequest/ServiceAttributeResponse: get list of attributes for a given service record handle
281ca3442bSMatthias Ringwald   * Service SearchAttributeRequest/SearchAtrributeResponse: for all service records that match ServiceSearchPattern: return list of attributes that match AttributeIDList
291ca3442bSMatthias Ringwald   * Transaction ID of response = ID of request
301ca3442bSMatthias Ringwald   * param lengh in bytes
311ca3442bSMatthias Ringwald * Continuation state parameter: send to client to denote further data (max 16 bytes)
321ca3442bSMatthias Ringwald * To get RFCOMM channel, we use SDP_ServiceSearchAttributeRequest(RFCOMM service, RFCOMM type)
331ca3442bSMatthias Ringwald
341ca3442bSMatthias RingwaldImplementation:
351ca3442bSMatthias Ringwald * DataElement creation API - no extra memory
361ca3442bSMatthias Ringwald * helper functions:
371ca3442bSMatthias Ringwald   * attribute ID in AttributeIDList
381ca3442bSMatthias Ringwald   * get attributes specified by AttributeIDList
391ca3442bSMatthias Ringwald   * service record contains UUID
401ca3442bSMatthias Ringwald   * does service search pattern matches record
411ca3442bSMatthias Ringwald   * get attribute value (DE) for attribute ID
421ca3442bSMatthias Ringwald   * create service record handle (incl. ServiceRecordHandle management)
431ca3442bSMatthias Ringwald * visitor pattern for DES traversal
441ca3442bSMatthias Ringwald   * call handler on every element: int handle_element(uint8_t element, void *context) - done?
451ca3442bSMatthias Ringwald * Dispatch packets for protocols implemented by BTdaemon
461ca3442bSMatthias Ringwald   * add packet_handler to l2cap_service_t and l2cap_channel_t
47*add0254bSMatthias Ringwald     * pass acl/event handler to l2cap_register_service
481ca3442bSMatthias Ringwald     * copy acl/event handler to l2cap_channel_t
491ca3442bSMatthias Ringwald     * if specified, call custom packet_handler instead of general one
501ca3442bSMatthias Ringwald   * acl -> l2cap -> l2cap_channel -> acl/event handler OR daemon
511ca3442bSMatthias Ringwald * LinkedList of service records
52665d90f2SMatthias Ringwald   * alloc { btstack_linked_list_item_t ; ServiceRecord }
531ca3442bSMatthias Ringwald   * add service record: service record -> service record handle or 0
541ca3442bSMatthias Ringwald   * remove service record: service record handle (32bit)
551ca3442bSMatthias Ringwald * SDP as part of stack itself
561ca3442bSMatthias Ringwald   * Register SDP PSM=0x0001
571ca3442bSMatthias Ringwald   * Accept incoming connections
581ca3442bSMatthias Ringwald   * Define all SDP requests/response PDU-IDs
591ca3442bSMatthias Ringwald   * Handle all three SDP requests by denying
601ca3442bSMatthias Ringwald     * ServiceSearchRequest
611ca3442bSMatthias Ringwald     * ServiceAttributeRequest
621ca3442bSMatthias Ringwald     * ServiceSearchAttributeRequest
631ca3442bSMatthias Ringwald   * Dynamically create denial
641ca3442bSMatthias Ringwald   * Handle ServiceSearchAttributeRequest
651ca3442bSMatthias Ringwald   * Handle ServiceSearchRequest
661ca3442bSMatthias Ringwald   * Handle ServiceAttributeRequest
671ca3442bSMatthias Ringwald   * Extract sdp_create_error_response
681ca3442bSMatthias Ringwald   * call sdp_create_error_response when service record handle is invalid
691ca3442bSMatthias Ringwald * Define and implement client commands & events for SDP registry
701ca3442bSMatthias Ringwald * Store client connection in service record item
711ca3442bSMatthias Ringwald * Unregister service when client disconnects
721ca3442bSMatthias Ringwald * Send SDP_ErrorResponse for invalid records
731ca3442bSMatthias Ringwald * Implement Continuation: limited nr of ServiceRecordHandles or AttributeList(s)ByteCount
741ca3442bSMatthias Ringwald   * ServiceSearchRequest: Iterate over all records - use record index as cont.
751ca3442bSMatthias Ringwald   * ServiceAttributeRequest: Iterate over all attributes - use attribute index as cont.
761ca3442bSMatthias Ringwald   * ServiceSearchAttributeRequest: Iterate over all records and attributes. Use {record, attribute} index
771ca3442bSMatthias Ringwald * Test continuation for all three commands
781ca3442bSMatthias Ringwald   * add 2 records, get all data back with limited result size
791ca3442bSMatthias Ringwald * sdp_handle_service_search_attribute_request
801ca3442bSMatthias Ringwald* implement SDP_sequence_traversal -> simplify traversing
811ca3442bSMatthias Ringwald
821ca3442bSMatthias Ringwald * keep track of remote incoming MTU during l2cap establishment
831ca3442bSMatthias Ringwald * segment l2cap packets according to MTU size
841ca3442bSMatthias Ringwald
851ca3442bSMatthias Ringwald * Packet for HID is shortened - bluez uses 0x0096 as MTU - segment packets
861ca3442bSMatthias Ringwald * String Handling in Linux SDP/sdptool probably buggy
871ca3442bSMatthias Ringwald
881ca3442bSMatthias Ringwald
891ca3442bSMatthias Ringwald