]> rtime.felk.cvut.cz Git - tiny-bt.git/blob - src/hil2cap.c
part of support functions was added
[tiny-bt.git] / src / hil2cap.c
1 /*
2 *  C Implementation: testovaci
3 *
4 * Description: 
5 *
6 *
7 * Author: root <root@ubuntu>, (C) 2008
8 *
9 * Copyright: See COPYING file that comes with this distribution
10 *
11 */
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <sys/ioctl.h>
15 #include <errno.h>
16 #include <stdint.h>
17 #include "hil2cap.h"
18 #include "hcidriver.h"
19
20
21 cmd_state_request array_req[MAX_CMD_STATE_REQUEST];
22 int cmd_req_id;
23
24
25
26
27 int create_master_connection(hci_dev_info *master){//establish connection and send a coutn of bytes every x second
28          //array of open request which are in waiting state for appropriate event or answer
29         connection_hci connection,*p_connection=&connection;
30         p_connection->con_id=0;
31         p_connection->con_state=DISCONNECTED;
32         
33         
34         while(1){
35                 if(!p_connection->con_state){ //there is no connection, create it
36                                 
37                 }
38
39
40
41         }
42         
43
44 }
45
46 int show_all_local_dev(hci_dev_info *master){ // and choose a master device which will initiate the connection
47         int sock,i;
48         hci_dev_list_req dlist,*p_dlist=&dlist;
49         hci_dev_req *p_dreq;
50         
51         p_dreq=p_dlist->dev_req;
52         
53         if((sock=socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI))<0){ 
54                 return -1;
55         }
56         
57         if((ioctl(sock, HCIGETDEVLIST, (void *) p_dlist))<0){
58                 return -1;
59         }
60         if(p_dlist->dev_num > 0){
61                 hci_dev_info dev_array[p_dlist->dev_num];
62                 for(i=0;i<p_dlist->dev_num;i++){
63                         dev_array[i].dev_id=(p_dreq+i)->dev_id;
64                         if(ioctl(sock, HCIGETDEVINFO, (void *) &dev_array[i])<0){
65                                 printf("No info");
66                                 continue;
67                         }
68                         int dd=hci_open_device(dev_array[i].dev_id);
69                         if(l2cap_call_cmd(READ_BD_ADDR_CMD_OP,dd)< 0){
70                                 printf("Error in call hci bd addr cmd \n");
71                                 return -1;
72                         }
73                         if(l2cap_call_cmd(READ_LOCAL_NAME_CMD_OP,dd)< 0){
74                                 printf("Error in call hci bd addr cmd \n");
75                                 return -1;
76                         }
77                 }
78                 *master = dev_array[0]; //I will take a first dev like a master
79                 
80         }
81         else{
82                 printf("There is no hci device \n");
83                 return -1;
84         }
85                 
86 }
87
88 int l2cap_call_cmd(__u16 ocf_ogf,int dd){
89         cmd_state_request new_req,*p_new_req=&new_req;
90
91         switch(ocf_ogf){
92         
93         case READ_BD_ADDR_CMD_OP:{
94                 p_new_req->actual_status=ESTABLISHED;
95                 p_new_req->id=cmd_rq_id++;
96                 p_new_req->req_opcode = ocf_ogf;
97                 p_new_req->evt_code = EVT_CMD_COMPLETE;
98                 p_new_req->p_serv_rutine=rutine_catch_bd_addr;
99
100                 if(req_fcn_add(p_new_req)<0){
101                         printf("Mistake with req array adding \n ");
102                         return -1;
103                 }
104                 call_hci_read_bd_addr_cmd()
105                 
106         
107         }
108         case READ_LOCAL_NAME_CMD_OP:{
109
110         }
111
112         
113         }
114         
115
116 }
117 /* request array support functions */
118 int req_fcn_add(cmd_state_request *p_req){ //fcn add the request at the end of array or replace the oldest request
119         int i,sig=0,index=0;
120         cmd_state_request the_oldest=array_req[0];
121         
122         for(i=0;i<MAX_CMD_STATE_REQUEST;i++){
123                 if(array_req[i]->actual_status==0 || array_req[i]->actual_status==3 ){
124                         array_req[i]=*p_req;
125                         sig=1;
126                         break;
127                 }
128                 if(array_req[i]->id < the_oldest.id){ //the smallest id (oldest request) will stay here
129                         the_oldest = array_req[i];
130                         index=i;
131                 }
132         }
133         if(!sig){
134                 return -1;
135                 array_req[index]=*p_req;        
136         }
137         return 1;
138 }
139
140 /* rutines for each command */
141 //todo:
142 void *rutine_catch_bd_addr(void *arg){
143
144 return (void*)0;
145 }
146
147
148 int main(void){
149         struct hci_dev_info master,*p_master=&master;
150         cmd_req_id=0;
151         memset(array_req,0,(sizeof(cmd_state_request)*));
152         
153         
154         
155         
156 return 0;
157 }
158
159
160 //void call_hci_send_data(unsigned short con_handle, __u8 pb_flag, __u8 b_flag, unsigned short data_lenght)
161
162 //void call_hci_create_connection(bt_address *dev_adress,unsigned short pkt_type,__u8 sc_mod){//
163
164 //}
165
166 //Socket functions
167 /* */
168         
169         
170