|
From: Anders J. <and...@us...> - 2001-10-10 14:58:19
|
The following files were modified in linux/drivers/char/bluetooth:
Name Old version New version Comment
---- ----------- ----------- -------
bluetooth.c 1.202 1.203=20=20=20=20=20=20=20=20=20=20=20
l2cap.c 1.120 1.121=20=20=20=20=20=20=20=20=20=20=20
rfcomm.c 1.122 1.123=20=20=20=20=20=20=20=20=20=20=20
test.c 1.28 1.29=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* Added usable errorvalues instead of just returning -1.
* GET_RFCOMMLINE and GET_SDPLINE -> GET_LINE, code cleanup.
The diff of the modified file(s):
--- bluetooth.c 2001/10/05 12:25:46 1.202
+++ bluetooth.c 2001/10/10 14:58:18 1.203
@@ -1562,7 +1562,7 @@
struct tty_struct *upper_tty;
u32 line;
=20
- line =3D GET_RFCOMMLINE(con_id);
+ line =3D GET_LINE(con_id);
=20=09
/* get upper tty and call its ldisc->receive_buf */
=20
@@ -1840,7 +1840,16 @@
s32
bt_connect(u8 *bd_addr, u32 con_id)
{
- u8 line;=09=09=09=09
+ u8 line =3D GET_LINE(con_id);=09=09=09=09
+ s32 retval =3D 0;
+
+ /* Check if we already got a connection on the line */
+ if ((SESSIONSTATE(line) =3D=3D BT_LOWERCONNECTED)||
+ (SESSIONSTATE(line) =3D=3D BT_ACTIVE)) {
+ D_WARN(__FUNCTION__ ": Already got connection on line %d\n",=20
+ line);=20
+ return -MSGCODE(MSG_BT_INTERFACE, BT_LINE_BUSY);
+ }
=20
switch (GET_PSM(con_id)) {
case RFCOMM_LAYER:
@@ -1849,16 +1858,7 @@
=20
CHECK_RFCOMM(con_id);
srv_ch =3D GET_RFCOMMSRVCH(con_id);
- line =3D GET_RFCOMMLINE(con_id);
=20=09=09
- /* check if we already have a connection otherwise wait... */
- if ((SESSIONSTATE(line) =3D=3D BT_LOWERCONNECTED)||
- (SESSIONSTATE(line) =3D=3D BT_ACTIVE)) {
- D_WARN(__FUNCTION__ ": Already got connection on line %d\n",=20
- GET_RFCOMMLINE(con_id));=20
- return -1;
- }=20
-
bt_ctrl.session[line].connect_status =3D -1;
=20
BT_DRIVER(__FUNCTION__ ": Connecting srv ch %d on line %d\n",
@@ -1885,19 +1885,6 @@
int sdp_connection_id =3D -1;
int return_value;
=20
- /* Get the line to use for SDP communication */
-
- line =3D GET_SDPLINE(con_id);
-
- /* Check the line to assure no other connections on it */
-
- if ((SESSIONSTATE(line) =3D=3D BT_LOWERCONNECTED) ||
- (SESSIONSTATE(line) =3D=3D BT_ACTIVE)) {
- D_WARN(__FUNCTION__ ": Already got connection on line %d\n",
- GET_SDPLINE(con_id));=20
- return -1;
- }
-
/* Initiate the connection */
=20
BT_DRIVER(__FUNCTION__ ": Connecting SDP on line %d\n", line);
@@ -1960,24 +1947,14 @@
case L2CAP_TEST_LAYER:
case L2CAP_TEST2_LAYER:
case L2CAP_TEST3_LAYER:
- line =3D (con_id & 0x0000ffff);
BT_DRIVER(__FUNCTION__ ": Connecting TEST_LAYER (psm %02X) on line %d\n"=
, GET_PSM(con_id), line);
-
- /* Check the line to assure no other connections on it */
-
- if ((SESSIONSTATE(line) =3D=3D BT_LOWERCONNECTED) ||
- (SESSIONSTATE(line) =3D=3D BT_ACTIVE)) {
- D_WARN(__FUNCTION__ ": Already got connection on line %d\n",
- line);=20
- return -1;
- }
=20
- if(test_connect_psmreq(bd_addr, GET_PSM(con_id)) < 0) {
+ if((retval =3D test_connect_psmreq(bd_addr, GET_PSM(con_id))) < 0) {
BT_DRIVER(__FUNCTION__ ": Failed\n");
- return bt_ctrl.session[line].connect_status;
+ return retval;
}
=20=20=20=20=20
- return bt_ctrl.session[line].connect_status;
+ return retval;
=20
case TCS_LAYER:
return tcs_connect_req(bd_addr);
@@ -1992,7 +1969,7 @@
=20
static s32 bt_execute_sdp_request(bt_sdp_request *sdpRequest)
{
- int line =3D GET_SDPLINE(sdpRequest->conID);
+ int line =3D GET_LINE(sdpRequest->conID);
int sdpIndex =3D GET_SDPINDEX(sdpRequest->conID);
=20
if (SESSIONSTATE(line) !=3D BT_ACTIVE) {
@@ -2050,25 +2027,21 @@
bt_connect_cfm(u32 con_id, s32 status)
{
u16 psm;
- s32 line;
-=09
+ s32 line =3D GET_LINE(con_id);
psm =3D GET_PSM(con_id);
=20
- switch (psm) {
- case RFCOMM_LAYER:
- line =3D GET_RFCOMMLINE(con_id);
- CHECK_RFCOMM(con_id);
-
if ((line < 0) || (line > BT_NBR_DATAPORTS)) {
-=09=09=20=20
D_ERR(__FUNCTION__ ": Invalid line (%d)\n", line);
return;
}
=20
+ switch (psm) {
+ case RFCOMM_LAYER:
+ CHECK_RFCOMM(con_id);
bt_ctrl.session[line].connect_status =3D status;
=20
BT_DRIVER(__FUNCTION__ ": Line %d [%s]\n",
- GET_RFCOMMLINE(con_id), psmname(psm));
+ line, psmname(psm));
=20
release_wq_timer(&bt_timer);
wake_up_interruptible(&bt_ctrl.connect_wq[line]);
@@ -2076,18 +2049,9 @@
break;
=20=09
case SDP_LAYER:
- line =3D GET_SDPLINE(con_id);
-
- /* Check incoming line for validity */
- if ((line < 0) || (line > BT_NBR_DATAPORTS)) {
- D_ERR(__FUNCTION__ ": Invalid line (%d)\n", line);
- return;
- }
-
/* Record the connection status for bt_connect() to process. */
-
bt_ctrl.session[line].connect_status =3D status;
- BT_DRIVER(__FUNCTION__ ": Line %d [%s]\n", GET_SDPLINE(con_id), psmname(=
psm));
+ BT_DRIVER(__FUNCTION__ ": Line %d [%s]\n", line, psmname(psm));
BT_DRIVER(__FUNCTION__ ": Wake up line %d\n", line);
release_wq_timer(&bt_timer);
wake_up_interruptible(&bt_ctrl.connect_wq[line]);
@@ -2135,12 +2099,19 @@
static s32=20
bt_disconnect(u32 con_id)
{
- int line;
+ int line =3D GET_LINE(con_id);
+ s32 retval =3D 0;
=20
+ if ((SESSIONSTATE(line) !=3D BT_LOWERCONNECTED) &&=20
+ (SESSIONSTATE(line) !=3D BT_ACTIVE)) {
+ D_ERR(__FUNCTION__ ": Line not connected\n");
+ return -MSGCODE(MSG_BT_INTERFACE, BT_NOTCONNECTED);
+ }
+=09
+
switch(GET_PSM(con_id))
{
case RFCOMM_LAYER:
- line =3D GET_RFCOMMLINE(con_id);
BT_DRIVER(__FUNCTION__ ": Disconnecting line %d (ONLY RFCOMM)\n",=20
line);
=20
@@ -2148,45 +2119,39 @@
=20
bt_ctrl.session[line].disconnect_status =3D -1;
=20
- /* check if we have a connection */
- if ((SESSIONSTATE(line) =3D=3D BT_LOWERCONNECTED) ||=20
- (SESSIONSTATE(line) =3D=3D BT_ACTIVE)) {
- if (rfcomm_disconnect_req(line) < 0) {
+ if ((retval =3D rfcomm_disconnect_req(line)) < 0) {
BT_DRIVER(__FUNCTION__ ": Failed\n");
- return bt_ctrl.session[line].disconnect_status;
+ return retval;
}
=20
/* fixme -- remove timers, useless when rfcomm blocks ? */
=20
/* Sleep if not yet disconnected */
if (bt_ctrl.session[line].disconnect_status =3D=3D -1) {
- /* use connect wq for dusconnect aswell */
start_wq_timer(&bt_timer, BT_CON_TIMEOUT,=20
&bt_ctrl.connect_wq[line]);
interruptible_sleep_on(&bt_ctrl.connect_wq[line]);
}
- } else {
- bt_ctrl.session[line].disconnect_status =3D
- MSGCODE(MSG_BT_INTERFACE, BT_NOTCONNECTED);
- }
+=09=09
return bt_ctrl.session[line].disconnect_status;
=20=09=20=20
case L2CAP_TEST_LAYER:
- test_disconnect_req(testcon); /* extern l2cap_con set in test.c */
+ retval =3D test_disconnect_req(testcon); /* extern l2cap_con set in test=
.c */
return bt_ctrl.session[line].disconnect_status;
=20
case L2CAP_TEST2_LAYER:
- test_disconnect_req(testcon2);
+ retval =3D test_disconnect_req(testcon2);
return bt_ctrl.session[line].disconnect_status;
=20
case L2CAP_TEST3_LAYER:
- test_disconnect_req(testcon3);
+ retval =3D test_disconnect_req(testcon3);
return bt_ctrl.session[line].disconnect_status;
=20
default:
BT_DRIVER(__FUNCTION__ ": Can't disconnect this layer (PSM %x)\n", GET_P=
SM(con_id));
return -EINVAL;
}
+ return retval;
}
=20
/* This function is currently not used in OpenBT for any useful stuff,
@@ -2204,7 +2169,7 @@
void
bt_disconnect_cfm(u32 con_id, s32 status)=20
{
- u32 line =3D GET_RFCOMMLINE(con_id);
+ u32 line =3D GET_LINE(con_id);
=20
BT_DRIVER(__FUNCTION__ ": PSM %d, status %d\n",=20
GET_PSM(con_id), status);
--- l2cap.c 2001/10/03 12:12:35 1.120
+++ l2cap.c 2001/10/10 14:58:18 1.121
@@ -1385,6 +1385,7 @@
}
=20
con->c_status =3D status;
+ con->c_result =3D status;
=20=09
if (status =3D=3D 0) {
/* pos cfm */
@@ -1536,7 +1537,7 @@
{
l2cap_con *con;
l2cap_con *tmpcon;
- s32 i;
+ s32 i, retval =3D 0;
u8 rev_bd[6];
=20
D_RCV(__FUNCTION__ "\n");
@@ -1601,24 +1602,22 @@
con->link_up =3D 1;
ENTERSTATE(con, W4_L2CAP_CONNECT_RSP);
PRINTSTATE(con);
-
- l2cap_connect_req(con, psm);
-
- l2ca_wait(__FUNCTION__ ": wait rsp", con);
-
- /* fixme -- use con->c_status */
- return 0;
} else {
D_STATE(__FUNCTION__ ": create new baseband link\n");
- lp_connect_req(con->remote_bd);=20=20
+ retval =3D lp_connect_req(con->remote_bd);
+ if(retval < 0) {
+ D_ERR(__FUNCTION__ ": failed (status %d)\n", retval);
+ return retval;
+ }
=20
/* wait here until we received a lp_connect_cfm */
l2ca_wait(__FUNCTION__ ": wait baseband", con);
=20=09=09
if (con->c_status !=3D RES_SUCCESS) {
- D_ERR(__FUNCTION__ ": failed !\n");
+ D_ERR(__FUNCTION__ ": lp_connect_req failed, no connection (status %d)\=
n", con->c_status);
+ retval =3D -MSGCODE(MSG_LAYER_HCI, con->c_status);
delete_con(con);
- return -1;
+ return retval;
}
}=09
=20
@@ -1628,13 +1627,18 @@
/* Leave loop when either status failed or success */
while (con->c_status =3D=3D CSTATUS_RTX_TIMEOUT) {
/* baseband is up, now initiate send connect req */
- l2cap_connect_req(con, con->psm);
-
+ retval =3D l2cap_connect_req(con, con->psm);
+ if(retval < 0) {
+ D_ERR(__FUNCTION__ ": failed (status %d)\n", retval);
+ }
/* wait until we received a response or after timeout */
l2ca_wait(__FUNCTION__ ": wait rsp", con);
}
=20
- return con->c_result;
+ if (con->c_status =3D=3D CSTATUS_MAX_NO_RTX && !retval) {
+ retval =3D -MSGCODE(MSG_LAYER_L2CAP, L2CAP_RTX_TIMEOUT);
+ }
+ return retval;
}
=20
/* params determines how we would like to receive data */
@@ -1662,7 +1666,7 @@
=20
} else if (con->current_state =3D=3D CLOSED) {
l2ca_config_cfm(con, CONF_REJ);
- return -1;
+ return -MSGCODE(MSG_LAYER_L2CAP, L2CAP_NO_CONNECTION);
} else if (con->current_state =3D=3D OPEN) {
DSYS("l2ca_config_req: state OPEN, reconfiguration !\n");
=20
@@ -1683,14 +1687,14 @@
} else {
D_ERR(__FUNCTION__ ": invalid state\n");
PRINTSTATE(con);
- return -1;
+ return -MSGCODE(MSG_LAYER_L2CAP, L2CAP_INVALID_STATE);
}
}
=20
s32=20
l2ca_disconnect_req(l2cap_con *con)
{
- s32 result =3D -1;
+ s32 retval =3D 0;
u16 tmp_hdl =3D con->hci_hdl;
=20
if (PARANOIA_CHECKCON(con)) {
@@ -1704,7 +1708,14 @@
ENTERSTATE(con, W4_L2CAP_DISCONNECT_RSP);
PRINTSTATE(con);
do {
- result =3D l2cap_disconnect_req(con);
+ retval =3D l2cap_disconnect_req(con);
+ if(retval < 0) {
+ /* This will result in a timeout and we need to try again
+ as the error is a result of insufficent space in our
+ memorypool and we try again after a timeout */
+ D_ERR(__FUNCTION__ ": Failed (status %d)\n", retval);
+ }
+=09=09=09
l2ca_wait(__FUNCTION__, con);
PRINTSTATE(con);
=20=09=09=09
@@ -1712,18 +1723,18 @@
} else {
D_ERR(__FUNCTION__ ": Invalid state!\n");
PRINTSTATE(con);
- return -1;=20=20=20=20
+ return -MSGCODE(MSG_LAYER_L2CAP, L2CAP_INVALID_STATE);=20=20=20=20
}
=20
- result =3D con->c_result;
-=09
if(con->c_status !=3D CSTATUS_MAX_NO_RTX) {
if (con->current_state =3D=3D CLOSED) {=09
/* remove l2cap connection */
delete_con(con);
} else {
- D_ERR("L2CAP Disconnect failed\n");
+ /* FIXME: If we reach here, should we delete the connection? */
+ D_ERR(__FUNCTION__ ": Failed (Connection not closed)");
PRINTSTATE(con);
+ retval =3D -MSGCODE(MSG_LAYER_L2CAP, L2CAP_FAILED);
}
}
=20=09
@@ -1738,7 +1749,7 @@
lp_disconnect(tmp_hdl);
}
=20
- return result;
+ return retval;
}
=20
=20
@@ -2060,8 +2071,8 @@
con->remote_cid);
=20=09
if (con->current_state !=3D W4_L2CAP_CONNECT_RSP) {
- D_ERR(__FUNCTION__ ": Invalid state !!!\n");
- return -1;
+ D_ERR(__FUNCTION__ ": Invalid state\n");
+ return -MSGCODE(MSG_LAYER_L2CAP, L2CAP_INVALID_STATE);
}
=20
payload_len =3D SIGCMD_HDRSIZE + CON_REQSIZE; /*2 x 4*/
@@ -2085,7 +2096,8 @@
=20
/* Don't increment ID if retransmission */
if (con->timer.rtx_no =3D=3D 0)
- cmd->id =3D set_id(con); /* Sets sig_id_sent in l2cap_con =
*/
+ cmd->id =3D set_id(con); /* S
+ets sig_id_sent in l2cap_con */
else
DSYS("RTX, use same ID\n");
=20
@@ -2722,7 +2734,7 @@
psm2str(con->psm));
D_ERR(__FUNCTION__ ": Flushing this buffer\n");
tx->flushed =3D 1;
- return -1;
+ return -MSGCODE(MSG_LAYER_L2CAP, L2CAP_EXCEED_REMOTE_MTU);
}
=20
/* Only send on an OPEN channel */
@@ -2730,7 +2742,7 @@
D_ERR(__FUNCTION__ ": not in open state\n");
D_ERR(__FUNCTION__ ": Flushing this buffer\n");
tx->flushed =3D 1;
- return -1;
+ return -MSGCODE(MSG_LAYER_L2CAP, L2CAP_INVALID_STATE);
}
=20
l2cap_buf =3D (l2cap_tx_buf *)(tx->data);
@@ -2846,7 +2858,7 @@
s32 l2ca_ping(BD_ADDR bd, u8 *opt_data, u16 len)
{
l2cap_con *con;
- s32 i ;
+ s32 i, retval =3D 0;
u8 rev_bd[6];
=20
D_XMIT("Sending ping\n");
@@ -2877,7 +2889,11 @@
lp_connect_cfm arrives */
con->c_flags |=3D FLAG_RETURNNOW;
=20
- lp_connect_req(con->remote_bd);
+ retval =3D lp_connect_req(con->remote_bd);
+ if(retval < 0) {
+ D_ERR(__FUNCTION__ ": lp_connect_req failed (status %d)\n", retval);
+ return retval;
+ }
=20
/* wait here until we received a lp_connect_cfm */
l2ca_wait(__FUNCTION__ ": wait baseband", con);
@@ -2886,9 +2902,10 @@
/* check status */
D_XMIT("Now we got baseband, send echo req !\n");
} else {
- D_ERR(__FUNCTION__ ": Ping failed !\n");
+ D_ERR(__FUNCTION__ ": lp_connect_req failed, no connection (status %d)\=
n", con->c_status);
+ retval =3D -MSGCODE(MSG_LAYER_HCI, con->c_status);
delete_con(con);
- return -1;
+ return retval;
}
}
=20
@@ -2910,10 +2927,10 @@
=20
if (con->c_status =3D=3D CSTATUS_MAX_NO_RTX) {
/* max number reached, try to disconnect */
- l2ca_disconnect_req(con);
+ retval =3D l2ca_disconnect_req(con);
}
=20
- return con->c_result;
+ return retval;
}
=20
s32 l2ca_getinfo(BD_ADDR bd, u16 infotype)
@@ -2921,6 +2938,7 @@
l2cap_con *con;
s32 i ;
u8 rev_bd[6];
+ s32 retval =3D 0;
=20=09
D_XMIT("Sending GetInfo : type 0x%x\n", infotype);
=20
@@ -2949,7 +2967,12 @@
lp_connect_cfm arrives */
con->c_flags |=3D FLAG_RETURNNOW;
=20
- lp_connect_req(con->remote_bd);
+ retval =3D lp_connect_req(con->remote_bd);
+ if(retval < 0) {
+ D_ERR(__FUNCTION__, ": lp_connect_req failed (status %d)\n", retval);
+ delete_con(con);
+ return retval;
+ }
=20
/* wait here until we received a lp_connect_cfm */
l2ca_wait(__FUNCTION__ ": wait baseband", con);
@@ -2958,10 +2981,9 @@
/* check status */
D_XMIT("Now we got baseband, send info req !\n");
} else {
- D_ERR(__FUNCTION__": GetInfo failed ! [cstatus %d]\n",=20
- con->c_status);
+ D_ERR(__FUNCTION__ ": lp_connect_req failed, no connection (status %d)\=
n", con->c_status);
delete_con(con);
- return -1;
+ return -MSGCODE(MSG_LAYER_HCI, con->c_status);
}
}
=20
@@ -2972,13 +2994,21 @@
/* leave loop when either status failed or success */
while (con->c_status =3D=3D CSTATUS_RTX_TIMEOUT) {
D_XMIT("Sending info req...\n");
- l2cap_info_req(con, infotype);=09
+ retval =3D l2cap_info_req(con, infotype);
+ if(retval < 0) {
+ D_ERR(__FUNCTION__ ": l2cap_info_req failed (status %d)\n", retval);
+ /* Timeout and then try again */
+ }
=20
/* wait until we received a response or after timeout */
l2ca_wait(__FUNCTION__ ": wait echo resp", con);
}
=20
- return con->c_result;
+ if (con->c_status =3D=3D CSTATUS_MAX_NO_RTX && !retval) {
+ retval =3D -MSGCODE(MSG_LAYER_L2CAP, L2CAP_RTX_TIMEOUT);
+ }
+
+ return retval;
}
=20
/*******************************************************************/
--- rfcomm.c 2001/10/05 12:06:43 1.122
+++ rfcomm.c 2001/10/10 14:58:18 1.123
@@ -1325,7 +1325,7 @@
u8 dlci;
rfcomm_con *rfcomm;
=20
- line =3D GET_RFCOMMLINE(con_id);
+ line =3D GET_LINE(con_id);
dlci =3D GET_RFCOMMDLCI(con_id);
=20=09
if (dlci =3D=3D 0) {
--- test.c 2001/09/28 14:35:38 1.28
+++ test.c 2001/10/10 14:58:18 1.29
@@ -184,12 +184,7 @@
test_connect_psmreq(BD_ADDR bd, u16 psm)
{
D_STATE("test_connect_req on psm 0x%x\n", psm);
-
- if (l2ca_connect_req(bd, psm)) {
- D_ERR(" tcs_connect_req: l2ca_connect_req failed\n");
- return -1;=20
- }
- return 0;
+ return l2ca_connect_req(bd, psm);
}
=20
static void
|