]> rtime.felk.cvut.cz Git - mirosot.git/blob - bluetooth/l2cap.c
Comments translated to english
[mirosot.git] / bluetooth / l2cap.c
1 /*******************************************************************\r
2   bluetooth library\r
3 \r
4   l2cap.c - fce for operation L2CAP protocol (build L2CAP packet)\r
5             and for saving data to data queue\r
6 \r
7   Copyright (C) 2006 by Petr Kovacik petr_kovacik@gmail.com\r
8 \r
9  *******************************************************************/\r
10 \r
11 \r
12 \r
13 #include <string.h>\r
14 #include <stdlib.h>\r
15 #ifdef BTH_LX\r
16 #include <types.h>\r
17 #include <cpu_def.h>\r
18 #include <h8s2638h.h>\r
19 #include <periph/sci_rs232.h>\r
20 #include <system_def.h>\r
21 \r
22 #else\r
23 #include "types.h"\r
24 #endif\r
25 \r
26 #include "hci.h"\r
27 #include "l2cap.h"\r
28 \r
29 #include "inline_fce.h"\r
30 #include "bth_inface.h"\r
31 #include "bth_fce_out.h"\r
32 \r
33 \r
34 /**\r
35  * pointers to functions, which are executed depending on a parameter\r
36  */\r
37 typedef int (*l2cap_code_fce_def)(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);\r
38 l2cap_code_fce_def l2cap_code_fce[]={\r
39   l2cap_none,l2cap_cod_command_rej,l2cap_cod_conn_req, l2cap_cod_conn_rsp, l2cap_cod_conf_req, l2cap_cod_conf_rsp,\r
40   l2cap_cod_disconn_req, l2cap_cod_disconn_rsp,   l2cap_cod_echo_req, l2cap_cod_echo_rsp, l2cap_cod_info_req,\r
41   l2cap_cod_info_rsp};\r
42 #define L2CAP_SUM_FC (sizeof(l2cap_code_fce)/sizeof(l2cap_code_fce[0]))\r
43 \r
44 \r
45 /*----------------------- function depending on code -----------------------------------*/\r
46 \r
47 /**\r
48 * Search the cannels of the connected device dev_num and search the channel dcid\r
49 */\r
50 inline int l2cap_find_dcid(int dcid, int dev_num )\r
51 {\r
52   int i;\r
53   for(i=1;i<L2CAP_NUM_OF_CANAL;i++)\r
54   {\r
55     if(bth_connected[dev_num]->dcid[i]==dcid)\r
56     {\r
57       return(-3);\r
58     };\r
59   };\r
60   return (0);\r
61 };\r
62 \r
63 \r
64 /*------------------------------ auxiliary functions --------------------------------*/\r
65 \r
66 int l2cap_add_to_send_buffer(uint8_t *bth_p)\r
67 {\r
68   if(bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
69   {return 1;};\r
70   bth_pole_adrr_comm_packet[bth_com_buf_info.aktual]=bth_p;\r
71 \r
72   /*set the position in command array for the next command. If it is possible to write there (if the pointer = NULL) is checked by the writer. .\r
73 \r
74   nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
75   se overuje, az pri samotnem ukladani */\r
76   if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
77   else{ bth_com_buf_info.aktual=0;};\r
78   return 0;\r
79 \r
80 };\r
81 /**\r
82 * Nonexisting function - should never happend \r
83 */\r
84 int l2cap_none(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan)\r
85 {\r
86   return (-3);\r
87 };\r
88 \r
89 \r
90 \r
91 /**\r
92  * decoding of the signaling packet and calling of the above functions\r
93  */\r
94 int l2cap_signaling(uint8_t *bth_p, uint16_t size,int dev_num)\r
95 {\r
96   l2cap_cmd_hdr bth_q;\r
97 \r
98   store16(bth_q.code,*((uint8_t*)bth_p+L2CAP_CMD_HDR____code));\r
99   store16(bth_connected[dev_num]->ident,*((uint8_t*)bth_p+L2CAP_CMD_HDR____ident));\r
100   __bthtomc16((uint8_t*)&(bth_q.len),((uint8_t*)bth_p+L2CAP_CMD_HDR____len));\r
101   \r
102   if(bth_q.code<L2CAP_SUM_FC)\r
103   { /*jump to the handling functions*/\r
104     l2cap_code_fce[bth_q.code]((uint8_t*)bth_p+L2CAP_CMD_HDR_SIZE, bth_q.len,dev_num, 0);\r
105     return 0;\r
106   }\r
107   else {return -1;};\r
108 };\r
109 \r
110 /*----------------------- functions depending on code -----------------------------------*/\r
111 \r
112 /**\r
113  * Command reject\r
114  */\r
115 int l2cap_cod_command_rej(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan)      //0x01\r
116 {\r
117   \r
118   return (-3);\r
119 };\r
120 \r
121 /**\r
122  * Connection request\r
123  */\r
124 int l2cap_cod_conn_req(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan)     //0x02\r
125 {\r
126   l2cap_conn_req bth_q;\r
127   if(bth_p==NULL)\r
128   {\r
129     /*the packet is built here - ie. this is the device that wants to create a new channel*/\r
130     /*zde se paket sestavuje - tj. jedna se o zarizeni, ktere chce vytvorit novy kanal*/\r
131 \r
132   }\r
133   else \r
134   {\r
135     /*local device receives packet 0x02*/\r
136     __bthtomc16((uint8_t*)&(bth_q.psm),((uint8_t*)bth_p+L2CAP_CONN_REQ____psm));\r
137     __bthtomc16((uint8_t*)&(bth_q.scid),((uint8_t*)bth_p+L2CAP_CONN_REQ____scid));\r
138     /*SCID is in this case DCID, because sending side choosed thich channel as SCID. This is viewed from the point of view of \r
139       receiving device, so this is DCID. */\r
140     /*SCID je v tomto pripade DCID, protoze vysilajici strana si tento kanal zvolila jako SCID. Uloha je brana z\r
141     pohledu daneho zarizeni (ktere paket prijalo) tudiz se jedna o DCID*/\r
142 \r
143     pos_chan=bth_add_chanal_dcid(dev_num, bth_q.scid); //add DCID of the remote device\r
144 \r
145     /*build the response packet*/\r
146     l2cap_cod_conn_rsp(NULL,0,dev_num,pos_chan);\r
147     bth_local_info.busy=0;\r
148   };\r
149   return (-1);\r
150 };\r
151 \r
152 /**\r
153   Connection response\r
154 */\r
155 int l2cap_cod_conn_rsp(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan)     //0x03\r
156 {\r
157   l2cap_conn_req bth_q;\r
158   uint8_t *bth_r;\r
159   uint16_t result=L2CAP_CR_SUCCESS;\r
160   uint16_t status=0;\r
161   uint8_t *typ_hci_paket;\r
162   hci_acl_hdr *hci_headr;\r
163   l2cap_hdr *l2cap_headr;\r
164   l2cap_cmd_hdr *l2cap_cmd_headr;\r
165   l2cap_conn_rsp *l2cap_conn_response;\r
166   if(bth_p==NULL)\r
167   {\r
168     /*the device received packet 0x03 from the remote device*/\r
169     int hp_size=(HCI_PKT_SIZE+HCI_ACL_HDR_SIZE+L2CAP_HDR_SIZE+L2CAP_CMD_HDR_SIZE+L2CAP_CONN_RSP_SIZE);\r
170     bth_r=malloc(hp_size);\r
171 \r
172     typ_hci_paket=(uint8_t*)bth_r;\r
173     hci_headr=(hci_acl_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer to head\r
174     l2cap_headr=(l2cap_hdr *)(((uint8_t*)hci_headr)+HCI_ACL_HDR_SIZE);   //pointer to parametrs\r
175     l2cap_cmd_headr=(l2cap_cmd_hdr *)(((uint8_t*)l2cap_headr)+L2CAP_HDR_SIZE);\r
176     l2cap_conn_response=(l2cap_conn_rsp *)(((uint8_t*)l2cap_cmd_headr)+L2CAP_CMD_HDR_SIZE);\r
177   /*------*/\r
178     store16(*typ_hci_paket, HCI_ACLDATA_PKT);\r
179     store_le16((uint8_t*)hci_headr+HCI_ACL_HDR____handle,(htobs(0x2000)|bth_connected[dev_num]->handle));\r
180     store_le16((uint8_t*)hci_headr+HCI_ACL_HDR____dlen,htobs(L2CAP_CMD_HDR_SIZE+L2CAP_CONN_RSP_SIZE+L2CAP_CMD_HDR_SIZE));\r
181 \r
182     store_le16((uint16_t*)((uint8_t*)l2cap_headr+L2CAP_HDR____len), htobs(L2CAP_CONN_RSP_SIZE+L2CAP_CMD_HDR_SIZE));\r
183     store_le16((uint16_t*)((uint8_t*)l2cap_headr+L2CAP_HDR____cid),htobs(0x0001));\r
184     store16(*((uint8_t*)l2cap_cmd_headr+L2CAP_CMD_HDR____code), L2CAP_CONN_RSP);\r
185 \r
186 \r
187     if(pos_chan>-1) //the channel of that device don't exists. We will create it\r
188     {\r
189       (bth_connected[dev_num])->scid[pos_chan]=(0x0040+pos_chan+1);\r
190       /*dcin - remote device, which     */\r
191       store_le16((uint16_t*)((uint8_t*)l2cap_conn_response+L2CAP_CONN_RSP____dcid),(0x0040+pos_chan+1));\r
192     }\r
193     else{\r
194       result=htobs(L2CAP_CR_PEND); status=htobs(L2CAP_CS_NO_INFO);\r
195       store_le16((uint16_t*)((uint8_t*)l2cap_conn_response+L2CAP_CONN_RSP____dcid),0);\r
196     };\r
197 \r
198     store16(*((uint8_t*)l2cap_cmd_headr+L2CAP_CMD_HDR____ident),((bths_connect_bluet*)bth_connected[dev_num])->ident);\r
199     store_le16((uint16_t*)((uint8_t*)l2cap_cmd_headr+L2CAP_CMD_HDR____len),L2CAP_CONN_RSP_SIZE);\r
200     store_le16((uint16_t*)((uint8_t*)l2cap_conn_response+L2CAP_CONN_RSP____scid),((bths_connect_bluet*)bth_connected[dev_num])->dcid[pos_chan]);\r
201 \r
202     if(l2cap_find_dcid(bth_q.scid, dev_num)>=0) //search all the DCID (SCID of remote device, if it is not used)\r
203     {\r
204       store_le16((uint16_t*)((uint8_t*)l2cap_conn_response+L2CAP_CONN_RSP____result),htobs(L2CAP_CR_SUCCESS));\r
205       store_le16((uint16_t*)((uint8_t*)l2cap_conn_response+L2CAP_CONN_RSP____status),htobs(L2CAP_CS_NO_INFO));\r
206     }\r
207     else//the device uses the channel, se reply with an apropriate error code\r
208     {\r
209       store_le16((uint16_t*)((uint8_t*)l2cap_conn_response+L2CAP_CONN_RSP____result),result);\r
210       store_le16((uint16_t*)((uint8_t*)l2cap_conn_response+L2CAP_CONN_RSP____status),status);\r
211     };\r
212     /*prepare data to sending buffer*/\r
213     return(l2cap_add_to_send_buffer(bth_r));\r
214   }\r
215   else\r
216   {\r
217     /*local device sends to the remote device paket 0x03 - apply for a channel*/\r
218   };\r
219   return (-1);\r
220 };\r
221 \r
222 /**\r
223   Configure request\r
224  */\r
225 int l2cap_cod_conf_req(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan)     //0x04\r
226 {\r
227   l2cap_conf_req bth_q;\r
228   uint8_t *bth_r;\r
229   uint8_t *typ_hci_paket;\r
230   hci_acl_hdr *hci_headr;\r
231   l2cap_hdr *l2cap_headr;\r
232   l2cap_cmd_hdr *l2cap_cmd_headr;\r
233   l2cap_conf_req *l2cap_conf_request;\r
234 \r
235   if(bth_p==NULL)\r
236   {\r
237   }\r
238   else\r
239   {\r
240     __bthtomc16((uint8_t*)&(bth_q.dcid),((uint8_t*)bth_p+L2CAP_CONF_REQ____dcid));\r
241     __bthtomc16((uint8_t*)&(bth_q.flags),((uint8_t*)bth_p+L2CAP_CONF_REQ____flags));\r
242     //yet some data .... - in our case, nothing is processed\r
243     /*------*/\r
244     pos_chan=bth_find_chanal_scid(dev_num, bth_q.dcid);\r
245     l2cap_cod_conf_rsp(NULL, 0, dev_num, pos_chan);     //0x05\r
246     \r
247   /***************build the packet, by which we send response code = 0x04 to the master*************/\r
248   /*setting of addresses for the parts of the packet + filling of inidividual fields*/\r
249     int hp_size=(HCI_PKT_SIZE+HCI_ACL_HDR_SIZE+L2CAP_HDR_SIZE+L2CAP_CMD_HDR_SIZE+L2CAP_CONF_REQ_SIZE);\r
250     bth_r=malloc(hp_size);\r
251 \r
252     typ_hci_paket=(uint8_t*)bth_r;\r
253     hci_headr=(hci_acl_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer to head\r
254     l2cap_headr=(l2cap_hdr *)(((uint8_t*)hci_headr)+HCI_ACL_HDR_SIZE);   //pointer to parametrs\r
255     l2cap_cmd_headr=(l2cap_cmd_hdr *)(((uint8_t*)l2cap_headr)+L2CAP_HDR_SIZE);\r
256     l2cap_conf_request=(l2cap_conf_req *)(((uint8_t*)l2cap_cmd_headr)+L2CAP_CMD_HDR_SIZE);\r
257     /*------*/\r
258 \r
259     store16(*typ_hci_paket, HCI_ACLDATA_PKT);\r
260     store_le16((uint8_t*)hci_headr+HCI_ACL_HDR____handle,(htobs(0x2000)|(bth_connected[dev_num])->handle));\r
261     store_le16((uint8_t*)hci_headr+HCI_ACL_HDR____dlen,htobs(L2CAP_CMD_HDR_SIZE+L2CAP_CONF_REQ_SIZE+L2CAP_CMD_HDR_SIZE));\r
262 \r
263     store_le16((uint16_t*)((uint8_t*)l2cap_headr+L2CAP_HDR____len), htobs(L2CAP_CONF_REQ_SIZE+L2CAP_CMD_HDR_SIZE));\r
264     store_le16((uint16_t*)((uint8_t*)l2cap_headr+L2CAP_HDR____cid),htobs(0x0001));\r
265 \r
266     store16(*((uint8_t*)l2cap_cmd_headr+L2CAP_CMD_HDR____code), L2CAP_CONF_REQ);\r
267     store16(*((uint8_t*)l2cap_cmd_headr+L2CAP_CMD_HDR____ident),(bth_connected[dev_num])->ident);\r
268     store_le16((uint16_t*)((uint8_t*)l2cap_cmd_headr+L2CAP_CMD_HDR____len),htobs(L2CAP_CONF_REQ_SIZE));\r
269 \r
270     store_le16((uint16_t*)((uint8_t*)l2cap_conf_request+L2CAP_CONF_REQ____dcid),(bth_connected[dev_num])->dcid[pos_chan]);\r
271     store_le16((uint16_t*)((uint8_t*)l2cap_conf_request+L2CAP_CONF_REQ____flags),0);\r
272   //the last item are data - they are not sent in this packet\r
273 \r
274   /******************* put it to send buffer **************************/\r
275     l2cap_add_to_send_buffer(bth_r);\r
276     return 0;\r
277   };\r
278   return (-1);\r
279 };\r
280 \r
281 \r
282 /**\r
283   Configure response\r
284  */\r
285 int l2cap_cod_conf_rsp(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan)     //0x05\r
286 {\r
287   l2cap_conf_rsp bth_q;\r
288   uint8_t *bth_r;\r
289   uint8_t *typ_hci_paket;\r
290   hci_acl_hdr *hci_headr;\r
291   l2cap_hdr *l2cap_headr;\r
292   l2cap_cmd_hdr *l2cap_cmd_headr;\r
293   l2cap_conf_rsp *l2cap_conf_response;\r
294 \r
295   if(bth_p==NULL)\r
296   {\r
297   /*build the response packet*/\r
298   /*setup the adresses for parts of the packet + filling of individual fields*/\r
299     int hp_size=(HCI_PKT_SIZE+HCI_ACL_HDR_SIZE+L2CAP_HDR_SIZE+L2CAP_CMD_HDR_SIZE+L2CAP_CONF_RSP_SIZE);\r
300     bth_r=malloc(hp_size);\r
301 \r
302     typ_hci_paket=(uint8_t*)bth_r;\r
303     hci_headr=(hci_acl_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);   //pointer on head\r
304     l2cap_headr=(l2cap_hdr *)(((uint8_t*)hci_headr)+HCI_ACL_HDR_SIZE);   //pointer on parametrs\r
305     l2cap_cmd_headr=(l2cap_cmd_hdr *)(((uint8_t*)l2cap_headr)+L2CAP_HDR_SIZE);\r
306     l2cap_conf_response=(l2cap_conf_rsp *)(((uint8_t*)l2cap_cmd_headr)+L2CAP_CMD_HDR_SIZE);\r
307   /*------*/\r
308     store16(*typ_hci_paket, HCI_ACLDATA_PKT);\r
309     store_le16((uint8_t*)hci_headr+HCI_ACL_HDR____handle,(htobs(0x2000)|(bth_connected[dev_num])->handle));\r
310     store_le16((uint8_t*)hci_headr+HCI_ACL_HDR____dlen,htobs(L2CAP_CMD_HDR_SIZE+L2CAP_CONF_RSP_SIZE+L2CAP_CMD_HDR_SIZE));\r
311 \r
312     store_le16((uint16_t*)((uint8_t*)l2cap_headr+L2CAP_HDR____len), htobs(L2CAP_CONF_RSP_SIZE+L2CAP_CMD_HDR_SIZE));\r
313     store_le16((uint16_t*)((uint8_t*)l2cap_headr+L2CAP_HDR____cid),htobs(0x0001));\r
314 \r
315     store16(*((uint8_t*)l2cap_cmd_headr+L2CAP_CMD_HDR____code), L2CAP_CONF_RSP);\r
316     (bth_connected[dev_num])->ident++;\r
317     store16(*((uint8_t*)l2cap_cmd_headr+L2CAP_CMD_HDR____ident),(bth_connected[dev_num])->ident);\r
318     store_le16((uint16_t*)((uint8_t*)l2cap_cmd_headr+L2CAP_CMD_HDR____len),htobs(L2CAP_CONF_RSP_SIZE));\r
319 \r
320     store_le16((uint16_t*)((uint8_t*)l2cap_conf_response+L2CAP_CONF_RSP____scid),(bth_connected[dev_num])->dcid[pos_chan]);\r
321     store_le16((uint16_t*)((uint8_t*)l2cap_conf_response+L2CAP_CONF_RSP____flags),0);\r
322     store_le16((uint16_t*)((uint8_t*)l2cap_conf_response+L2CAP_CONF_RSP____result),0);\r
323   //posledni polozka jsou data - nebubu posilat v tomto paketu //same as in previous func\r
324 \r
325 \r
326   /******************* umisteni do vysilaciho bufferu **************************/\r
327     return(l2cap_add_to_send_buffer(bth_r));\r
328   }\r
329   else\r
330   {\r
331     __bthtomc16((uint8_t*)&(bth_q.scid),((uint8_t*)bth_p+L2CAP_CONF_RSP____scid));\r
332     __bthtomc16((uint8_t*)&(bth_q.flags),((uint8_t*)bth_p+L2CAP_CONF_RSP____flags));\r
333     __bthtomc16((uint8_t*)&(bth_q.result),((uint8_t*)bth_p+L2CAP_CONF_RSP____result));\r
334    return (bth_q.result);;\r
335   };\r
336 };\r
337 \r
338 /**\r
339   Disconnection request \r
340  */\r
341 int l2cap_cod_disconn_req(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan)  //0x06\r
342 {\r
343   return (-3);\r
344 };\r
345 \r
346 /**\r
347   Disconnection response\r
348  */\r
349 int l2cap_cod_disconn_rsp(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan)  //0x07\r
350 {\r
351   return (-3);\r
352 };\r
353 \r
354 \r
355 /**\r
356   Configure response\r
357  */\r
358 int l2cap_cod_echo_req(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan)     //0x08\r
359 {\r
360   return (-3);\r
361 };\r
362 \r
363 \r
364 /**\r
365   Echo request\r
366  */\r
367 int l2cap_cod_echo_rsp(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan)     //0x09\r
368 {\r
369   return (-3);\r
370 };\r
371 \r
372 /**\r
373   Echo response\r
374  */\r
375 int l2cap_cod_info_req(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan)     //0x0a\r
376 {\r
377   return (-3);\r
378 };\r
379 \r
380 /**\r
381   Information request\r
382  */\r
383 int l2cap_cod_info_rsp(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan)     //0x0b\r
384 {\r
385   return (-3);\r
386 };\r
387 \r
388 /*----------------------- send data ----------------------------*/\r
389 \r
390 /**\r
391  * zabali data z dat. zasobniku do peketu a da k odeslani\r
392 */\r
393 int l2cap_send_data(int inx_handle, int inx_chanal)\r
394 \r
395 {\r
396   uint8_t *typ_hci_paket;\r
397   hci_acl_hdr *hci_headr;\r
398   l2cap_hdr *l2cap_headr;\r
399   uint8_t *data;\r
400   uint8_t *bth_r;\r
401   int zn;\r
402   int hp_size,size=0;\r
403   uint16_t handle, chanal;\r
404 \r
405   \r
406   if(bth_connected[inx_handle]==NULL) return (-1);\r
407   if((bth_connected[inx_handle])->dcid[inx_chanal]==0) return (-1);\r
408 \r
409   /*reading from sending buffer, try 1 character*/\r
410   zn=bth_inface_t_isr(0);\r
411   if(zn>=0)\r
412   {\r
413     handle = ((bths_connect_bluet*)bth_connected[inx_handle])->handle;\r
414     handle=(handle | htobs(0x2000));\r
415     chanal = (bth_connected[inx_handle])->dcid[inx_chanal];\r
416     \r
417     /*make space for the packer + assign adresses for individual parts of L2CAP packet*/\r
418     hp_size=(HCI_PKT_SIZE+HCI_ACL_HDR_SIZE+L2CAP_HDR_SIZE+BTH_INFACE_BUF_LEN);\r
419     bth_r=malloc(hp_size);\r
420     \r
421     typ_hci_paket=bth_r; //pozice v buff, ktera je prirazena paketu\r
422     hci_headr=(hci_acl_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
423     l2cap_headr=(l2cap_hdr *)(((uint8_t*)hci_headr)+HCI_ACL_HDR_SIZE);   //pointer on parametrs\r
424     data=((uint8_t*)l2cap_headr+L2CAP_HDR_SIZE); //pointer na data\r
425 \r
426 /*-----------------------------DATA FOR SENDING TO PC --------------------------*/\r
427     *((uint8_t*)data+size)=(uint8_t)zn;\r
428     size++;\r
429     /*cyclic reading of the folowing characters and building of the packet*/\r
430     while ((zn=bth_inface_t_isr(0))>=0)\r
431     {\r
432       *((uint8_t*)data+size)=(uint8_t)zn;\r
433       size++;\r
434     };\r
435   }\r
436   else {return (0);}; //data are not in the queue\r
437   \r
438 /*build the rest of the response packet ie. fill the fields*/\r
439   store16(*typ_hci_paket, HCI_ACLDATA_PKT);\r
440   store_le16((uint8_t*)hci_headr+HCI_ACL_HDR____handle,handle);\r
441   store_le16((uint8_t*)hci_headr+HCI_ACL_HDR____dlen,(htobs(L2CAP_CMD_HDR_SIZE)+size));\r
442 \r
443   store_le16((uint16_t*)((uint8_t*)l2cap_headr+L2CAP_HDR____len),size);\r
444   store_le16((uint16_t*)((uint8_t*)l2cap_headr+L2CAP_HDR____cid),chanal);\r
445   \r
446 //  VypisHexa((void*)typ_hci_paket,16);\r
447 //  bth_local_info.busy=0;\r
448   return(l2cap_add_to_send_buffer(bth_r));\r
449 };\r