]> rtime.felk.cvut.cz Git - mirosot.git/blob - bluetooth/bth_command.c
6979574fae6ef305d8fdd860264851544c84f1be
[mirosot.git] / bluetooth / bth_command.c
1 /*******************************************************************\r
2   bluetooth library\r
3 \r
4   bth_command.c - command functions (bth specification) - build command\r
5                   packet\r
6 \r
7   Copyright (C) 2006 by Petr Kovacik petr_kovacik@gmail.com\r
8 \r
9  *******************************************************************/\r
10 \r
11 \r
12 #include <string.h>\r
13 #include <stdlib.h>\r
14 #ifdef BTH_LX\r
15 #include <types.h>\r
16 #include <cpu_def.h>\r
17 #include <h8s2638h.h>\r
18 #include <periph/sci_rs232.h>\r
19 #include <system_def.h>\r
20 \r
21 #else\r
22 #include "types.h"\r
23 #endif\r
24 \r
25 #include "hci.h"\r
26 #include "hci_event.h"\r
27 #include "hci_command.h"\r
28 #include "inline_fce.h"\r
29 \r
30 \r
31 bths_check_command *bth_find_end(bths_check_command *dyn_chan)\r
32 {\r
33    bths_check_command *temp;\r
34    if(dyn_chan!=NULL)\r
35     {\r
36       temp=dyn_chan;\r
37       while (temp->next!=NULL)\r
38       {\r
39         temp=temp->next;             /*put the command to the queue*/\r
40       };\r
41       return temp;\r
42     }\r
43     else\r
44     {\r
45     return NULL;\r
46     };\r
47 };\r
48 \r
49 \r
50 /********************************************************************/\r
51 /***********************   OGF = 0x01    ****************************/\r
52 /*-------------------LINK CONTROL COMMANDS--------------------------*/\r
53 /********************************************************************/\r
54 \r
55 int bth_cmd_inqury(uint8_t length, uint8_t rsp, uint8_t *lap)\r
56 {\r
57 /*------------------------ parts of packet-----------------------*/\r
58     uint8_t *typ_hci_paket;\r
59     hci_command_hdr *hci_headr;\r
60     inquiry_cp *bth_cmd_packet;\r
61     uint16_t i; //used in loops\r
62 /*-------------------------------------------------------------------------------*/\r
63 /*-- determine the size of memory needed for command in buff and determine if it fit there */\r
64 \r
65 \r
66     if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
67     {return 1;};\r
68 /*setup adresses for packet parts + filling of inidividual fields*/\r
69     int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+INQUIRY_CP_SIZE);\r
70 \r
71     bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
72     typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //possition in buff, which is assigned to the packet\r
73     hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer to head\r
74     bth_cmd_packet=(inquiry_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer to parametrs\r
75 \r
76     store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
77     store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY)));\r
78     store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),INQUIRY_CP_SIZE);\r
79 \r
80     /*pokud neni uvedeno lap zvoli se univerzlni*/\r
81     /*if lap is not specified, the universal one is chosen*/\r
82       store_le16((uint8_t*)bth_cmd_packet+INQUIRY_CP____length,length);\r
83       store_le16((uint8_t*)bth_cmd_packet+INQUIRY_CP____num_rsp,rsp);\r
84 \r
85     if(lap==NULL)\r
86     {\r
87       uint8_t lap_univ[]={0x33,0x8b,0x9e};\r
88       memcpy(((uint8_t*)bth_cmd_packet+INQUIRY_CP____lap),&lap_univ,3);\r
89     }\r
90     else{\r
91       for(i=0; i<3; i++) {store_le16((uint8_t*)bth_cmd_packet+INQUIRY_CP____lap+i,*(lap+2-i));};\r
92     };\r
93 \r
94 /*setup position in command array for the next command. Possibility of writing there (address in array = NULL) is checked when writing is realy done.*/\r
95 /*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
96 se overuje, az pri samotnem ukladani */\r
97     if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
98     else{ bth_com_buf_info.aktual=0;};\r
99  return -1;\r
100 };\r
101 \r
102 /*--- 0x01 - 0x000F --- Change_Connection_Packet_Type ---*/\r
103 int change_connection_packet_type(uint16_t handle, uint16_t ptype)\r
104 {\r
105     uint8_t *typ_hci_paket;\r
106     hci_command_hdr *hci_headr;\r
107     set_conn_ptype_cp *bth_cmd_packet;\r
108 /*-- determine the size of memory needed for command in buff and determine if it fit there */\r
109 /*-------------------------------------------------------------------------------*/\r
110 /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
111 \r
112     if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
113     {return 1;};\r
114 /*setup adresses for packet parts + filling of inidividual fields*/\r
115     int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+SET_CONN_PTYPE_CP_SIZE);\r
116     bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
117     typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
118     hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
119     bth_cmd_packet=(set_conn_ptype_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
120 \r
121     store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
122     store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_LINK_CTL, OCF_SET_CONN_PTYPE)));\r
123     store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),SET_CONN_PTYPE_CP_SIZE);\r
124     store_le16((uint8_t*)bth_cmd_packet+SET_CONN_PTYPE_CP____handle,handle);\r
125     store_le16((uint8_t*)bth_cmd_packet+SET_CONN_PTYPE_CP____pkt_type,ptype);\r
126 \r
127 /*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
128 se overuje, az pri samotnem ukladani */\r
129     if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
130     else{ bth_com_buf_info.aktual=0;};\r
131   return(-1);\r
132 };\r
133 \r
134 \r
135 \r
136 int bth_cmd_disconnect(uint16_t handle, uint8_t reason)\r
137 {\r
138 /*------------------------ parts of packet-----------------------*/\r
139     uint8_t *typ_hci_paket;\r
140     hci_command_hdr *hci_headr;\r
141     disconnect_cp *bth_cmd_packet;\r
142 /*-- determine the size of memory needed for command in buff and determine if it fit there */\r
143 /*-------------------------------------------------------------------------------*/\r
144 /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
145 \r
146     if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
147     {return 1;};\r
148 /*setup adresses for packet parts + filling of inidividual fields*/\r
149     int hp_size=HCI_PKT_SIZE+HCI_COMMAND_HDR_SIZE+DISCONNECT_CP_SIZE;\r
150 \r
151     bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
152     typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
153     hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
154     bth_cmd_packet=(disconnect_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
155 \r
156     store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
157     store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_LINK_POLICY, OCF_DISCONNECT)));\r
158     store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),WRITE_PAGE_ACTIVITY_CP_SIZE);\r
159     store_le16((uint16_t*)((uint8_t*)bth_cmd_packet+DISCONNECT_CP____handle),handle);\r
160     store16(*((uint8_t*)bth_cmd_packet+DISCONNECT_CP____reason),reason);\r
161 \r
162 /*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
163 se overuje, az pri samotnem ukladani */\r
164     if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
165     else{ bth_com_buf_info.aktual=0;};\r
166  return -1;\r
167 };\r
168 \r
169 //--------------------------------------------------------------------------------------------\r
170 //--------------------------------------------------------------------------------------------\r
171 \r
172 \r
173 \r
174 /********************************************************************/\r
175 /***********************   OGF = 0x02    ****************************/\r
176 /*-------------------LINK POLICY COMMANDS--------------------------*/\r
177 /********************************************************************/\r
178 int bth_cmd_write_link_policy_settings(uint16_t handle, uint16_t policy) /*obcode=0x0D08; 0x02--0x000D*/\r
179 {\r
180 /*------------------------ parts of packet-----------------------*/\r
181     uint8_t *typ_hci_paket;\r
182     hci_command_hdr *hci_headr;\r
183     write_link_policy_cp *bth_cmd_packet;\r
184 /*-- determine the size of memory needed for command in buff and determine if it fit there */\r
185 /*-------------------------------------------------------------------------------*/\r
186 /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
187 \r
188     if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
189     {return 1;};\r
190 /*setup adresses for packet parts + filling of inidividual fields*/\r
191     int hp_size=HCI_PKT_SIZE+HCI_COMMAND_HDR_SIZE+WRITE_LINK_POLICY_CP_SIZE;\r
192 \r
193     bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
194     typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
195     hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
196     bth_cmd_packet=(write_link_policy_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
197 \r
198     store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
199     store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_LINK_POLICY, OCF_WRITE_LINK_POLICY)));\r
200     store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),WRITE_PAGE_ACTIVITY_CP_SIZE);\r
201     store_le16((uint16_t*)((uint8_t*)bth_cmd_packet+WRITE_LINK_POLICY_CP____handle),handle);\r
202     store_le16((uint16_t*)((uint8_t*)bth_cmd_packet+WRITE_LINK_POLICY_CP____policy),policy);\r
203 \r
204 /*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
205 se overuje, az pri samotnem ukladani */\r
206     if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
207     else{ bth_com_buf_info.aktual=0;};\r
208  return -1;\r
209 };\r
210 \r
211 \r
212 \r
213 \r
214 /********************************************************************/\r
215 /***********************   OGF = 0x03    ****************************/\r
216 /*--------------HOST CONTROLLER & BASEBAND COMMANDS-----------------*/\r
217 /********************************************************************/\r
218 int bth_cmd_reset(void)         /*opcode=0x0C03 OCF = 0x0003, OGF = 0x03*/\r
219 {\r
220 /*------------------------ parts of packet-----------------------*/\r
221     uint8_t *typ_hci_paket;\r
222     hci_command_hdr *hci_headr;\r
223 /*-- determine the size of memory needed for command in buff and determine if it fit there */\r
224 /*-------------------------------------------------------------------------------*/\r
225 /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
226 \r
227     if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
228     {return 1;};\r
229 /*setup adresses for packet parts + filling of inidividual fields*/\r
230     int hp_size=HCI_PKT_SIZE+HCI_COMMAND_HDR_SIZE;\r
231 \r
232     bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
233     typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
234     hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
235 \r
236     store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
237     store_le16(((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode),htobs(cmd_opcode_pack(OGF_HOST_CTL,OCF_RESET )));\r
238 \r
239 \r
240     store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),0);\r
241 \r
242 /*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
243 se overuje, az pri samotnem ukladani */\r
244     if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
245     else{ bth_com_buf_info.aktual=0;};\r
246  return -1;\r
247 };\r
248 \r
249 \r
250 \r
251 /********************************************************************/\r
252 /***********************   OGF = 0x04    ****************************/\r
253 /*-------------------INFORMATIONAL PARAMETERS-----------------------*/\r
254 /********************************************************************/\r
255 \r
256 \r
257 \r
258 int bth_accept_conn_req_cp(bdaddr_t *bdaddr)                 /*0x01 - 0x0009*/\r
259 {\r
260 /*------------------------ parts of packet-----------------------*/\r
261     uint8_t *typ_hci_paket; //FIXME: hjkhjkh\r
262     hci_command_hdr *hci_headr;\r
263     accept_conn_req_cp *bth_cmd_packet;\r
264 /*-- determine the size of memory needed for command in buff and determine if it fit there */\r
265 /*-------------------------------------------------------------------------------*/\r
266 /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
267 \r
268     if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
269     {return 1;};\r
270 /*setup adresses for packet parts + filling of inidividual fields*/\r
271     int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+ACCEPT_CONN_REQ_CP_SIZE);\r
272 \r
273     bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
274     typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
275     hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
276     bth_cmd_packet=(accept_conn_req_cp*)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
277 \r
278     store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
279     store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_LINK_CTL, OCF_ACCEPT_CONN_REQ)));\r
280     store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),ACCEPT_CONN_REQ_CP_SIZE);\r
281     memcpy((uint8_t*)bth_cmd_packet+ACCEPT_CONN_REQ_CP____bdaddr,bdaddr,sizeof(bdaddr_t));\r
282     store16(*((uint8_t*)bth_cmd_packet+ACCEPT_CONN_REQ_CP____role), 0x01); //ACL\r
283 \r
284 /*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
285 se overuje, az pri samotnem ukladani */\r
286     if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
287     else{ bth_com_buf_info.aktual=0;};\r
288  return 0;\r
289 };\r
290 \r
291 int bth_cmd_write_page_scan(uint16_t interval, uint16_t window)        /*obcode=1C0C OGF = 0x001C OCF=0x03*/\r
292 {\r
293 /*------------------------ parts of packet-----------------------*/\r
294     uint8_t *typ_hci_paket;\r
295     hci_command_hdr *hci_headr;\r
296     write_page_activity_cp *bth_cmd_packet;\r
297 /*-- determine the size of memory needed for command in buff and determine if it fit there */\r
298 /*-------------------------------------------------------------------------------*/\r
299 /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
300 \r
301     if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
302     {return 1;};\r
303 /*setup adresses for packet parts + filling of inidividual fields*/\r
304     int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+WRITE_PAGE_ACTIVITY_CP_SIZE);\r
305 \r
306     bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
307     typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
308     hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
309     bth_cmd_packet=(write_page_activity_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
310 \r
311     store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
312     store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_PAGE_ACTIVITY)));\r
313     store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),WRITE_PAGE_ACTIVITY_CP_SIZE);\r
314     store_le16((uint8_t*)bth_cmd_packet+WRITE_PAGE_ACTIVITY_CP____interval,interval);\r
315     store_le16((uint8_t*)bth_cmd_packet+WRITE_PAGE_ACTIVITY_CP____window,window);\r
316 \r
317 /*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
318 se overuje, az pri samotnem ukladani */\r
319     if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
320     else{ bth_com_buf_info.aktual=0;};\r
321  return -1;\r
322 };\r
323 \r
324 \r
325 \r
326 //--------------------------------------------------------------------------------------------\r
327 //--------------------------------------------------------------------------------------------\r
328 //--------------------------------------------------------------------------------------------\r
329 int bth_cmd_write_inquiry_scan_activity(uint16_t interval, uint16_t window) //0x001E\r
330 {\r
331 /*------------------------ parts of packet-----------------------*/\r
332     uint8_t *typ_hci_paket;\r
333     hci_command_hdr *hci_headr;\r
334     write_inq_activity_cp *bth_cmd_packet;\r
335 /*-- determine the size of memory needed for command in buff and determine if it fit there */\r
336 /*-------------------------------------------------------------------------------*/\r
337 /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
338 \r
339     if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
340     {return 1;};\r
341 /*setup adresses for packet parts + filling of inidividual fields*/\r
342     int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+WRITE_PAGE_ACTIVITY_CP_SIZE);\r
343     bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
344     typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
345     hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
346     bth_cmd_packet=(write_inq_activity_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
347 \r
348     store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
349     store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_INQ_ACTIVITY)));\r
350     store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),WRITE_INQ_ACTIVITY_CP_SIZE);\r
351     store_le16((uint8_t*)bth_cmd_packet+WRITE_INQ_ACTIVITY_CP____interval,interval);\r
352     store_le16((uint8_t*)bth_cmd_packet+WRITE_INQ_ACTIVITY_CP____window,window);\r
353 \r
354 /*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
355 se overuje, az pri samotnem ukladani */\r
356     if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
357     else{ bth_com_buf_info.aktual=0;};\r
358     return(-1);\r
359 };\r
360 \r
361 int bth_cmd_read_bd_addr(void) /*opcode=0x0910 OCF = 0x0009, OGF = 0x04*/\r
362 {\r
363 /*------------------------ parts of packet-----------------------*/\r
364     uint8_t *typ_hci_paket;\r
365     hci_command_hdr *hci_headr;\r
366 /*-- determine the size of memory needed for command in buff and determine if it fit there */\r
367 /*-------------------------------------------------------------------------------*/\r
368 /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
369 \r
370     if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
371     {return 1;};\r
372 /*setup adresses for packet parts + filling of inidividual fields*/\r
373     int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE);\r
374     bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
375     typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
376     hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
377 \r
378     store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
379     store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_INFO_PARAM, OCF_READ_BD_ADDR)));\r
380     store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),0);\r
381 \r
382 /*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
383 se overuje, az pri samotnem ukladani */\r
384     if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
385     else{ bth_com_buf_info.aktual=0;};\r
386   return -1;\r
387 };\r
388 \r
389 int bth_cmd_write_scan_enable(uint8_t set_ing_scan) //0x001A\r
390 {\r
391 /*------------------------ parts of packet-----------------------*/\r
392     uint8_t *typ_hci_paket;\r
393     hci_command_hdr *hci_headr;\r
394     uint8_t *bth_cmd_packet;\r
395 \r
396 /*-- determine the size of memory needed for command in buff and determine if it fit there */\r
397 /*-------------------------------------------------------------------------------*/\r
398 /*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
399 \r
400     if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
401     {return 1;};\r
402 /*setup adresses for packet parts + filling of inidividual fields*/\r
403     int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+WRITE_SCAN_ENABLE_SIZE);\r
404     bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
405     typ_hci_paket=(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
406     hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
407     bth_cmd_packet=(uint8_t *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
408 \r
409 \r
410     store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
411     store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE)));\r
412     store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),WRITE_SCAN_ENABLE_SIZE);\r
413     store16(*bth_cmd_packet,set_ing_scan);\r
414 /*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
415 se overuje, az pri samotnem ukladani */\r
416     if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
417     else{ bth_com_buf_info.aktual=0;};\r
418   return -1;\r
419 };\r
420 \r
421 //FIXME: All the czech comments are the same as in the first function.\r
422 \r