From d161a872794053e1f48e3fd1679784cc2ea0cc0a Mon Sep 17 00:00:00 2001 From: David Plotek Date: Fri, 25 Jul 2008 00:47:56 +0200 Subject: [PATCH 1/1] begin part of slave main cycle with ansvering the incoming events --- src/hil2cap.c | 6 ++-- src/hil2cap.h | 11 +++++-- testf/t2/slavetest.c | 78 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 74 insertions(+), 21 deletions(-) diff --git a/src/hil2cap.c b/src/hil2cap.c index 02a4a44..a79042c 100644 --- a/src/hil2cap.c +++ b/src/hil2cap.c @@ -216,6 +216,7 @@ int main(void){ bt_address remote_bd_addr_array[HCI_MAX_DEV]; memset(remote_bd_addr_array,0,(sizeof(bt_address)*HCI_MAX_DEV)); connection_hci connection,*p_connection=&connection; + bt_address prefered; int remd_count,i; cmd_req_id=0; global_index=0; @@ -233,8 +234,9 @@ int main(void){ printba(&remote_bd_addr_array[i]); } p_connection->master=master; - p_connection->slave.bdaddr=remote_bd_addr_array[0]; - + //p_connection->slave.bdaddr=remote_bd_addr_array[0]; + fill_add(&prefered,0xE1,0x03,0x24,0x63,0x89,0x22); + p_connection->slave.bdaddr=prefered; if(create_master_connection(p_connection)<0){ printf("connection error"); return -1; diff --git a/src/hil2cap.h b/src/hil2cap.h index 1434a4e..826ab3e 100644 --- a/src/hil2cap.h +++ b/src/hil2cap.h @@ -21,10 +21,10 @@ #define DISCONNECTED 0 #define CONNECTED 1 -/* CMD request states*/ +/* CMD\EVT states*/ #define FREE 0 #define ESTABLISHED 1 -#define PENDING 2 +#define PERMANENT 2 #define DONE 3 /* CMD ocf and ogf */ @@ -41,6 +41,7 @@ #define MAX_CMD_STATE_REQUEST 0x0F +#define MAX_EVT_COUNT 128 typedef struct{ __u8 actual_status; __u8 id; @@ -50,6 +51,12 @@ typedef struct{ } __attribute__((packed)) cmd_state_request; +typedef struct{ + __u8 actual_status; + __u16 id; + __u16 evt_code; + void (*p_serv_rutine)(void); +} __attribute__((packed)) incoming_evt; typedef struct{ __u16 con_id; diff --git a/testf/t2/slavetest.c b/testf/t2/slavetest.c index f1c1ac2..cf66c80 100644 --- a/testf/t2/slavetest.c +++ b/testf/t2/slavetest.c @@ -20,30 +20,30 @@ #include #include "hcidriver.h" -cmd_state_request array_req[MAX_CMD_STATE_REQUEST]; -int cmd_req_id; +incoming_evt evt_array[MAX_CMD_STATE_REQUEST]; +int evt_id; int global_index; -int req_fcn_add(cmd_state_request *p_req){ //fcn add the request at the end of array or replace the oldest request +int add_evt_toarray(incoming_evt *p_evt){ //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]; + incoming_evt the_oldest=evt_array[0]; - for(i=0;iid=cmd_req_id++; - //p_new_req->req_opcode = ocf_ogf; - p_new_req->evt_code = EVT_CONN_REQUEST; - p_new_req->p_serv_rutine=&rutine_con_req; + p_new_evt->id=evt_id++; + p_new_evt->actual_status=PERMANENT; + p_new_req->evt_code = EVT_CMD_STATUS; + p_new_req->p_serv_rutine=&rutine_cmd_status; + int dd=hci_open_device(1); // only for testig 1 + add_evt_toarray(p_new_evt); + p_new_evt->id=evt_id++; + p_new_evt->actual_status=ESTABLISHED; + p_new_req->evt_code = EVT_CONN_REQUEST; + p_new_req->p_serv_rutine=&rutine_con_req; + + len = sizeof(of); + if(getsockopt(dd, SOL_HCI, HCI_FILTER, &of, &len)<0){ + printf("some problem with getsockopt: %d",dd); + return -1; + } + hci_filter_clear(&nf); + hci_filter_set_ptype(HCI_EVENT_PKT, &nf); + hci_filter_set_event(EVT_CMD_STATUS, &nf); + //hci_filter_set_event(EVT_INQUIRY_RESULT_WITH_RSSI, &nf); + //hci_filter_set_event(p_req->event, &nf); + //hci_filter_set_opcode(*(p_req->p_OCF_OGF), &nf); + + if(setsockopt(dd, SOL_HCI, HCI_FILTER, &nf, sizeof(nf))<0){ + printf("some problem with setsockopt: %d",dd); + return -1; + } + while(1){ + if(check_socket(dd)<0){ + printf("problem with sock checking \n"); + break; + } + } + setsockopt(dd, SOL_HCI, HCI_FILTER, &of, sizeof(of)); + hci_close_dev(dd); return 0; } -- 2.39.2