Add bluetooth channel connection callback to the incomplete BluetoothHost demo.
[pub/USBasp.git] / Demos / Host / Incomplete / BluetoothHost / Lib / ServiceDiscoveryProtocol.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #define INCLUDE_FROM_SERVICEDISCOVERYPROTOCOL_C
32 #include "ServiceDiscoveryProtocol.h"
33
34 void ServiceDiscovery_ProcessPacket(void* Data, Bluetooth_Channel_t* Channel)
35 {
36 SDP_PDUHeader_t* SDPHeader = (SDP_PDUHeader_t*)Data;
37 SDPHeader->ParameterLength = SwapEndian_16(SDPHeader->ParameterLength);
38
39 BT_SDP_DEBUG(1, "SDP Packet Received", NULL);
40 BT_SDP_DEBUG(2, "-- PDU ID: 0x%02X", SDPHeader->PDU);
41 BT_SDP_DEBUG(2, "-- Param Length: 0x%04X", SDPHeader->ParameterLength);
42
43 switch (SDPHeader->PDU)
44 {
45 case SDP_PDU_SERVICESEARCHREQUEST:
46 ServiceDiscovery_ProcessServiceSearch(SDPHeader);
47 break;
48 case SDP_PDU_SERVICEATTRIBUTEREQUEST:
49 ServiceDiscovery_ProcessServiceAttribute(SDPHeader);
50 break;
51 case SDP_PDU_SERVICESEARCHATTRIBUTEREQUEST:
52 ServiceDiscovery_ProcessServiceSearchAttribute(SDPHeader);
53 break;
54 }
55 }
56
57 static void ServiceDiscovery_ProcessServiceSearch(SDP_PDUHeader_t* SDPHeader)
58 {
59 BT_SDP_DEBUG(1, "<< Service Search", NULL);
60 }
61
62 static void ServiceDiscovery_ProcessServiceAttribute(SDP_PDUHeader_t* SDPHeader)
63 {
64 BT_SDP_DEBUG(1, "<< Service Attribute", NULL);
65 }
66
67 static void ServiceDiscovery_ProcessServiceSearchAttribute(SDP_PDUHeader_t* SDPHeader)
68 {
69 uint8_t* CurrentParameter = ((uint8_t*)SDPHeader + sizeof(SDP_PDUHeader_t));
70
71 BT_SDP_DEBUG(1, "<< Service Search Attribute", NULL);
72
73 uint8_t ServicePatternLength = ServiceDiscovery_GetDataElementSize(CurrentParameter);
74 while (ServicePatternLength)
75 {
76 uint8_t UUIDLength = ServiceDiscovery_GetDataElementSize(CurrentParameter);
77 uint8_t UUID[16];
78
79 memset(UUID, 0x00, sizeof(UUID));
80 memcpy(&UUID[sizeof(UUID) - UUIDLength], CurrentParameter, UUIDLength);
81
82 BT_SDP_DEBUG(2, "-- UUID: 0x%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
83 UUID[0], UUID[1], UUID[2], UUID[3], UUID[4], UUID[5], UUID[6], UUID[7],
84 UUID[8], UUID[9], UUID[10], UUID[11], UUID[12], UUID[13], UUID[14], UUID[15]);
85
86 ServicePatternLength -= UUIDLength;
87 }
88
89 uint16_t MaxAttributeSize = ServiceDiscovery_Read16BitParameter(CurrentParameter);
90
91 uint8_t AttributeIDListLength = ServiceDiscovery_GetDataElementSize(CurrentParameter);
92 while (AttributeIDListLength)
93 {
94 uint8_t AttributeLength = ServiceDiscovery_GetDataElementSize(CurrentParameter);
95
96 BT_SDP_DEBUG(2, "-- Attribute Length: 0x%04X", AttributeLength);
97
98 AttributeIDListLength -= AttributeLength;
99 }
100 }
101
102 static uint32_t ServiceDiscovery_GetDataElementSize(void* DataElementHeader)
103 {
104 uint8_t SizeIndex = (*((uint8_t*)DataElementHeader++) & 0x07);
105
106 switch (SizeIndex)
107 {
108 case 0:
109 return 1;
110 case 1:
111 return 2;
112 case 2:
113 return 4;
114 case 3:
115 return 8;
116 case 4:
117 return 16;
118 case 5:
119 return *((uint8_t*)DataElementHeader++);
120 case 6:
121 return *((uint16_t*)DataElementHeader++);
122 default:
123 return *((uint32_t*)DataElementHeader++);
124 }
125 }