|
From: Peter K. <pk...@us...> - 2001-09-21 12:51:37
|
The following files were modified in linux/drivers/char/bluetooth:
Name Old version New version Comment
---- ----------- ----------- -------
hci.c 1.180 1.181=20=20=20=20=20=20=20=20=20=20=20
l2cap.c 1.118 1.119=20=20=20=20=20=20=20=20=20=20=20
sdp.c 1.79 1.80=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Replaces CHAR2INTx() macros with get_unaligned() and leXX_to_cpu().
The diff of the modified file(s):
--- hci.c 2001/09/12 12:42:19 1.180
+++ hci.c 2001/09/21 12:51:06 1.181
@@ -61,11 +61,16 @@
#include <linux/interrupt.h>
#include <linux/bluetooth/sec_client.h>
#include <asm/io.h>
+#include <asm/byteorder.h>
+#include <asm/unaligned.h>
=20
#else /* user mode */
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+
+#include <asm/unaligned.h>
+
#include "include/bluetooth.h"
#include "include/hci.h"
#include "include/hci_internal.h"
@@ -79,23 +84,11 @@
#endif
=20
/****************** CONSTANT AND MACRO SECTION ***************************=
***/
-
-
-#define SET_UART(x1,x2,x3,x4) (((((x4)&7)<<5) + (((x3)&1)<<4) + \
- (((x2)&1)<<3) + (((x1)&1)<<2)) & 0xfc)
-
-#define SET_BAUD_RATE(x) (27648000/(x))
-
-
-#define SET_PROTOCOL_MODE(x1,x2,x3,x4,x5,x6) ((((x6)&7)<<5) + (((x5)&1)<<4=
) + \
- (((x4)&1)<<3) + (((x3)&1)<<2) + \
- (((x2)&1)<<1) + ((x1)&1))
-
=20
-#define MAKE_ACL_HDR(hci_hdl,pb,bc,len) (cpu_to_le32(((len & 0xffff) << 16=
) + \
- ((bc & 0x3) << 14) + \
- ((pb & 0x3) << 12) + \
- (hci_hdl & 0xfff)))
+/* These two macros are the same as le16_to_cpup() and le32_to_cpup()
+ only that they work with unaligned addresses */
+#define le16_to_cpuu(addr) (le16_to_cpu(get_unaligned((u16 *)addr)))
+#define le32_to_cpuu(addr) (le32_to_cpu(get_unaligned((u32 *)addr)))
=20
#define ACL_LINK 1
#define SCO_LINK 0
@@ -140,7 +133,6 @@
#define USE_NCPTIMER=20
#define NCP_TIMEOUT (2*HZ)
=20
-
/****************** TYPE DEFINITION SECTION ******************************=
***/
=20
/* cmd_t and cmd_buf are structures used to handle the queue of commands
@@ -156,9 +148,9 @@
u32 next_to_send; /* index in cmd_buf */
u8 count;
cmd_t buf[NBR_CMD_BUFS];
-} cmd_buf;
+};
=20
-/* This is the states the state machine in hci_receive_data can be in */
+/* These are the states the state machine in hci_receive_data can be in */
enum states{WAIT_FOR_PACKET_TYPE, WAIT_FOR_EVENT_TYPE, WAIT_FOR_EVENT_LENG=
TH,
WAIT_FOR_EVENT_PARAM, WAIT_FOR_ACL_HDR, WAIT_FOR_ACL_DATA,=20
WAIT_FOR_SCO_HDR, WAIT_FOR_SCO_DATA, WAIT_FOR_TIMEOUT};
@@ -170,11 +162,11 @@
description of the HCI event packet. */
=20
typedef struct event_struct {
- u32 pkt_type:8;
- u32 event_type:8;
- u32 len:8;
+ u8 pkt_type;
+ u8 event_type;
+ u8 len;
u8 data[0];
-} event_struct;
+} __attribute__ ((packed)) event_struct;
#endif
=20
/****************** LOCAL FUNCTION DECLARATION SECTION *******************=
***/
@@ -187,6 +179,7 @@
static hci_in_buffer* get_free_inbuffer(void);
static u32 send_acl_packet(bt_tx_buf *tx_buf);
static void set_acl_hdr(u8 *data, u32 len, u8 pb, u8 bc, u32 hci_hdl);
+static u16 hci_handle(void *data);
static cmd_t* get_next_cmd(void);=20
static s32 insert_cmd(u8* cmd, u8 len);=20
static void init_cmd_buf(void);
@@ -261,6 +254,8 @@
=20
/****************** LOCAL VARIABLE DECLARATION SECTION *******************=
***/
=20
+static struct cmd_buf cmd_buf;
+
/* Struct used for sending command packets */
cmd_pkt c_pkt;
=20
@@ -346,7 +341,6 @@
* parse_sco_packet or the parse_event_packet, depending on the packet type
*/
=20
-
void
hci_receive_data(u8* data, u32 count)
{
@@ -473,10 +467,11 @@
buf +=3D c;
count -=3D c;
if (tmp_pos =3D=3D ACL_HDR_LEN) {
- hci_hdl =3D CHAR2INT12(hdr[1],hdr[0]);
- pb_flag =3D (((u32) hdr[1]) & 0x30) >> 4;
- bc_flag =3D (((u32) hdr[1]) & 0xc0) >> 6;
- data_len =3D CHAR2INT16(hdr[3],hdr[2]);
+ u32 tmp_hdr =3D le32_to_cpuu(hdr);
+ hci_hdl =3D GET_BITS(tmp_hdr, 0, 12);
+ pb_flag =3D GET_BITS(tmp_hdr, 12, 2);
+ bc_flag =3D GET_BITS(tmp_hdr, 14, 2);
+ data_len =3D GET_BITS(tmp_hdr, 16, 16);
=20
/* Check the length to make sure we won't=20
overrun in_buf->buf_ptr in a memcpy later.
@@ -562,7 +557,7 @@
buf +=3D c;
count -=3D c;
if (tmp_pos =3D=3D SCO_HDR_LEN) {
- hci_hdl =3D CHAR2INT12(hdr[1],hdr[0]);
+ hci_hdl =3D hci_handle(hdr);
data_len =3D hdr[2];
tmp_pos =3D 0;
state =3D WAIT_FOR_SCO_DATA;
@@ -606,8 +601,8 @@
while (count > 0) {
event_type =3D tmp_buf[0];
event_len =3D tmp_buf[1];
- tmp_buf +=3D 2;
- count -=3D 2;
+ tmp_buf +=3D EVENT_HDR_LEN;
+ count -=3D EVENT_HDR_LEN;
=20
D_REC(__FUNCTION__ ": Received event 0x%02x with len:%d\n", event_type, =
event_len);
=20=09=09
@@ -630,14 +625,17 @@
tmp_buf =3D data;
=20
while (count > 0) {
- /* Parse the HCI header */
- hci_hdl =3D CHAR2INT12(tmp_buf[1],tmp_buf[0]);
- pb_flag =3D (((u32) tmp_buf[1]) & 0x30) >> 4;
- bc_flag =3D (((u32) tmp_buf[1]) & 0xc0) >> 6;
- data_len =3D CHAR2INT16(tmp_buf[3],tmp_buf[2]);
- tmp_buf +=3D 4;
- count -=3D 4;
+ u32 tmp_hdr =3D le32_to_cpuu(tmp_buf);
=20=09=09
+ /* Parse the ACL header */
+ hci_hdl =3D GET_BITS(tmp_hdr, 0, 12);
+ pb_flag =3D GET_BITS(tmp_hdr, 12, 2);
+ bc_flag =3D GET_BITS(tmp_hdr, 14, 2);
+ data_len =3D GET_BITS(tmp_hdr, 16, 16);
+
+ tmp_buf +=3D ACL_HDR_LEN;
+ count -=3D ACL_HDR_LEN;
+=09=09
/* Check the length to make sure we won't=20
overrun in_buf->buf_ptr in a memcpy later.
--gmcnutt
@@ -727,7 +725,7 @@
that have been sent */
=20
for (i =3D 0; i < 4 * nbr_of_hdl; i +=3D 4) {
- hci_ctrl.hc_buf.acl_num +=3D CHAR2INT16(pkt[i+3], pkt[i+2]);
+ hci_ctrl.hc_buf.acl_num +=3D le16_to_cpuu(&pkt[i+2]);
}
=20=09
D_QUEUE("<NCP:%d>\n", hci_ctrl.hc_buf.acl_num);
@@ -824,7 +822,7 @@
get_err_msg(buf[0]));
=20
link_type =3D buf[9];
- hci_hdl =3D CHAR2INT12(buf[2], buf[1]);
+ hci_hdl =3D hci_handle(&buf[1]);
test_hci_hdl =3D hci_hdl;
=20
if (link_type =3D=3D ACL_LINK) {
@@ -898,7 +896,7 @@
release_cmd_timer();
wake_up_interruptible(&hci_wq);
=20
- if (lp_disconnect_ind(CHAR2INT12(buf[2], buf[1])))
+ if (lp_disconnect_ind(hci_handle(&buf[1])))
if (hci_ctrl.nbr_of_connections > 0) {
hci_ctrl.nbr_of_connections--;
hci_update_load_factor();
@@ -909,7 +907,7 @@
connections we can acl_num by reading the buffersizes again,
but this will not work in a multipoint connection. */
=20
- reset_hci_con_bd(CHAR2INT12(buf[2], buf[1]));
+ reset_hci_con_bd(hci_handle(&buf[1]));
=20=09=09
if (hci_ctrl.nbr_of_connections <=3D 0) {
hci_read_buffer_size(HCI_NON_BLOCK);
@@ -926,7 +924,7 @@
=20=09=09=09
}
=20=09=09
- sec_man_event(HCI, get_bd(CHAR2INT12(buf[2], buf[1])), AUTHENTICATION_CO=
MPLETE, buf, 1);
+ sec_man_event(HCI, get_bd(hci_handle(&buf[1])), AUTHENTICATION_COMPLETE,=
buf, 1);
#endif
wake_up_interruptible(&hci_wq);
break;
@@ -958,7 +956,7 @@
tmp[0] =3D buf[0];
tmp[1] =3D buf[3];
=20=09=09
- sec_man_event(HCI, get_bd(CHAR2INT12(buf[2], buf[1=
])), ENCRYPTION_CHANGE, tmp, 2);
+ sec_man_event(HCI, get_bd(hci_handle(&buf[1])), EN=
CRYPTION_CHANGE, tmp, 2);
}
#endif
wake_up_interruptible(&hci_wq);
@@ -1022,12 +1020,13 @@
=20
case FLUSH_OCCURRED:
D_CMD(__FUNCTION__ ": FLUSH_OCCURRED on hci_hdl %d\n",
- CHAR2INT12(buf[1],buf[0]));
- btmem_flushhandle(CHAR2INT12(buf[1],buf[0]));
+ hci_handle(buf));
+ btmem_flushhandle(hci_handle(buf));
break;
=20
case HARDWARE_ERROR:
- D_ERR(__FUNCTION__ ": An hardware error with error code 0x%02x occurred\=
n Please refer to your bluetooth module manual\n", buf[0]);
+ D_ERR(__FUNCTION__ ": A hardware error with error code 0x%02X occurred.\=
n", buf[0]);
+ D_ERR(__FUNCTION__ ": Please refer to your Bluetooth module's manual.\n"=
);
break;
=20
case ROLE_CHANGED:
@@ -1041,10 +1040,10 @@
=20=09=09=09
} else if (buf[7]) {
DSYS(__FUNCTION__ ": Current master is 0x%04x%08x\n",=20
- CHAR2INT16(buf[6], buf[5]),=20
- CHAR2INT32(buf[4], buf[3], buf[2], buf[1]));
+ le16_to_cpuu(&buf[5]), le32_to_cpuu(&buf[1]));
} else {
- DSYS(__FUNCTION__ ": Our role is master for BD Address 0x%04x%08x\n", C=
HAR2INT16(buf[6], buf[5]), CHAR2INT32(buf[4], buf[3], buf[2], buf[1]));
+ DSYS(__FUNCTION__ ": Our role is master for BD Address 0x%04x%08x\n",
+ le16_to_cpuu(&buf[5]), le32_to_cpuu(&buf[1]));
}
break;
=20
@@ -1058,7 +1057,7 @@
=20
case MODE_CHANGE:
D_CMD(__FUNCTION__ ": MODE_CHANGE on hci_hdl %d\n",
- CHAR2INT12(buf[2],buf[1]));
+ hci_handle(&buf[1]));
break;
=20
case RETURN_LINK_KEYS:
@@ -1162,13 +1161,11 @@
the command complete event */
=20
ogf =3D (u32) buf[2] >> 2;
- ocf =3D CHAR2INT10(buf[2],buf[1]);
+ ocf =3D le16_to_cpuu(&buf[1]) & 0x03FF;
r_val =3D buf + 3;
=20
switch (ogf) {
-
case HCI_LC:
-=20=20=20=20=20=20=20=20=20=20
switch (ocf) {
case LINK_KEY_REQUEST_REPLY:
release_cmd_timer();
@@ -1239,16 +1236,13 @@
D_CMD(__FUNCTION__ ": HCI_LC, ocf %d not recognised!\n", ocf);
break;
}
-
break;
=20=20=20=20=20=20=20=20=20=20=20
case HCI_HC: /* Host Controller commands */
-=09=09
release_cmd_timer();
/* FIXME -- correct timer should be released */
=20=20=20=20=20=20=20=20=20=20=20
switch (ocf) {
-=09=09=09
case CREATE_NEW_UNIT_KEY:
D_CMD(__FUNCTION__ ": CREATE_NEW_UNIT_KEY\n");
if (r_val[0]) {
@@ -1268,13 +1262,12 @@
result_param =3D - r_val[0];
} else {
D_CMD(__FUNCTION__ ": READ_STORED_LINK_KEY Success\n");
- result_param =3D CHAR2INT32(r_val[4], r_val[3],
- r_val[2], r_val[=
1]);
+ result_param =3D le32_to_cpuu(&r_val[1]);
}
DSYS(__FUNCTION__ ": Max number of Linkkeys: %d\n",
- CHAR2INT16(r_val[2], r_val[1]));
+ le16_to_cpuu(&r_val[1]));
DSYS(__FUNCTION__ ": Number of Linkkeys read: %d\n",
- CHAR2INT16(r_val[4], r_val[3]));
+ le16_to_cpuu(&r_val[3]));
break;
=20
case WRITE_STORED_LINK_KEY:
@@ -1296,11 +1289,11 @@
result_param =3D - r_val[0];
} else {
D_CMD(__FUNCTION__ ": DELETE_STORED_LINK_KEY Success\n");
- result_param =3D CHAR2INT16(r_val[2], r_val[1]);
+ result_param =3D le16_to_cpuu(&r_val[1]);
}
=20=09=09=09
D_CMD(__FUNCTION__ ": Number of Linkkeys deleted: %d\n",
- CHAR2INT16(r_val[2], r_val[1]));
+ le16_to_cpuu(&r_val[1]));
break;=09
=20=20=20=20=20=20=20=20=20=20=20=20=20
case READ_TRANSMIT_POWER_LEVEL:=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
@@ -1311,8 +1304,7 @@
get_err_msg(r_val[0]));
break;
} else {
- unsigned short hci_hdl =3D CHAR2INT12(r_val[2], r_val[1]);
- DSYS("READ_TRANSMIT_POWER_LEVEL : handle %d, %d dBm\n", hci_hdl, r_val=
[3]);
+ DSYS("READ_TRANSMIT_POWER_LEVEL: handle %d, %d dBm\n", hci_handle(&r_v=
al[1]), r_val[3]);
}
break;
=20
@@ -1438,7 +1430,7 @@
=20=20=20=20=20=20=20=20=20=20=20=20=20
case READ_LINK_SUPERVISION_TIMEOUT:
D_CMD(__FUNCTION__ ": Link supervision timeout is: %d\n",
- CHAR2INT16(buf[4],buf[3]));
+ le16_to_cpuu(&buf[3]));
break;
=20=20=20=20=20=20=20=20=20=20=20=20=20
case WRITE_LINK_SUPERVISION_TIMEOUT:
@@ -1497,7 +1489,6 @@
release_cmd_timer();
=20
switch (ocf) {
-
case READ_COUNTRY_CODE:
if (r_val[0]) {
D_ERR(__FUNCTION__ ": READ_COUNTRY_CODE : %s\n",
@@ -1528,10 +1519,10 @@
get_err_msg(r_val[0]));
break;
}
- hci_ctrl.hc_buf.acl_len =3D CHAR2INT16(r_val[2],r_val[1]);
+ hci_ctrl.hc_buf.acl_len =3D le16_to_cpuu(&r_val[1]);
hci_ctrl.hc_buf.sco_len =3D (u32) r_val[3];
- hci_ctrl.hc_buf.acl_num =3D CHAR2INT16(r_val[5],r_val[4]);
- hci_ctrl.hc_buf.sco_num =3D CHAR2INT16(r_val[7],r_val[6]);
+ hci_ctrl.hc_buf.acl_num =3D le16_to_cpuu(&r_val[4]);
+ hci_ctrl.hc_buf.sco_num =3D le16_to_cpuu(&r_val[6]);
printk("\nHW module contains...\n");
printk("%d ACL buffers at %d bytes\n%d SCO buffers at %d bytes\n\n",
hci_ctrl.hc_buf.acl_num, hci_ctrl.hc_buf.acl_len,
@@ -1592,10 +1583,9 @@
wake_up_interruptible(&hci_wq);
break;
=20=20=20=20=20=20=20=20=20=20=20
- case MANUFACTURER_SPEC: { /* manufacturer specific */
+ case MANUFACTURER_SPEC: /* Manufacturer specific */
D_CMD(__FUNCTION__ ": MANUFACTURER_SPEC\n");
process_vendor_return_param(ocf, r_val);
- }
break;
=20=20=20=20=20=20=20=20=20
default:
@@ -3531,13 +3521,22 @@
void=20
set_acl_hdr(u8 *data, u32 len, u8 pb, u8 bc, u32 hci_hdl)
{
- u32 tmp_hdr;
+ u32 tmp_hdr =3D 0;
+
+ SET_BITS(tmp_hdr, 0, 12, hci_hdl);
+ SET_BITS(tmp_hdr, 12, 2, pb);
+ SET_BITS(tmp_hdr, 14, 2, bc);
+ SET_BITS(tmp_hdr, 16, 16, len);
=20
data[0] =3D ACL_PKT;
- tmp_hdr =3D MAKE_ACL_HDR(hci_hdl,pb,bc,len);
- memcpy(data + 1, &tmp_hdr, 4);
+ put_unaligned(cpu_to_le32(tmp_hdr), (u32*)&data[1]);
}
=20
+u16
+hci_handle(void *data)
+{
+ return GET_BITS(le16_to_cpuu(data), 0, 12);
+}
=20
/* Returns the error messages according to the specification page 746 */
u8*=20
@@ -3645,9 +3644,9 @@
and 0x13 is the code for "Other End Terminated
Connection: User Ended Connection" */
D_CMD(__FUNCTION__ ": DISCONNECT->disconnection complete\n");
- o_len =3D set_discon_cpl_event(out_event, CHAR2INT12(cmd->data[1], cmd-=
>data[0]), 0x13);
+ o_len =3D set_discon_cpl_event(out_event, hci_handle(cmd->data), 0x13);
bt_write_lower_driver(o_event, o_len);
- if (lp_disconnect_ind(CHAR2INT12(cmd->data[1],cmd->data[0])))
+ if (lp_disconnect_ind(hci_handle(cmd->data)))
if (hci_ctrl.nbr_of_connections > 0) {
hci_ctrl.nbr_of_connections--;
hci_update_load_factor();
--- l2cap.c 2001/09/12 12:38:10 1.118
+++ l2cap.c 2001/09/21 12:51:06 1.119
@@ -59,12 +59,16 @@
#include <linux/bluetooth/l2cap_con.h>
#include <linux/bluetooth/l2cap_sec.h>
#include <linux/bluetooth/bt_errno.h>
+#include <asm/byteorder.h>
+#include <asm/unaligned.h>
#else /* user mode */
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#include <errno.h>
+#include <asm/unaligned.h>
+
#include "include/l2cap.h"
#include "include/hci.h"
#include "include/hci_internal.h"
@@ -588,7 +592,7 @@
in the connection less packet */
con =3D get_con_hcihdl(hci_handle);
=20=09=09
- get_upper(CHAR2INT16(pkt->data[1], pkt->data[0]))->
+ get_upper(le16_to_cpu(get_unaligned((u16 *)&pkt->data[0])))->
receive_data(con, pkt->data + 2, pkt_len - 2);
break;
=20=20=20=20=20
--- sdp.c 2001/09/19 10:16:27 1.79
+++ sdp.c 2001/09/21 12:51:06 1.80
@@ -58,6 +58,8 @@
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <asm/unaligned.h>
+
#include "include/bluetooth.h"
#include "include/btcommon.h"
#include "include/sdp.h"
@@ -798,7 +800,7 @@
=20
#ifndef __KERNEL__
if (sdp_sock < 0) {
- send_error_rsp(sdp, CHAR2INT16(data[2], data[1]), 6);
+ send_error_rsp(sdp, le16_to_cpu(get_unaligned((u16 *)&data[1])), 6);
}
#endif
=20
|