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