|
From: Peter K. <pk...@us...> - 2001-10-16 14:59:45
|
The following file was modified in linux/drivers/char/bluetooth:
Name Old version New version Comment
---- ----------- ----------- -------
rfcomm.c 1.125 1.126=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Replaced swap_pn_msg() with use of le16_to_cpuu(), and put_unaligned()
and cpu_to_le16() to make sure it works on unaligned addresses (thanks
to Alain Paschoud for pointing this out).
The diff of the modified file(s):
--- rfcomm.c 2001/10/16 09:30:12 1.125
+++ rfcomm.c 2001/10/16 14:59:29 1.126
@@ -52,6 +52,8 @@
#include <linux/string.h>
#include <linux/sched.h>
=20
+#include <asm/unaligned.h>
+
#include <linux/bluetooth/rfcomm.h>
#include <linux/bluetooth/rfcomm_sec.h>
#include <linux/bluetooth/btmem.h>
@@ -145,25 +147,24 @@
#define UIH 0xef
=20
/* The values in the type field in a multiplexer command packet */
-#define TEST 0x8
+#define TEST 0x08
#define FCON 0x28
#define FCOFF 0x18
#define MSC 0x38
#define RPN 0x24
#define RLS 0x14
#define PN 0x20
-#define NSC 0x4
+#define NSC 0x04
=20
/* Define of some V.24 signals modem control signals in RFCOMM */
-#define FC 0x2
-#define RTC 0x4
-#define RTR 0x8
+#define FC 0x02
+#define RTC 0x04
+#define RTR 0x08
#define DV 0x80
=20
/* endian-swapping macros for structs */
#define swap_long_frame(x) ((x)->h.length.val =3D le16_to_cpu((x)->h.lengt=
h.val))
#define swap_mcc_long_frame(x) (swap_long_frame(x))
-#define swap_pn_msg(x) ((x)->frame_size =3D le16_to_cpu((x)->frame_size))
=20
#define RFCOMM_CON_TIMEOUT (5*HZ)
=20
@@ -190,8 +191,8 @@
=20
typedef union long_length {
struct bits {
- u8 ea:1;
- unsigned short len:15;
+ u16 ea:1;
+ u16 len:15;
} __attribute__ ((packed)) bits;
u16 val;
} __attribute__ ((packed)) long_length;
@@ -337,8 +338,8 @@
=20
typedef union long_length {
struct bits {
- unsigned short len:15;
- u8 ea:1;
+ u16 len:15;
+ u16 ea:1;
} __attribute__ ((packed)) bits;
u16 val;
} __attribute__ ((packed)) long_length;
@@ -1568,17 +1569,19 @@
}
break;
}
+
case PN: /*DLC parameter negotiation*/
{
- pn_msg *pn_pkt =3D (pn_msg*) data;
+ pn_msg *pn_pkt;
+
D_CTRL(FNC"Received DLC parameter negotiation, PN\n");
if (longpkt) {
/* If a long length field is used, then move the
payload pointer one byte ahead */
data++;
- pn_pkt =3D (pn_msg*) data;
}=20=20
- swap_pn_msg(pn_pkt);
+ pn_pkt =3D (pn_msg*) data;
+
if (pn_pkt->mcc_s_head.type.cr =3D=3D MCC_CMD) {
u8 tmp_dlci;
u16 frame_size;
@@ -1588,7 +1591,7 @@
back a response */
=20
tmp_dlci =3D pn_pkt->dlci;
- frame_size =3D pn_pkt->frame_size;
+ frame_size =3D le16_to_cpuu(&pn_pkt->frame_size);
=20
frame_size =3D MIN(frame_size, rfcomm->l2cap->local_mtu - RFCOMM_MAX_HD=
R_SIZE);
credit =3D pn_pkt->credit_flow;
@@ -1615,11 +1618,11 @@
u8 tmp_dlci;
tmp_dlci =3D pn_pkt->dlci;
D_CTRL(FNC"received PN response with:\n");
- D_CTRL(FNC"Frame size:%d\n",pn_pkt->frame_size);
+ D_CTRL(FNC"Frame size:%d\n", le16_to_cpuu(&pn_pkt->frame_size));
D_CTRL(FNC"credit_flow:%d\n", pn_pkt->credit_flow);
D_CTRL(FNC"credits:%d\n", pn_pkt->credits);
=20=09=09=09
- rfcomm->dlci[tmp_dlci].mtu =3D pn_pkt->frame_size;
+ rfcomm->dlci[tmp_dlci].mtu =3D le16_to_cpuu(&pn_pkt->frame_size);
=20=09=09=09
if (pn_pkt->credit_flow =3D=3D 0xe) {
DSYS(FNC"Credit flow control used\n");
@@ -1634,10 +1637,9 @@
if (rfcomm->dlci[tmp_dlci].state =3D=3D NEGOTIATING) {
send_sabm(rfcomm, tmp_dlci);
}
-
- }
}
break;
+ }
=20=20=20=20=20
case NSC: /*Non supported command resonse*/
D_CTRL(FNC"Received Non supported command response\n");
@@ -1650,7 +1652,6 @@
=20=20=20=20=20
break;
}
-
}
=20
=20
@@ -2247,8 +2248,7 @@
D_CTRL("send_pn_msg: DLCI 0x%02x, prior:0x%02x, frame_size:%d, credit_flo=
w:%x, credits:%d, cr:%x\n",
dlci, prior, frame_size, credit_flow, credits, cr);
=20
- /* FIXME: Can't use structures here, sizeof doesn't work... */
- rfcomm_frame_size =3D 14; //sizeof(pn_msg);
+ rfcomm_frame_size =3D sizeof *pn_pkt;
tx_buf =3D subscribe_bt_buf(sizeof(rfcomm_tx_buf) + rfcomm_frame_size);
=20
if (!tx_buf) {
@@ -2280,12 +2280,10 @@
pn_pkt->credit_flow =3D credit_flow;
pn_pkt->prior =3D prior;
pn_pkt->ack_timer =3D 0;
- pn_pkt->frame_size =3D frame_size;
+ put_unaligned(cpu_to_le16(frame_size), &pn_pkt->frame_size);
pn_pkt->credits =3D credits;
pn_pkt->max_nbrof_retrans =3D 0;
=20=20=20
- swap_pn_msg(pn_pkt);
-
return l2cap_send_data(tx_buf,rfcomm->l2cap);
}
=20
|