|
From: Gordon M. <gm...@us...> - 2001-03-07 20:07:43
|
The following file was modified in linux/drivers/char/bluetooth:
Name Old version New version Comment
---- ----------- ----------- -------
rfcomm.c 1.92 1.93=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
--Made big-endian changes to rfcomm.c.
The diff of the modified file(s):
--- rfcomm.c 2001/03/05 15:52:52 1.92
+++ rfcomm.c 2001/03/07 20:09:24 1.93
@@ -157,12 +157,43 @@
#define RTR 0x8
#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))
+
+#ifdef BTD_USERSTACK
+
+# include <asm/byteorder.h>
+# ifdef __LITTLE_ENDIAN
+# define cpu_to_le16(x) (x)
+# define cpu_to_le32(x) (x)
+# define cpu_to_be16(x) htons((x))
+# define cpu_to_be32(x) htonl((x))
+# else
+# define cpu_to_be16(x) (x)
+# define cpu_to_be32(x) (x)
+ extern inline __u16 cpu_to_le16(__u16 x) { return (x<<8) | (x>>8);}
+ extern inline __u32 cpu_to_le32(__u32 x) { return((x>>24) |
+ ((x>>8)&0xff00) | ((x<<8)&0xff0000) | (x<<24));}
+# endif
+
+# define le16_to_cpu(x) cpu_to_le16(x)
+# define le32_to_cpu(x) cpu_to_le32(x)
+# define be16_to_cpu(x) cpu_to_be16(x)
+# define be32_to_cpu(x) cpu_to_be32(x)
+
+#endif
+
/****************** TYPE DEFINITION SECTION ******************************=
***/
=20
/* Typedefinitions of stuctures used for creating and parsing packets, for=
a
further description of the structures please se the bluetooth core
specification part F:1 and the ETSI TS 07.10 specification */
=20
+#include <asm/byteorder.h>
+#ifdef __LITTLE_ENDIAN_BITFIELD
+
typedef struct address_field{
u8 ea:1;
u8 cr:1;
@@ -361,6 +392,150 @@
u8 fcs;
} __attribute__ ((packed)) nsc_msg;
=20
+#elif defined(__BIG_ENDIAN_BITFIELD)
+
+typedef struct address_field{
+ u8 server_chn:5;
+ u8 d:1;
+ u8 cr:1;
+ u8 ea:1;
+} __attribute__ ((packed)) address_field;
+
+typedef struct short_length{
+ u8 len:7;
+ u8 ea:1;
+} __attribute__ ((packed)) short_length;
+
+typedef union long_length {
+ struct bits {
+ unsigned short len:15;
+ u8 ea:1;
+ } bits;
+ u16 val;
+} __attribute__ ((packed)) long_length;
+
+typedef struct short_frame_head{=20
+ address_field addr;
+ u8 control;
+ short_length length;
+} __attribute__ ((packed)) short_frame_head;
+
+typedef struct short_frame{
+ short_frame_head h;
+ u8 data[0];
+} __attribute__ ((packed)) short_frame;
+
+typedef struct long_frame_head{=20
+ address_field addr;
+ u8 control;
+ long_length length;
+ u8 data[0];
+} __attribute__ ((packed)) long_frame_head;
+
+typedef struct long_frame{=20
+ long_frame_head h;
+ u8 data[0];
+} __attribute__ ((packed)) long_frame;
+
+typedef struct mcc_type{=20
+ u8 type:6;
+ u8 cr:1;
+ u8 ea:1;
+} __attribute__ ((packed)) mcc_type;
+
+typedef struct mcc_short_frame_head{=20
+ mcc_type type;
+ short_length length;
+ u8 value[0];
+} __attribute__ ((packed)) mcc_short_frame_head;
+
+typedef struct mcc_short_frame{=20
+ mcc_short_frame_head h;
+ u8 value[0];
+} __attribute__ ((packed)) mcc_short_frame;
+
+typedef struct mcc_long_frame_head{=20
+ mcc_type type;
+ long_length length;
+ u8 value[0];
+} __attribute__ ((packed)) mcc_long_frame_head;
+
+typedef struct mcc_long_frame{=20
+ mcc_long_frame_head h;
+ u8 value[0];
+} __attribute__ ((packed)) mcc_long_frame;
+
+typedef struct v24_signals{=20
+ u8 dv:1;
+ u8 ic:1;
+ u8 reserved:2;
+ u8 rtr:1;
+ u8 rtc:1;
+ u8 fc:1;
+ u8 ea:1;
+} __attribute__ ((packed)) v24_sigs;
+
+typedef struct brk_sigs{=20
+ u8 len:4;
+ u8 b3:1;
+ u8 b2:1;
+ u8 b1:1;
+ u8 ea:1;
+} __attribute__ ((packed)) brk_sigs;
+
+typedef struct msc_msg{=20
+ short_frame_head s_head;
+ mcc_short_frame_head mcc_s_head;
+ address_field dlci;
+ u8 v24_sigs;
+ //brk_sigs break_signals;
+ u8 fcs;
+} __attribute__ ((packed)) msc_msg;
+
+typedef struct rpn_msg{=20
+ short_frame_head s_head;
+ mcc_short_frame_head mcc_s_head;
+ address_field dlci;
+ rpn_values rpn_val;
+ u8 fcs;
+} __attribute__ ((packed)) rpn_msg;
+
+typedef struct rls_msg{=20
+ short_frame_head s_head;
+ mcc_short_frame_head mcc_s_head;
+ address_field dlci;
+ u8 res:4;
+ u8 error:4;
+ u8 fcs;
+} __attribute__ ((packed)) rls_msg;
+
+typedef struct pn_msg{=20
+ short_frame_head s_head;
+ mcc_short_frame_head mcc_s_head;
+ u8 res1:2;
+ u8 dlci:6;
+ u8 credit_flow:4;
+ u8 frame_type:4;
+ u8 res2:2;
+ u8 prior:6;
+ u8 ack_timer;
+ u32 frame_size:16;
+ u8 max_nbrof_retrans;
+ u8 credits;
+ u8 fcs;
+} __attribute__ ((packed)) pn_msg;
+
+typedef struct nsc_msg{=20
+ short_frame_head s_head;
+ mcc_short_frame_head mcc_s_head;
+ mcc_type command_type;
+ u8 fcs;
+} __attribute__ ((packed)) nsc_msg;
+
+#else /* __XXX_ENDIAN */
+#error Processor endianness unknown!
+#endif /* __XXX_ENDIAN */
+
/****************** LOCAL FUNCTION DECLARATION SECTION *******************=
***/
=20
static void process_mcc(u8* data, u32 len, rfcomm_con *rfcomm, s32 long_pk=
t);
@@ -1061,6 +1236,7 @@
packet */=20
D_REC(FNC"Long UIH packet received\n");
long_pkt =3D (long_frame*) data;
+ swap_long_frame(long_pkt);
uih_len =3D long_pkt->h.length.bits.len;
uih_data_start =3D long_pkt->h.data;
D_REC(FNC"long packet length %d\n",
@@ -1256,6 +1432,7 @@
if ((mcc_short_pkt->h.length.ea) =3D=3D 0) {
mcc_long_frame *mcc_long_pkt;
mcc_long_pkt =3D (mcc_long_frame*) mcc_short_pkt;
+ swap_mcc_long_frame(mcc_long_pkt);
rfcomm_test_msg(rfcomm, mcc_long_pkt->value,
mcc_long_pkt->h.length.bits.len,
MCC_RSP);
@@ -1363,6 +1540,7 @@
case PN: /*DLC parameter negotiation*/
{
pn_msg *pn_pkt =3D (pn_msg*) data;
+ swap_pn_msg(pn_pkt);
D_CTRL(FNC"Received DLC parameter negotiation, PN\n");
if (longpkt) {
/* UNPLUGGED Ericsson using 2 bytes length field */
@@ -1648,6 +1826,7 @@
set_uih_hdr((void*) l_pkt, dlci, len, rfcomm->initiator);
memcpy(l_pkt->data, data, len);
l_pkt->data[len] =3D crc_calc((u8*) l_pkt, SHORT_CRC_CHECK);
+ swap_long_frame(l_pkt);
} else {
short_frame *s_pkt;
=20
@@ -1746,6 +1925,8 @@
mcc_pkt->h.type.type =3D TEST;
mcc_pkt->h.length.bits.ea =3D EA;
mcc_pkt->h.length.bits.len =3D len;
+ swap_long_frame(uih_pkt);
+ swap_mcc_long_frame(mcc_pkt);
memcpy(mcc_pkt->value,test_pattern,len);
} else if (len > (SHORT_PAYLOAD_SIZE-sizeof(mcc_short_frame))) {
long_frame *uih_pkt;
@@ -1777,6 +1958,7 @@
mcc_pkt->h.type.type =3D TEST;
mcc_pkt->h.length.ea =3D EA;
mcc_pkt->h. length.len =3D len;
+ swap_long_frame(uih_pkt);
memcpy(mcc_pkt->value,test_pattern,len);
} else {
short_frame *uih_pkt;
@@ -2033,6 +2215,8 @@
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
|