source: asp3_tinet_ecnl_arm/trunk/btstack/src/pan.c@ 352

Last change on this file since 352 was 352, checked in by coas-nagasima, 6 years ago

arm向けASP3版ECNLを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 8.9 KB
Line 
1/*
2 * Copyright (C) 2014 by BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holders nor the names of
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * 4. Any redistribution, use, or modification is done solely for
17 * personal benefit and not for any commercial purpose or for
18 * monetary gain.
19 *
20 * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * Please inquire about commercial licensing options at btstack@ringwald.ch
34 *
35 */
36
37/*
38 * pan.h
39 *
40 * Created by Milanka Ringwald on 10/16/14.
41 */
42
43#include "pan.h"
44
45#include <stdio.h>
46#include <string.h>
47
48#include <btstack/sdp_util.h>
49
50static const char default_panu_service_name[] = "Personal Ad-hoc User Service";
51static const char default_panu_service_desc[] = "Personal Ad-hoc User Service";
52
53static const char default_nap_service_name[] = "Network Access Point Service";
54static const char default_nap_service_desc[] = "Personal Ad-hoc Network Service which provides access to a network";
55
56static const char default_gn_service_name[] = "Group Ad-hoc Network Service";
57static const char default_gn_service_desc[] = "Personal Group Ad-hoc Network Service";
58
59#define NETWORK_TYPE_IPv4 0x0800
60#define NETWORK_TYPE_ARP 0x0806
61#define NETWORK_TYPE_IPv6 0x86DD
62
63#define IP_PROTOCOL_ICMP_IPv4 0x0001
64#define IP_PROTOCOL_ICMP_IPv6 0x003a
65#define IP_PROTOCOL_UDP 0x0011
66
67static uint16_t network_packet_types_table[] = { NETWORK_TYPE_IPv4, NETWORK_TYPE_ARP, 0}; // 0 as end of list
68
69void pan_create_service(bnep_service_uuid_t service_uuid, uint8_t *service, const char *name, const char *descriptor,
70 security_description_t security_desc, net_access_type_t net_access_type, uint32_t max_net_access_rate,
71 const char *IPv4Subnet, const char *IPv6Subnet){
72
73 uint8_t* attribute;
74 uint16_t *network_packet_types = network_packet_types_table;
75 de_create_sequence(service);
76
77 // 0x0000 "Service Record Handle"
78 de_add_number(service, DE_UINT, DE_SIZE_16, SDP_ServiceRecordHandle);
79 de_add_number(service, DE_UINT, DE_SIZE_32, 0x10001);
80
81 // 0x0001 "Service Class ID List"
82 de_add_number(service, DE_UINT, DE_SIZE_16, SDP_ServiceClassIDList);
83 attribute = de_push_sequence(service);
84 {
85 // "UUID for PAN Service"
86 de_add_number(attribute, DE_UUID, DE_SIZE_32, service_uuid);
87 }
88 de_pop_sequence(service, attribute);
89
90 // 0x0004 "Protocol Descriptor List"
91 de_add_number(service, DE_UINT, DE_SIZE_16, SDP_ProtocolDescriptorList);
92 attribute = de_push_sequence(service);
93 {
94 uint8_t* l2cpProtocol = de_push_sequence(attribute);
95 {
96 de_add_number(l2cpProtocol, DE_UUID, DE_SIZE_16, 0x0100);
97 de_add_number(l2cpProtocol, DE_UINT, DE_SIZE_16, SDP_BNEPProtocol); // l2cap psm
98 }
99 de_pop_sequence(attribute, l2cpProtocol);
100
101 uint8_t* bnep = de_push_sequence(attribute);
102 {
103 de_add_number(bnep, DE_UUID, DE_SIZE_16, 0x000F); // bnep
104 de_add_number(bnep, DE_UINT, DE_SIZE_16, 0x0100); // version
105
106 uint8_t * net_packet_type_list = de_push_sequence(bnep);
107 {
108 if (network_packet_types){
109 while (*network_packet_types){
110 de_add_number(net_packet_type_list, DE_UINT, DE_SIZE_16, *network_packet_types++);
111 }
112 }
113 }
114 de_pop_sequence(bnep, net_packet_type_list);
115 }
116 de_pop_sequence(attribute, bnep);
117 }
118 de_pop_sequence(service, attribute);
119
120 // 0x0005 "Public Browse Group"
121 de_add_number(service, DE_UINT, DE_SIZE_16, SDP_BrowseGroupList); // public browse group
122 attribute = de_push_sequence(service);
123 {
124 de_add_number(attribute, DE_UUID, DE_SIZE_16, 0x1002 );
125 }
126 de_pop_sequence(service, attribute);
127
128 // 0x0006 "LanguageBaseAttributeIDList"
129 de_add_number(service, DE_UINT, DE_SIZE_16, SDP_LanguageBaseAttributeIDList);
130 attribute = de_push_sequence(service);
131 {
132 de_add_number(attribute, DE_UINT, DE_SIZE_16, 0x656e);
133 de_add_number(attribute, DE_UINT, DE_SIZE_16, 0x006a);
134 de_add_number(attribute, DE_UINT, DE_SIZE_16, 0x0100); // Base for Service Name and Service Description
135 }
136 de_pop_sequence(service, attribute);
137
138 // 0x0008 "Service Availability", optional
139 // de_add_number(service, DE_UINT, DE_SIZE_16, 0x0008);
140 // de_add_number(service, DE_UINT, DE_SIZE_8, service_availability);
141
142 // 0x0009 "Bluetooth Profile Descriptor List"
143 de_add_number(service, DE_UINT, DE_SIZE_16, SDP_BluetoothProfileDescriptorList);
144 attribute = de_push_sequence(service);
145 {
146 uint8_t *sppProfile = de_push_sequence(attribute);
147 {
148 de_add_number(sppProfile, DE_UUID, DE_SIZE_16, service_uuid);
149 de_add_number(sppProfile, DE_UINT, DE_SIZE_16, 0x0100); // Verision 1.0
150 }
151 de_pop_sequence(attribute, sppProfile);
152 }
153 de_pop_sequence(service, attribute);
154
155 // 0x0100 "Service Name"
156 de_add_number(service, DE_UINT, DE_SIZE_16, 0x0100);
157 if (name){
158 de_add_data(service, DE_STRING, strlen(name), (uint8_t *) name);
159 } else {
160 switch (service_uuid){
161 case PANU_UUID:
162 de_add_data(service, DE_STRING, strlen(default_panu_service_name), (uint8_t *) default_panu_service_name);
163 break;
164 case NAP_UUID:
165 de_add_data(service, DE_STRING, strlen(default_nap_service_name), (uint8_t *) default_nap_service_name);
166 break;
167 case GN_UUID:
168 de_add_data(service, DE_STRING, strlen(default_gn_service_name), (uint8_t *) default_gn_service_name);
169 break;
170 default:
171 break;
172 }
173 }
174
175 // 0x0101 "Service Description"
176 de_add_number(service, DE_UINT, DE_SIZE_16, 0x0101);
177 if (descriptor){
178 de_add_data(service, DE_STRING, strlen(descriptor), (uint8_t *) descriptor);
179 } else {
180 switch (service_uuid){
181 case PANU_UUID:
182 de_add_data(service, DE_STRING, strlen(default_panu_service_desc), (uint8_t *) default_panu_service_desc);
183 break;
184 case NAP_UUID:
185 de_add_data(service, DE_STRING, strlen(default_nap_service_desc), (uint8_t *) default_nap_service_desc);
186 break;
187 case GN_UUID:
188 de_add_data(service, DE_STRING, strlen(default_gn_service_desc), (uint8_t *) default_gn_service_desc);
189 break;
190 default:
191 break;
192 }
193 }
194
195 // 0x030A "Security Description"
196 de_add_number(service, DE_UINT, DE_SIZE_16, 0x030A);
197 de_add_number(service, DE_UINT, DE_SIZE_16, security_desc);
198
199 if (service_uuid == PANU_UUID) return;
200
201 if (IPv4Subnet){
202 // 0x030D "IPv4Subnet", optional
203 de_add_number(service, DE_UINT, DE_SIZE_16, 0x030D);
204 de_add_data(service, DE_STRING, strlen(IPv4Subnet), (uint8_t *) IPv4Subnet);
205 }
206
207 if (IPv6Subnet){
208 // 0x030E "IPv6Subnet", optional
209 de_add_number(service, DE_UINT, DE_SIZE_16, 0x030E);
210 de_add_data(service, DE_STRING, strlen(IPv6Subnet), (uint8_t *) IPv6Subnet);
211 }
212
213 if (service_uuid == GN_UUID) return;
214
215 // 0x030B "NetAccessType"
216 de_add_number(service, DE_UINT, DE_SIZE_16, 0x030B);
217 de_add_number(service, DE_UINT, DE_SIZE_16, net_access_type);
218
219 // 0x030C "MaxNetAccessRate"
220 de_add_number(service, DE_UINT, DE_SIZE_16, 0x030C);
221 de_add_number(service, DE_UINT, DE_SIZE_32, max_net_access_rate);
222
223}
224
225
226void pan_create_nap_service(uint8_t *service, const char *name, const char *description, security_description_t security_desc,
227 net_access_type_t net_access_type, uint32_t max_net_access_rate, const char *IPv4Subnet, const char *IPv6Subnet){
228
229 pan_create_service(NAP_UUID, service, name, description, security_desc, net_access_type, max_net_access_rate, IPv4Subnet, IPv6Subnet);
230}
231
232void pan_create_gn_service(uint8_t *service, const char *name, const char *description, security_description_t security_desc,
233 const char *IPv4Subnet, const char *IPv6Subnet){
234 pan_create_service(GN_UUID, service, name, description, security_desc, PAN_NET_ACCESS_TYPE_NONE, 0, IPv4Subnet, IPv6Subnet);
235}
236
237void pan_create_panu_service(uint8_t *service, const char *name, const char *description, security_description_t security_desc){
238 pan_create_service(PANU_UUID, service, name, description, security_desc, PAN_NET_ACCESS_TYPE_NONE, 0, NULL, NULL);
239}
Note: See TracBrowser for help on using the repository browser.