From: Mattias A. <mat...@us...> - 2001-08-27 15:20:42
|
The following file was modified in linux/drivers/char/bluetooth: Name Old version New version Comment ---- ----------- ----------- ------- test.c 1.25 1.26=20=20=20=20=20=20=20=20=20=20=20=20 The accompanying log: * use simple_strtoul instead of my_atoi (kernel mode) * renamed l2cap con object variables * added tx_data command which can send data to any local CID The diff of the modified file(s): --- test.c 2001/08/17 09:20:46 1.25 +++ test.c 2001/08/27 15:20:41 1.26 @@ -133,6 +133,12 @@ s32 use_multiple_conf_params =3D 0; s32 disable_testpsm =3D 0; =20 +u8 testdata[UPTEST_DATA_LEN]; + +#ifdef __KERNEL__ +#define strtoul simple_strtoul +#endif + void test_init(void) { protocol_layer this_layer; @@ -205,18 +211,18 @@ } =20 =20 -void test_connect_ind(l2cap_con *l2cap)=20 +void test_connect_ind(l2cap_con *con)=20 { #ifdef __KERNEL__ static struct timer_list test_timer; #endif =20 - D_STATE("test_connect_ind : remote cid : %d\n", l2cap->remote_cid); - PRINTPSM(l2cap); + D_STATE("test_connect_ind : remote cid : %d\n", con->remote_cid); + PRINTPSM(con); =20 if (emulate_pending) { printk("Sending connect rsp pending and waiting 5 secs\n"); - if (l2ca_connect_rsp(l2cap, RES_PENDING, STAT_AUTHENTPEND)) { + if (l2ca_connect_rsp(con, RES_PENDING, STAT_AUTHENTPEND)) { D_ERR("test_connect_ind: l2ca_connect_rsp failed\n");=20 return; } @@ -225,17 +231,19 @@ #ifdef __KERNEL__ init_timer(&test_timer); test_timer.function =3D test_timeout; - test_timer.data =3D (unsigned long)l2cap; + test_timer.data =3D (unsigned long)con; test_timer.expires =3D jiffies + 5*HZ; add_timer(&test_timer); -#endif return; +#else + sleep(5); +#endif } =20=09 if (disable_testpsm =3D=3D 1) { /* send back psm not supp */ - if (l2ca_connect_rsp(l2cap, RES_PSMNEG, 0)) { + if (l2ca_connect_rsp(con, RES_PSMNEG, 0)) { D_ERR("test_connect_ind: l2ca_connect_rsp failed\n");=20 return; } @@ -245,48 +253,47 @@ } =20 printk("now sending back result success !\n"); - if (l2ca_connect_rsp(l2cap, RES_SUCCESS, STAT_NOINFO)) { + if (l2ca_connect_rsp(con, RES_SUCCESS, STAT_NOINFO)) { D_ERR("test_connect_ind: l2ca_connect_rsp failed\n");=20 return; } =20 /* (temp fix for test interface) store connection */ =20 - if (l2cap->psm =3D=3D L2CAP_TEST_LAYER) - testcon =3D l2cap; - else if (l2cap->psm =3D=3D L2CAP_TEST2_LAYER) - testcon2 =3D l2cap; - else if (l2cap->psm =3D=3D L2CAP_TEST3_LAYER) - testcon3 =3D l2cap; + if (con->psm =3D=3D L2CAP_TEST_LAYER) + testcon =3D con; + else if (con->psm =3D=3D L2CAP_TEST2_LAYER) + testcon2 =3D con; + else if (con->psm =3D=3D L2CAP_TEST3_LAYER) + testcon3 =3D con; } =20 /* only client receives connect pnd */ -void test_connect_pnd(l2cap_con *l2cap, s32 status) +void test_connect_pnd(l2cap_con *con, s32 status) { D_STATE("test_connect_pnd : reason %d\n", status);=09 - PRINTPSM(l2cap); + PRINTPSM(con); =20 - if (l2cap->psm =3D=3D L2CAP_TEST_LAYER) - testcon =3D l2cap; - else if (l2cap->psm =3D=3D L2CAP_TEST2_LAYER) - testcon2 =3D l2cap; - else if (l2cap->psm =3D=3D L2CAP_TEST3_LAYER) - testcon3 =3D l2cap; + if (con->psm =3D=3D L2CAP_TEST_LAYER) + testcon =3D con; + else if (con->psm =3D=3D L2CAP_TEST2_LAYER) + testcon2 =3D con; + else if (con->psm =3D=3D L2CAP_TEST3_LAYER) + testcon3 =3D con; } =20 /* only client receives connect cfm */ -void test_connect_cfm(l2cap_con *l2cap, s32 status) +void test_connect_cfm(l2cap_con *con, s32 status) { D_STATE("test_connect_cfm\n"); - PRINTPSM(l2cap); + PRINTPSM(con); =20 if(status) { D_STATE("Connect failed: Status %d\n", status); return; } =20=09 - - if (!l2ca_local_conf_done(l2cap)) { + if (!l2ca_local_conf_done(con)) { if (dont_send_config_req) { printk("Don't send back config_req...\n"); printk("Now waiting for initator to shutdown link...\n"); @@ -296,20 +303,20 @@ =20 /* still haven't sent config request yet */ if (use_multiple_conf_params) { - if (l2ca_config_req(l2cap, 1280, NULL, 0x1234, 0)) { + if (l2ca_config_req(con, 1280, NULL, 0x1234, 0)) { D_ERR("test_config_cfm : Configuration request failed\n"); } } else { - if (l2ca_config_req(l2cap, 0, NULL, 0, 0)) { + if (l2ca_config_req(con, 0, NULL, 0, 0)) { D_ERR("test_config_cfm : Configuration request failed\n"); } } =20=09=09 /* store connection */ - if (l2cap->psm =3D=3D L2CAP_TEST_LAYER) - testcon =3D l2cap; - else if (l2cap->psm =3D=3D L2CAP_TEST2_LAYER) - testcon2 =3D l2cap; - else if (l2cap->psm =3D=3D L2CAP_TEST3_LAYER) - testcon3 =3D l2cap; + if (con->psm =3D=3D L2CAP_TEST_LAYER) + testcon =3D con; + else if (con->psm =3D=3D L2CAP_TEST2_LAYER) + testcon2 =3D con; + else if (con->psm =3D=3D L2CAP_TEST3_LAYER) + testcon3 =3D con; } else=20=09=20=20=20=20=20=20=20 D_RCV("test_config_cfm : already have sent config request\n"); } @@ -317,28 +324,28 @@ =20 /* someone wants to configure l2cap... */ void=20 -test_config_ind(l2cap_con* l2cap) +test_config_ind(l2cap_con* con) {=20 D_STATE("test_config_ind : remote cid : %d remote_mtu : %d\n",=20 - l2cap->remote_cid, l2cap->remote_mtu); + con->remote_cid, con->remote_mtu); =20=09 /* check if we have sent a pos response yet */ - if (!l2ca_remote_conf_done(l2cap)) { + if (!l2ca_remote_conf_done(con)) { /* still haven't sent a pos configure response*/ =20 - if (l2ca_config_rsp(l2cap, 0, NULL, CONF_SUCCESS)) { + if (l2ca_config_rsp(con, 0, NULL, CONF_SUCCESS)) { D_ERR("test_config_ind : Configuration response failed\n"); }=20=20=20=20 } else=20 printk("test_config_ind : already have sent back a pos response\n"); =20 /* check if we received a pos response on a previous config req */=20 - if (!l2ca_local_conf_done(l2cap)) { + if (!l2ca_local_conf_done(con)) { =20 /* still haven't sent config request yet */ =20 D_RCV("Setting local mtu to %d on con (%d:%d)\n",=20 - l2cap->local_mtu, l2cap->local_cid, l2cap->remote_cid); + con->local_mtu, con->local_cid, con->remote_cid); =20 if (dont_send_config_req) { printk("Don't send back config_req...\n"); @@ -349,11 +356,11 @@ =20=09=09 /* still haven't sent config request yet */ if (use_multiple_conf_params) { - if (l2ca_config_req(l2cap, 1280, NULL, 0x1234, 0)) { + if (l2ca_config_req(con, 1280, NULL, 0x1234, 0)) { D_ERR("test_config_cfm : Configuration request failed\n"); } } else { - if (l2ca_config_req(l2cap, test_inmtu, NULL, 0, 0)) + if (l2ca_config_req(con, test_inmtu, NULL, 0, 0)) D_ERR("test_config_ind : configuration request failed\n"); =20 if (test_inmtu) @@ -367,26 +374,26 @@ D_RCV("already ready with config req\n"); } =20 -void test_config_cfm(l2cap_con *l2cap, s32 status) +void test_config_cfm(l2cap_con *con, s32 status) { - D_STATE("test_config_cfm : remote cid : %d\n", l2cap->remote_cid); + D_STATE("test_config_cfm : remote cid : %d\n", con->remote_cid); =20=09 D_STATE("Now we have an open l2cap channel\n"); =20 /* negotiate upper protocol */ } =20 -void test_disconnect_ind(l2cap_con *l2cap)=20 +void test_disconnect_ind(l2cap_con *con)=20 { D_STATE("test_disconnect_ind : (%d:%d)\n",=20 - l2cap->local_cid, l2cap->remote_cid); + con->local_cid, con->remote_cid); =20 - l2ca_disconnect_rsp(l2cap); + l2ca_disconnect_rsp(con); } =20 -void test_disconnect_cfm(l2cap_con *l2cap) +void test_disconnect_cfm(l2cap_con *con) { - D_STATE("TEST_disconnect_cfm: remote cid : %d\n", l2cap->remote_cid); + D_STATE("TEST_disconnect_cfm: remote cid : %d\n", con->remote_cid); } =20 s32 test_disconnect_req(l2cap_con *con) @@ -398,9 +405,9 @@ return l2ca_disconnect_req(con); } =20 -void test_receive_data(l2cap_con *l2cap, unsigned char* data, u32 len) +void test_receive_data(l2cap_con *con, unsigned char* data, u32 len) { - PRINTPSM(l2cap); + PRINTPSM(con); PRINTPKT("test_receive_data : ", data, len);=20=20 } =20 @@ -428,25 +435,8 @@ return l2cap_send_data(tx_buf, con); } =20 -/* assumes int at end of string */ -int -my_atoi(u8 *str) -{ - int i =3D 0, mult =3D 1; - int len =3D strlen(str); - int res =3D 0; =20=20=20 - for (i =3D len-1; i >=3D 0; i--) { - if ((str[i] <=3D '9') && (str[i] >=3D '0' )) { - res +=3D mult*(str[i]-'0'); - mult *=3D 10; - } - else=20 - return -1; - }=20=20 - - return res; -} +/* FIXME -- add new commands in user application menu !!!! */ =20 void test_process_cmd(unsigned char *cmd, s32 size) @@ -455,8 +445,9 @@ int testcase, tmp[10], i; unsigned char bd[6], char_buf[4]; char_buf[3] =3D 0; + if(strncmp(cmd, "t ", 2) =3D=3D 0) { - testcase =3D my_atoi(cmd+2); + testcase =3D strtoul(cmd+2, NULL, 0); =20 if (testcase > 0) { process_test_cmd(testcase); @@ -466,8 +457,12 @@ } } else if(!strncmp(cmd, "bb_conn ", 8)) { + char *p =3D cmd + 8; +=09=09 for (i =3D 0; i < 6; i++) { - bd[i] =3D (unsigned char *)my_atoi(strncpy(&char_buf[0], cmd + 8 + (i*3= ), 3)); + bd[i] =3D strtoul(p, &p, 0); + printk("bb_conn read [%d] =3D 0x%x\n", i, bd[i]); + p=3Dp+1; } =20=09=09 printk("Connecting BB to bd : %02X:%02X:%02X:%02X:%02X:%02X\n", @@ -478,13 +473,13 @@ lp_connect_req(bd); } else if(!strncmp(cmd, "bb_disc ", 8)) { - int i =3D my_atoi(&cmd[8]); + int i =3D strtoul(cmd+8, NULL, 0); lp_disconnect((unsigned short)i); } else if(!strncmp(cmd, "lcid_disconnect ", 16)) { l2cap_con *con =3D NULL; - int i =3D my_atoi(&cmd[16]); - if(con =3D get_lcon(i)) { + int i =3D strtoul(cmd + 16, NULL, 0); + if((con =3D get_lcon(i))) { l2ca_disconnect_req(con); } else { @@ -493,12 +488,33 @@ } else if(!strncmp(cmd, "test_case_reject ", 17)) { unsigned short fake_psm =3D 0x4561; + char *p =3D cmd + 8; for (i =3D 0; i < 6; i++) { - bd[i] =3D (unsigned char)my_atoi(strncpy(&char_buf[0], cmd + 17 + i*3, = 3)); + bd[i] =3D strtoul(p, &p, 0); + printk("bb_conn read [%d] =3D 0x%x\n", i, bd[i]); + p++; }=20=20 l2ca_connect_req(bd, fake_psm); } - else { + else if(!strncmp(cmd, "tx_data ", 8)) { + int lcid, len; + char *p =3D cmd+8; + l2cap_con *con; + lcid =3D strtoul(p, &p, 0); + len =3D strtoul(p+1, &p, 0); +=09=09 + /* first find connection based on local cid */ + con =3D get_lcon(lcid); + if (!con) { + printk("Found no connection with lcid : %d\n", lcid); + return; + } + + test_send_data(con, testdata, len); + } else if(!strncmp(cmd, "sdptest ", 8)) { + int n =3D strtoul(cmd+8, NULL, 0);=09 + do_sdp_test(n); + } else { printk("Unknown test cmd!\n"); } =20=09 |