|
From: Mattias A. <mat...@us...> - 2001-04-25 17:39:14
|
The following file was modified in linux/drivers/char/bluetooth:
Name Old version New version Comment
---- ----------- ----------- -------
bluetooth.c 1.171 1.172=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* added check when unregistering tty in bt_close. The closing pid
must be same as the one that opened tty.
* don't sleep in bt_connect/bt_disconnect if request failed (releases=20
blocks immediately)
* added error code when trying to disconnect in not connected state.
* changed some debug
The diff of the modified file(s):
--- bluetooth.c 2001/04/20 14:33:07 1.171
+++ bluetooth.c 2001/04/25 17:39:13 1.172
@@ -81,6 +81,7 @@
#include <linux/bluetooth/tcs.h>
#include <linux/bluetooth/sdp.h>
#include <linux/bluetooth/sec_client.h>
+#include <linux/bluetooth/bt_errno.h>
=20
#ifdef CONFIG_BLUETOOTH_USE_TCI
#include <linux/bluetooth/tci.h>
@@ -459,23 +460,24 @@
bt_chars_in_buffer(struct tty_struct *tty)
{
u16 n =3D buf_byte_count();
+ /* what if multiple pppd are running and one pppd=20
+ ends, then this won't be zero.... */
+
+ /* fixme -- we must find number bytes belonging to=20
+ this line */
=20
BT_DRIVER("bt_chars_in_buffer : %d\n", n);=20=20
return n;
}
=20
-/* Must flush the buffer, otherwise chars_in_buffer returns nonzero
- and pppd hangs on the exit while doing the set line disc ioctl */
static void
bt_flush_buffer(struct tty_struct *tty)
{
/* Clearing the buffers here may lead to them being cleared before
they are sent when diconnecting a connection */
+ BT_DRIVER("bt_flush_buffer, ignored\n");
#if 0
bt_tx_buf* tx_buf;
-
- BT_DRIVER("bt_flush_buffer\n");
-=09
while ((tx_buf =3D get_bt_buf())) {
unsubscribe_bt_buf(tx_buf);
}
@@ -1077,6 +1079,7 @@
=20=09=09
BT_DRIVER("BTSETMSSWITCH : %d\n", enable);
hci_force_msswitch(enable);
+ return 0;
}
=20=09=09
default:=09=09
@@ -1661,12 +1664,18 @@
BT_DRIVER(FNC"Connecting srv ch %d on line %d\n",
srv_ch, line);
BT_DATADUMP("Remote BD : ", bd_addr, 6);
- rfcomm_connect_req(bd_addr, srv_ch, line);=09=09
=20
+ if (rfcomm_connect_req(bd_addr, srv_ch, line) < 0){
+ BT_DRIVER("bt_connect failed\n");
+ return bt_ctrl.session[line].connect_status;
+ }
+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+ /* sleep if not yet connected */
+ if (bt_ctrl.session[line].connect_status =3D=3D -1) {
start_wq_timer(&bt_timer, BT_CON_TIMEOUT,=20
&bt_ctrl.connect_wq[line]);
-
interruptible_sleep_on(&bt_ctrl.connect_wq[line]);
+ }
return bt_ctrl.session[line].connect_status;
}
break;
@@ -1913,15 +1922,28 @@
=20
bt_ctrl.session[line].disconnect_status =3D -1;
=20
- start_wq_timer(&bt_timer, BT_CON_TIMEOUT, &bt_ctrl.connect_wq[line]);
+ /* check if we have a connection */
+ if ((SESSIONSTATE(line) =3D=3D BT_LOWERCONNECTED) ||=20
+ (SESSIONSTATE(line) =3D=3D BT_ACTIVE))
+ {=20=20=20=20=20=20=20=20=20=20
+ if (rfcomm_disconnect_req(GET_RFCOMMLINE(con_id)) < 0) {
+ BT_DRIVER("bt_disconnect failed\n");
+ return bt_ctrl.session[line].disconnect_status;
+ }
=20
- rfcomm_disconnect_req(GET_RFCOMMLINE(con_id));
+ /* fixme -- remove timers, useless when rfcomm blocks ? */
=20
- /* Only sleep if no reply yet, use connect wq for=20
- disconnect aswell */
+ /* 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,=
=20
+ BT_NOTCONNECTE=
D);
=20=09
return bt_ctrl.session[line].disconnect_status;
}
@@ -2380,6 +2402,7 @@
{
/* don't touch con/disc status here */
bt_ctrl.session[line].upper_tty =3D NULL;
+ bt_ctrl.session[line].pid =3D 0;
bt_ctrl.session[line].rfcomm =3D NULL;
bt_ctrl.session[line].dlci =3D 0;=20
bt_ctrl.session[line].state =3D BT_INACTIVE;
@@ -2553,7 +2576,7 @@
{
s32 line =3D GET_TTYLINE(tty);
=20=20
- DSYS("Registering tty on line %d\n", line);
+ BT_DRIVER("Registering tty on line %d\n", line);
=20=09
/* Allow multiple open for ttyBTC */
if (line =3D=3D BT_NBR_PORTS-BT_NBR_CTRLPORTS) {
@@ -2575,6 +2598,7 @@
(SESSIONSTATE(line) =3D=3D BT_INACTIVE)) {
NBR_UPPER++;
bt_ctrl.session[line].upper_tty =3D tty;
+ bt_ctrl.session[line].pid =3D current->pid;
tty->driver_data =3D &bt_ctrl.session[line];
=20
if (SESSIONSTATE(line) =3D=3D BT_INACTIVE)
@@ -2597,11 +2621,18 @@
s32
bt_unregister_tty(struct tty_struct *tty, s32 line)
{
- DSYS("Unregistering tty on line %d\n", line);
+ BT_DRIVER("Unregistering tty on line %d\n", line);
=20
if (line =3D=3D BT_NBR_PORTS-BT_NBR_CTRLPORTS) {
if (--NBR_CTRL_FDS !=3D 0)
return 0; /* still more open fd:s on ttyBTC */
+ }
+
+ /* Check that the pid closing is the one that opened the tty */
+ if (current->pid !=3D bt_ctrl.session[line].pid)
+ {
+ BT_DRIVER(__FUNCTION__" invalid pid\n");
+ return -1;
}
=20
/* Check that it is ok to close this line ...=20
|