]> rtime.felk.cvut.cz Git - mirosot.git/blobdiff - bth_tests/bluetooth/bth_command.c
Added bth_test application. Not finished.
[mirosot.git] / bth_tests / bluetooth / bth_command.c
diff --git a/bth_tests/bluetooth/bth_command.c b/bth_tests/bluetooth/bth_command.c
new file mode 100644 (file)
index 0000000..f275b10
--- /dev/null
@@ -0,0 +1,419 @@
+/*******************************************************************\r
+  bluetooth library\r
+\r
+  bth_command.c - command functions (bth specification) - build command\r
+                  packet\r
+\r
+  Copyright (C) 2006 by Petr Kovacik petr_kovacik@gmail.com\r
+\r
+ *******************************************************************/\r
+\r
+\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <types.h>\r
+#ifdef BTH_LX\r
+#include <cpu_def.h>\r
+#include <h8s2638h.h>\r
+#include <periph/sci_rs232.h>\r
+#include <system_def.h>\r
+#endif\r
+\r
+#include "hci.h"\r
+#include "hci_event.h"\r
+#include "hci_command.h"\r
+#include "inline_fce.h"\r
+\r
+\r
+bths_check_command *bth_find_end(bths_check_command *dyn_chan)\r
+{\r
+   bths_check_command *temp;\r
+   if(dyn_chan!=NULL)\r
+    {\r
+      temp=dyn_chan;\r
+      while (temp->next!=NULL)\r
+      {\r
+        temp=temp->next;             /*put the command to the queue*/\r
+      };\r
+      return temp;\r
+    }\r
+    else\r
+    {\r
+    return NULL;\r
+    };\r
+};\r
+\r
+\r
+/********************************************************************/\r
+/***********************   OGF = 0x01    ****************************/\r
+/*-------------------LINK CONTROL COMMANDS--------------------------*/\r
+/********************************************************************/\r
+\r
+int bth_cmd_inqury(uint8_t length, uint8_t rsp, uint8_t *lap)\r
+{\r
+/*------------------------ parts of packet-----------------------*/\r
+    uint8_t *typ_hci_paket;\r
+    hci_command_hdr *hci_headr;\r
+    inquiry_cp *bth_cmd_packet;\r
+    uint16_t i; //used in loops\r
+/*-------------------------------------------------------------------------------*/\r
+/*-- determine the size of memory needed for command in buff and determine if it fit there */\r
+\r
+\r
+    if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
+    {return 1;};\r
+/*setup adresses for packet parts + filling of inidividual fields*/\r
+    int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+INQUIRY_CP_SIZE);\r
+\r
+    bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
+    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
+    hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer to head\r
+    bth_cmd_packet=(inquiry_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer to parametrs\r
+\r
+    store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
+    store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY)));\r
+    store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),INQUIRY_CP_SIZE);\r
+\r
+    /*pokud neni uvedeno lap zvoli se univerzlni*/\r
+    /*if lap is not specified, the universal one is chosen*/\r
+      store_le16((uint8_t*)bth_cmd_packet+INQUIRY_CP____length,length);\r
+      store_le16((uint8_t*)bth_cmd_packet+INQUIRY_CP____num_rsp,rsp);\r
+\r
+    if(lap==NULL)\r
+    {\r
+      uint8_t lap_univ[]={0x33,0x8b,0x9e};\r
+      memcpy(((uint8_t*)bth_cmd_packet+INQUIRY_CP____lap),&lap_univ,3);\r
+    }\r
+    else{\r
+      for(i=0; i<3; i++) {store_le16((uint8_t*)bth_cmd_packet+INQUIRY_CP____lap+i,*(lap+2-i));};\r
+    };\r
+\r
+/*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
+/*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
+se overuje, az pri samotnem ukladani */\r
+    if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
+    else{ bth_com_buf_info.aktual=0;};\r
+ return -1;\r
+};\r
+\r
+/*--- 0x01 - 0x000F --- Change_Connection_Packet_Type ---*/\r
+int change_connection_packet_type(uint16_t handle, uint16_t ptype)\r
+{\r
+    uint8_t *typ_hci_paket;\r
+    hci_command_hdr *hci_headr;\r
+    set_conn_ptype_cp *bth_cmd_packet;\r
+/*-- determine the size of memory needed for command in buff and determine if it fit there */\r
+/*-------------------------------------------------------------------------------*/\r
+/*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
+\r
+    if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
+    {return 1;};\r
+/*setup adresses for packet parts + filling of inidividual fields*/\r
+    int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+SET_CONN_PTYPE_CP_SIZE);\r
+    bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
+    typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
+    hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
+    bth_cmd_packet=(set_conn_ptype_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
+\r
+    store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
+    store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_LINK_CTL, OCF_SET_CONN_PTYPE)));\r
+    store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),SET_CONN_PTYPE_CP_SIZE);\r
+    store_le16((uint8_t*)bth_cmd_packet+SET_CONN_PTYPE_CP____handle,handle);\r
+    store_le16((uint8_t*)bth_cmd_packet+SET_CONN_PTYPE_CP____pkt_type,ptype);\r
+\r
+/*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
+se overuje, az pri samotnem ukladani */\r
+    if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
+    else{ bth_com_buf_info.aktual=0;};\r
+  return(-1);\r
+};\r
+\r
+\r
+\r
+int bth_cmd_disconnect(uint16_t handle, uint8_t reason)\r
+{\r
+/*------------------------ parts of packet-----------------------*/\r
+    uint8_t *typ_hci_paket;\r
+    hci_command_hdr *hci_headr;\r
+    disconnect_cp *bth_cmd_packet;\r
+/*-- determine the size of memory needed for command in buff and determine if it fit there */\r
+/*-------------------------------------------------------------------------------*/\r
+/*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
+\r
+    if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
+    {return 1;};\r
+/*setup adresses for packet parts + filling of inidividual fields*/\r
+    int hp_size=HCI_PKT_SIZE+HCI_COMMAND_HDR_SIZE+DISCONNECT_CP_SIZE;\r
+\r
+    bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
+    typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
+    hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
+    bth_cmd_packet=(disconnect_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
+\r
+    store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
+    store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_LINK_POLICY, OCF_DISCONNECT)));\r
+    store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),WRITE_PAGE_ACTIVITY_CP_SIZE);\r
+    store_le16((uint16_t*)((uint8_t*)bth_cmd_packet+DISCONNECT_CP____handle),handle);\r
+    store16(*((uint8_t*)bth_cmd_packet+DISCONNECT_CP____reason),reason);\r
+\r
+/*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
+se overuje, az pri samotnem ukladani */\r
+    if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
+    else{ bth_com_buf_info.aktual=0;};\r
+ return -1;\r
+};\r
+\r
+//--------------------------------------------------------------------------------------------\r
+//--------------------------------------------------------------------------------------------\r
+\r
+\r
+\r
+/********************************************************************/\r
+/***********************   OGF = 0x02    ****************************/\r
+/*-------------------LINK POLICY COMMANDS--------------------------*/\r
+/********************************************************************/\r
+int bth_cmd_write_link_policy_settings(uint16_t handle, uint16_t policy) /*obcode=0x0D08; 0x02--0x000D*/\r
+{\r
+/*------------------------ parts of packet-----------------------*/\r
+    uint8_t *typ_hci_paket;\r
+    hci_command_hdr *hci_headr;\r
+    write_link_policy_cp *bth_cmd_packet;\r
+/*-- determine the size of memory needed for command in buff and determine if it fit there */\r
+/*-------------------------------------------------------------------------------*/\r
+/*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
+\r
+    if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
+    {return 1;};\r
+/*setup adresses for packet parts + filling of inidividual fields*/\r
+    int hp_size=HCI_PKT_SIZE+HCI_COMMAND_HDR_SIZE+WRITE_LINK_POLICY_CP_SIZE;\r
+\r
+    bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
+    typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
+    hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
+    bth_cmd_packet=(write_link_policy_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
+\r
+    store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
+    store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_LINK_POLICY, OCF_WRITE_LINK_POLICY)));\r
+    store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),WRITE_PAGE_ACTIVITY_CP_SIZE);\r
+    store_le16((uint16_t*)((uint8_t*)bth_cmd_packet+WRITE_LINK_POLICY_CP____handle),handle);\r
+    store_le16((uint16_t*)((uint8_t*)bth_cmd_packet+WRITE_LINK_POLICY_CP____policy),policy);\r
+\r
+/*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
+se overuje, az pri samotnem ukladani */\r
+    if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
+    else{ bth_com_buf_info.aktual=0;};\r
+ return -1;\r
+};\r
+\r
+\r
+\r
+\r
+/********************************************************************/\r
+/***********************   OGF = 0x03    ****************************/\r
+/*--------------HOST CONTROLLER & BASEBAND COMMANDS-----------------*/\r
+/********************************************************************/\r
+int bth_cmd_reset(void)                /*opcode=0x0C03 OCF = 0x0003, OGF = 0x03*/\r
+{\r
+/*------------------------ parts of packet-----------------------*/\r
+    uint8_t *typ_hci_paket;\r
+    hci_command_hdr *hci_headr;\r
+/*-- determine the size of memory needed for command in buff and determine if it fit there */\r
+/*-------------------------------------------------------------------------------*/\r
+/*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
+\r
+    if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
+    {return 1;};\r
+/*setup adresses for packet parts + filling of inidividual fields*/\r
+    int hp_size=HCI_PKT_SIZE+HCI_COMMAND_HDR_SIZE;\r
+\r
+    bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
+    typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
+    hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
+\r
+    store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
+    store_le16(((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode),htobs(cmd_opcode_pack(OGF_HOST_CTL,OCF_RESET )));\r
+\r
+\r
+    store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),0);\r
+\r
+/*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
+se overuje, az pri samotnem ukladani */\r
+    if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
+    else{ bth_com_buf_info.aktual=0;};\r
+ return -1;\r
+};\r
+\r
+\r
+\r
+/********************************************************************/\r
+/***********************   OGF = 0x04    ****************************/\r
+/*-------------------INFORMATIONAL PARAMETERS-----------------------*/\r
+/********************************************************************/\r
+\r
+\r
+\r
+int bth_accept_conn_req_cp(bdaddr_t *bdaddr)                 /*0x01 - 0x0009*/\r
+{\r
+/*------------------------ parts of packet-----------------------*/\r
+    uint8_t *typ_hci_paket; //FIXME: hjkhjkh\r
+    hci_command_hdr *hci_headr;\r
+    accept_conn_req_cp *bth_cmd_packet;\r
+/*-- determine the size of memory needed for command in buff and determine if it fit there */\r
+/*-------------------------------------------------------------------------------*/\r
+/*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
+\r
+    if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
+    {return 1;};\r
+/*setup adresses for packet parts + filling of inidividual fields*/\r
+    int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+ACCEPT_CONN_REQ_CP_SIZE);\r
+\r
+    bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
+    typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
+    hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
+    bth_cmd_packet=(accept_conn_req_cp*)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
+\r
+    store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
+    store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_LINK_CTL, OCF_ACCEPT_CONN_REQ)));\r
+    store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),ACCEPT_CONN_REQ_CP_SIZE);\r
+    memcpy((uint8_t*)bth_cmd_packet+ACCEPT_CONN_REQ_CP____bdaddr,bdaddr,sizeof(bdaddr_t));\r
+    store16(*((uint8_t*)bth_cmd_packet+ACCEPT_CONN_REQ_CP____role), 0x01); //ACL\r
+\r
+/*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
+se overuje, az pri samotnem ukladani */\r
+    if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
+    else{ bth_com_buf_info.aktual=0;};\r
+ return 0;\r
+};\r
+\r
+int bth_cmd_write_page_scan(uint16_t interval, uint16_t window)        /*obcode=1C0C OGF = 0x001C OCF=0x03*/\r
+{\r
+/*------------------------ parts of packet-----------------------*/\r
+    uint8_t *typ_hci_paket;\r
+    hci_command_hdr *hci_headr;\r
+    write_page_activity_cp *bth_cmd_packet;\r
+/*-- determine the size of memory needed for command in buff and determine if it fit there */\r
+/*-------------------------------------------------------------------------------*/\r
+/*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
+\r
+    if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
+    {return 1;};\r
+/*setup adresses for packet parts + filling of inidividual fields*/\r
+    int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+WRITE_PAGE_ACTIVITY_CP_SIZE);\r
+\r
+    bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
+    typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
+    hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
+    bth_cmd_packet=(write_page_activity_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
+\r
+    store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
+    store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_PAGE_ACTIVITY)));\r
+    store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),WRITE_PAGE_ACTIVITY_CP_SIZE);\r
+    store_le16((uint8_t*)bth_cmd_packet+WRITE_PAGE_ACTIVITY_CP____interval,interval);\r
+    store_le16((uint8_t*)bth_cmd_packet+WRITE_PAGE_ACTIVITY_CP____window,window);\r
+\r
+/*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
+se overuje, az pri samotnem ukladani */\r
+    if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
+    else{ bth_com_buf_info.aktual=0;};\r
+ return -1;\r
+};\r
+\r
+\r
+\r
+//--------------------------------------------------------------------------------------------\r
+//--------------------------------------------------------------------------------------------\r
+//--------------------------------------------------------------------------------------------\r
+int bth_cmd_write_inquiry_scan_activity(uint16_t interval, uint16_t window) //0x001E\r
+{\r
+/*------------------------ parts of packet-----------------------*/\r
+    uint8_t *typ_hci_paket;\r
+    hci_command_hdr *hci_headr;\r
+    write_inq_activity_cp *bth_cmd_packet;\r
+/*-- determine the size of memory needed for command in buff and determine if it fit there */\r
+/*-------------------------------------------------------------------------------*/\r
+/*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
+\r
+    if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
+    {return 1;};\r
+/*setup adresses for packet parts + filling of inidividual fields*/\r
+    int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+WRITE_PAGE_ACTIVITY_CP_SIZE);\r
+    bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
+    typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
+    hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
+    bth_cmd_packet=(write_inq_activity_cp *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
+\r
+    store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
+    store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_INQ_ACTIVITY)));\r
+    store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),WRITE_INQ_ACTIVITY_CP_SIZE);\r
+    store_le16((uint8_t*)bth_cmd_packet+WRITE_INQ_ACTIVITY_CP____interval,interval);\r
+    store_le16((uint8_t*)bth_cmd_packet+WRITE_INQ_ACTIVITY_CP____window,window);\r
+\r
+/*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
+se overuje, az pri samotnem ukladani */\r
+    if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
+    else{ bth_com_buf_info.aktual=0;};\r
+    return(-1);\r
+};\r
+\r
+int bth_cmd_read_bd_addr(void) /*opcode=0x0910 OCF = 0x0009, OGF = 0x04*/\r
+{\r
+/*------------------------ parts of packet-----------------------*/\r
+    uint8_t *typ_hci_paket;\r
+    hci_command_hdr *hci_headr;\r
+/*-- determine the size of memory needed for command in buff and determine if it fit there */\r
+/*-------------------------------------------------------------------------------*/\r
+/*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
+\r
+    if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
+    {return 1;};\r
+/*setup adresses for packet parts + filling of inidividual fields*/\r
+    int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE);\r
+    bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
+    typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
+    hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
+\r
+    store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
+    store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_INFO_PARAM, OCF_READ_BD_ADDR)));\r
+    store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),0);\r
+\r
+/*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
+se overuje, az pri samotnem ukladani */\r
+    if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
+    else{ bth_com_buf_info.aktual=0;};\r
+  return -1;\r
+};\r
+\r
+int bth_cmd_write_scan_enable(uint8_t set_ing_scan) //0x001A\r
+{\r
+/*------------------------ parts of packet-----------------------*/\r
+    uint8_t *typ_hci_paket;\r
+    hci_command_hdr *hci_headr;\r
+    uint8_t *bth_cmd_packet;\r
+\r
+/*-- determine the size of memory needed for command in buff and determine if it fit there */\r
+/*-------------------------------------------------------------------------------*/\r
+/*-- urceni potreb. velikostipro command prikaz v buff. a zjisteni zda se vejde--*/\r
+\r
+    if(bth_array_adrr_comm_packet[bth_com_buf_info.aktual]!=NULL)\r
+    {return 1;};\r
+/*setup adresses for packet parts + filling of inidividual fields*/\r
+    int hp_size=(sizeof(uint8_t)+HCI_COMMAND_HDR_SIZE+WRITE_SCAN_ENABLE_SIZE);\r
+    bth_array_adrr_comm_packet[bth_com_buf_info.aktual]=malloc(hp_size);\r
+    typ_hci_paket=(uint8_t*)bth_array_adrr_comm_packet[bth_com_buf_info.aktual]; //pozice v buff, ktera je prirazena paketu\r
+    hci_headr=(hci_command_hdr *)(((uint8_t*)typ_hci_paket)+HCI_PKT_SIZE);             //pointer on head\r
+    bth_cmd_packet=(uint8_t *)(((uint8_t*)hci_headr)+HCI_COMMAND_HDR_SIZE);   //pointer on parametrs\r
+\r
+\r
+    store16(*typ_hci_paket, HCI_COMMAND_PKT);\r
+    store_le16((uint8_t*)hci_headr+HCI_COMMAND_HDR____opcode,htobs(cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE)));\r
+    store16(*((uint8_t*)hci_headr+HCI_COMMAND_HDR____plen),WRITE_SCAN_ENABLE_SIZE);\r
+    store16(*bth_cmd_packet,set_ing_scan);\r
+/*nastaveni pozice v poli command prikazu pro pristi prikaz. Moznost zapisu (adresa v poli = NULL)\r
+se overuje, az pri samotnem ukladani */\r
+    if(bth_com_buf_info.aktual<(LENCOMMAND-2)){bth_com_buf_info.aktual++;}\r
+    else{ bth_com_buf_info.aktual=0;};\r
+  return -1;\r
+};\r
+\r
+//FIXME: All the czech comments are the same as in the first function.\r
+\r