From: Peter K. <pk...@us...> - 2001-05-18 15:42:13
|
The following file was modified in linux/drivers/char/bluetooth: Name Old version New version Comment ---- ----------- ----------- ------- bcsp_datagram.c 1.2 1.3=20=20=20=20=20=20=20=20=20=20=20=20=20 The accompanying log: * Use get_unaligned() instead of CHAR2INT32(). * Rewrote send_sync() & co to not use kmalloc(), and only implement the functionality once. Should now also be correct for big endian machines. The diff of the modified file(s): --- bcsp_datagram.c 2001/05/17 15:25:15 1.2 +++ bcsp_datagram.c 2001/05/18 15:42:13 1.3 @@ -42,18 +42,21 @@ =20 /****************** INCLUDE FILES SECTION ********************************= ***/ =20 -#include <stdio.h> #include <linux/malloc.h> +#include <asm/byteorder.h> +#include <asm/unaligned.h> + +#include <linux/bluetooth/sysdep-2.1.h> #include <linux/bluetooth/bcsp.h> #include <linux/bluetooth/bcsp_debug.h> #include <linux/bluetooth/btcommon.h> =20 /****************** CONSTANT AND MACRO SECTION ***************************= ***/ =20 -#define SYNC 0xededdcda -#define SYNC_RSP 0xeeefafac -#define CONF 0xedacefad -#define CONF_RSP 0xd0d0adde +#define SYNC 0xEDEDDCDA +#define SYNC_RSP 0xEEEFAFAC +#define CONF 0xEDACEFAD +#define CONF_RSP 0xD0D0ADDE =20 #if DATAGRAM_DEBUG #define D(fmt...) printk("DATAGRAM: " fmt) @@ -70,6 +73,7 @@ static s32 handle_sync_pkt(struct bcsp *bcsp); static s32 send_sync_rsp(void); static s32 send_conf_rsp(void); +static s32 send_sync_pkt(u32 type); =20 /****************** GLOBAL VARIABLE DECLARATION SECTION ******************= ***/ =20 @@ -85,7 +89,7 @@ return 0; } =20 - D(__FUNCTION__ ": Datagram packet received\n"); + D(__FUNCTION__ ": Datagram packet received:\n"); PRINTPKT(bcsp->payload, bcsp->payload_length); =20=09 return 0; @@ -109,12 +113,14 @@ s32 handle_sync_pkt(struct bcsp *bcsp) { - u32 sync_string; =20 - sync_string =3D CHAR2INT32(bcsp->payload[3],bcsp->payload[2], - bcsp->payload[1],bcsp->payload[0]); + if (bcsp->payload_length < sizeof(u32)) { + return FALSE; + } =20 + sync_string =3D le32_to_cpu(get_unaligned((u32 *)bcsp->payload)); + if (sync_string =3D=3D SYNC) { D(__FUNCTION__ ": Found SYNC\n"); send_sync_rsp();=09=09 @@ -126,83 +132,41 @@ } else { return FALSE; } -=09 } =20 s32 send_sync(void) { - struct bcsp bcsp; - u32 sync =3D SYNC; - s32 tmp; -=09 - D(__FUNCTION__ "\n"); - - init_bcsp_packet(&bcsp); -=09 - bcsp.identifier =3D 1;=20=20 - bcsp.payload_length =3D 4; - - if (!(bcsp.payload =3D kmalloc(bcsp.payload_length, GFP_ATOMIC))) { - return -ENOMEM; - } - memcpy(bcsp.payload, &sync, bcsp.payload_length); - - PRINTPKT(bcsp.payload, bcsp.payload_length); - - tmp =3D mux_send(&bcsp); - kfree(bcsp.payload); - return tmp; + return send_sync_pkt(SYNC); } =20 s32 send_sync_rsp(void) { - struct bcsp bcsp; - s32 tmp; - u32 sync_rsp =3D SYNC_RSP; - - D(__FUNCTION__ "\n"); - - init_bcsp_packet(&bcsp); - - bcsp.identifier =3D 1;=20=20 - bcsp.payload_length =3D 4; - - if (!(bcsp.payload =3D kmalloc(bcsp.payload_length, GFP_ATOMIC))) { - return -ENOMEM; + return send_sync_pkt(SYNC_RSP); } - memcpy(bcsp.payload, &sync_rsp, bcsp.payload_length); - - PRINTPKT(bcsp.payload, bcsp.payload_length); =20 - tmp =3D mux_send(&bcsp); - kfree(bcsp.payload); - return tmp; +s32 +send_conf_rsp(void) +{ + return send_sync_pkt(CONF_RSP); } =20 s32 -send_conf_rsp(void) +send_sync_pkt(u32 type) { struct bcsp bcsp; - s32 tmp; - u32 conf_rsp =3D CONF_RSP; + u32 payload =3D cpu_to_le32(type); =20=09 D(__FUNCTION__ "\n"); =20 init_bcsp_packet(&bcsp); =20=09 bcsp.identifier =3D 1;=20 - bcsp.payload_length =3D 4; - - if (!(bcsp.payload =3D kmalloc(bcsp.payload_length, GFP_ATOMIC))) { - return -ENOMEM; - } - memcpy(bcsp.payload, &conf_rsp, bcsp.payload_length); + bcsp.payload =3D (u8 *)&payload; + bcsp.payload_length =3D sizeof(u32); =20 - tmp =3D mux_send(&bcsp); - kfree(bcsp.payload); - return tmp; + return mux_send(&bcsp); } =20 /****************** END OF FILE sequence.c *******************************= ***/ |