From 8928dfef12503ab269bb1695e564cdebc1d53e84 Mon Sep 17 00:00:00 2001 From: David Plotek Date: Sun, 20 Jul 2008 13:03:57 +0200 Subject: [PATCH] part of support functions was added --- src/hil2cap.c | 176 ++++++++++++++++++++++++++++++++------------------ src/hil2cap.h | 29 +++++++-- 2 files changed, 137 insertions(+), 68 deletions(-) diff --git a/src/hil2cap.c b/src/hil2cap.c index 87885b5..d7e2b22 100644 --- a/src/hil2cap.c +++ b/src/hil2cap.c @@ -18,38 +18,22 @@ #include "hcidriver.h" +cmd_state_request array_req[MAX_CMD_STATE_REQUEST]; +int cmd_req_id; -extern int errno; - -int main(void) -{ dev_lap lap; - lap.byte[0]=0x00; - lap.byte[1]=0x55; - lap.byte[2]=0x12; - //inicialization process, obtain adress and name from local controller - struct hci_dev_info device,*p_device; - p_device=&device; - connection_hci connection,*p_connection; - p_connection=&connection; - p_connection->con_state=DISCONNECTED; - //show_all_local_dev(p_connection,p_device); - - -return 0; -} -int create_master_connection(void){//establish connection and send a coutn of bytes every x second - cmd_state_request array_req[MAX_CMD_STATE_REQUEST]; //array of open request which are in waiting state for appropriate event or answer +int create_master_connection(hci_dev_info *master){//establish connection and send a coutn of bytes every x second + //array of open request which are in waiting state for appropriate event or answer connection_hci connection,*p_connection=&connection; p_connection->con_id=0; p_connection->con_state=DISCONNECTED; - memset(array_req,0,(sizeof(cmd_state_request)*MAX_CMD_STATE_REQUEST)); + while(1){ if(!p_connection->con_state){ //there is no connection, create it - + } @@ -59,62 +43,128 @@ int create_master_connection(void){//establish connection and send a coutn of by } - -//void call_hci_send_data(unsigned short con_handle, __u8 pb_flag, __u8 b_flag, unsigned short data_lenght) - -//void call_hci_create_connection(bt_address *dev_adress,unsigned short pkt_type,__u8 sc_mod){// - -//} - -//Socket functions -/*void show_all_local_dev(connection_hci *connection, struct hci_dev_info *p_device){ - int errr=0; +int show_all_local_dev(hci_dev_info *master){ // and choose a master device which will initiate the connection int sock,i; - int timeout=1000; + hci_dev_list_req dlist,*p_dlist=&dlist; + hci_dev_req *p_dreq; - bt_device_req_list dlist,*p_dlist; - bt_device_req *p_dreq; - - p_dlist=&dlist; - p_dlist->dev_num=HCI_MAX_DEV; p_dreq=p_dlist->dev_req; if((sock=socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI))<0){ - perror("socket"); - errr=1; + return -1; } if((ioctl(sock, HCIGETDEVLIST, (void *) p_dlist))<0){ - perror("Can't get device list"); - errr=2; + return -1; } - if(p_dlist->dev_num >1 && errr == 0){ - bt_device dev_array[p_dlist->dev_num]; + if(p_dlist->dev_num > 0){ + hci_dev_info dev_array[p_dlist->dev_num]; for(i=0;idev_num;i++){ - dev_array[i].dev_id=(p_dreq+i)->dev_id; - if(ioctl(sock, HCIGETDEVINFO, (void *) &dev_array[i])<0){ - printf("No info"); - continue; - } - int dd=hci_open_device(dev_array[i].dev_id); - if(call_hci_read_bd_addr_cmd(dd,&dev_array[i].bdaddr, timeout)< 0){ - printf("Error in call hci bd addr cnd"); - exit(0); - } - printba(&dev_array[i].bdaddr); + dev_array[i].dev_id=(p_dreq+i)->dev_id; + if(ioctl(sock, HCIGETDEVINFO, (void *) &dev_array[i])<0){ + printf("No info"); + continue; + } + int dd=hci_open_device(dev_array[i].dev_id); + if(l2cap_call_cmd(READ_BD_ADDR_CMD_OP,dd)< 0){ + printf("Error in call hci bd addr cmd \n"); + return -1; + } + if(l2cap_call_cmd(READ_LOCAL_NAME_CMD_OP,dd)< 0){ + printf("Error in call hci bd addr cmd \n"); + return -1; + } } + *master = dev_array[0]; //I will take a first dev like a master + } else{ - switch(errr){ - case 1: printf("Error: %d,%d",errr,errno);break; - case 2: printf("Error: %d,%d",errr,errno);break; - //case 3: printf("Error in call hci bd addr cnd");break; - } - printf("There is no BT host controler device connected!! \n"); - exit(0); + printf("There is no hci device \n"); + return -1; } -} */ +} + +int l2cap_call_cmd(__u16 ocf_ogf,int dd){ + cmd_state_request new_req,*p_new_req=&new_req; + + switch(ocf_ogf){ + + case READ_BD_ADDR_CMD_OP:{ + p_new_req->actual_status=ESTABLISHED; + p_new_req->id=cmd_rq_id++; + p_new_req->req_opcode = ocf_ogf; + p_new_req->evt_code = EVT_CMD_COMPLETE; + p_new_req->p_serv_rutine=rutine_catch_bd_addr; + + if(req_fcn_add(p_new_req)<0){ + printf("Mistake with req array adding \n "); + return -1; + } + call_hci_read_bd_addr_cmd() + + + } + case READ_LOCAL_NAME_CMD_OP:{ + + } + + + } + + +} +/* request array support functions */ +int req_fcn_add(cmd_state_request *p_req){ //fcn add the request at the end of array or replace the oldest request + int i,sig=0,index=0; + cmd_state_request the_oldest=array_req[0]; + + for(i=0;iactual_status==0 || array_req[i]->actual_status==3 ){ + array_req[i]=*p_req; + sig=1; + break; + } + if(array_req[i]->id < the_oldest.id){ //the smallest id (oldest request) will stay here + the_oldest = array_req[i]; + index=i; + } + } + if(!sig){ + return -1; + array_req[index]=*p_req; + } + return 1; +} + +/* rutines for each command */ +//todo: +void *rutine_catch_bd_addr(void *arg){ + +return (void*)0; +} + + +int main(void){ + struct hci_dev_info master,*p_master=&master; + cmd_req_id=0; + memset(array_req,0,(sizeof(cmd_state_request)*)); + + + + +return 0; +} + + +//void call_hci_send_data(unsigned short con_handle, __u8 pb_flag, __u8 b_flag, unsigned short data_lenght) + +//void call_hci_create_connection(bt_address *dev_adress,unsigned short pkt_type,__u8 sc_mod){// + +//} + +//Socket functions +/* */ diff --git a/src/hil2cap.h b/src/hil2cap.h index 62871d4..b125137 100644 --- a/src/hil2cap.h +++ b/src/hil2cap.h @@ -18,17 +18,36 @@ #include /* Connection states */ -#define DISCONNECTED 0 -#define CONNECTED 1 -#define PENDING 2 +#define DISCONNECTED 0 +#define CONNECTED 1 +#define PENDING 2 + +/* CMD request states*/ +#define FREE 0 +#define ESTABLISHED 1 +#define PENDING 2 +#define DONE 3 + +/* CMD ocf and ogf */ + +#define INQUIRY_CMD_OP 0x0104 +#define INQUIRY_CANCEL_CMD_OP 0x0204 +#define CREATE_CONNECTION_CMD_OP 0x0504 +#define DISCONNECT_CMD_OP 0x0604 +#define REMOTE_NAME_REQUEST_CMD_OP 0x1904 +#define RESET_CMD_OP 0x030C +#define WRITE_LOCAL_NAME_CMD_OP 0x130C +#define READ_LOCAL_NAME_CMD_OP 0x140C +#define READ_BD_ADDR_CMD_OP 0x0910 #define MAX_CMD_STATE_REQUEST 0x0F typedef struct{ __u8 actual_status; __u8 id; - __u16 request_opcode; - __u16 answer_opcode; + __u16 req_opcode; + __u16 evt_code; // code of expected ansver event , command status event will be accepted everytime + void *p_serv_rutine; } __attribute__((packed)) cmd_state_request; -- 2.39.2