From: Mattias A. <mat...@us...> - 2001-06-13 12:41:04
|
The following file was modified in linux/drivers/char/bluetooth: Name Old version New version Comment ---- ----------- ----------- ------- bluetooth.c 1.179 1.180=20=20=20=20=20=20=20=20=20=20=20 The accompanying log: * Added/Modified some debug * added fail checks for bcsp init and hci init * added semaphore protection around bt_ioctl * added bt_wait_tx() which waits for serial dma to finish tx=20 (used in non blocking set baudrate commands) * use return value in bt_init_stack to signal failed init to usermode The diff of the modified file(s): --- bluetooth.c 2001/06/07 06:49:09 1.179 +++ bluetooth.c 2001/06/13 12:10:44 1.180 @@ -190,7 +190,7 @@ static void bt_receive_data(u8* data, u32 count); =20 static void bt_show_version(void); -static void bt_init_stack(void); +static s32 bt_init_stack(void); static s32 bt_ctrl_init(void); static s32 bt_connect(u8 *bd_addr, u32 con_id); static s32 bt_disconnect(u32 con_id); @@ -252,6 +252,12 @@ =20 /****************** LOCAL VARIABLE DECLARATION SECTION *******************= ***/ =20 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) +static struct semaphore ioctl_sem =3D MUTEX; +#else +static struct semaphore ioctl_sem; +#endif /* LINUX_VERSION_CODE */ + static struct bt_ctrl_struct bt_ctrl; =20 /* some defines for easier reading */ @@ -489,8 +495,9 @@ #endif } =20 + static s32 -bt_ioctl(struct tty_struct *tty, struct file * file, +__bt_ioctl(struct tty_struct *tty, struct file * file, u32 cmd, unsigned long arg) { #define FNC "bt_ioctl: " @@ -613,7 +620,7 @@ } =20=09 case BTINITSTACK: - bt_init_stack(); + return bt_init_stack(); break; =20 case BTSHUTDOWN: @@ -623,7 +630,8 @@ case BTREADREMOTEBDADDR: BT_DRIVER(FNC"BTREADREMOTEBDADDR\n"); =20 - /* FIXME -- add parameter do get remote bd from any connected device */ + /* FIXME -- add parameter do get remote bd from any + connected device */ get_remote_bd(bd_addr); =20 { @@ -802,6 +810,7 @@ case HCICREATE_NEW_UNIT_KEY: { s32 result; + BT_DRIVER(FNC"HCICREATE_NEW_UNIT_KEY\n"); result =3D hci_create_new_unit_link_key(); put_user(result, (s32*)arg); break; @@ -851,7 +860,7 @@ /* FIXME: If we send the length of the string too, we don't have to copy all the 248 byte... */ u8 local_name[248]; - + BT_DRIVER(FNC"HCISETLOCALNAME\n"); copy_from_user(local_name, (s32*)arg, 248); hci_change_local_name(local_name); break; @@ -859,14 +868,13 @@ =20 case HCIREADSCANENABLE: BT_DRIVER("Reading scan enable\n"); - tmp =3D hci_read_scan_enable(); put_user(tmp, (s32*)arg); break; =20=09 case HCIWRITESCANENABLE: GET_USER(tmp, (s32*)arg); - BT_DRIVER("setting write scan enable : [0x%x]\n", tmp); + BT_DRIVER("Setting write scan enable : [0x%x]\n", tmp); hci_write_scan_enable(tmp); break; =20=09=09 @@ -874,7 +882,7 @@ { u32 par[2]; copy_from_user(&par, (s32*)arg, size); - BT_DRIVER("setting write page scan activity : [0x%x,0x%x]\n",=20 + BT_DRIVER("Setting write page scan activity : [0x%x,0x%x]\n",=20 par[0], par[1]); hci_write_pagescan_activity(par[0], par[1]); break; @@ -883,6 +891,7 @@ case HCIWRITECLASSOFDEVICE: { u8 class_of_device[3]; + BT_DRIVER(FNC"HCIWRITECLASSOFDEVICE\n"); copy_from_user(class_of_device, (s32*)arg, size); hci_write_class_of_device(class_of_device); break; @@ -891,6 +900,7 @@ case HCIREAD_AUTHENTICATION_ENABLE: { s32 result =3D hci_read_authentication_enable(); + BT_DRIVER(FNC"HCIREAD_AUTHENTICATION_ENABLE\n"); put_user(result, (s32*)arg); break; } @@ -899,7 +909,7 @@ { u8 enable; s32 result =3D 0; - + BT_DRIVER(FNC"HCIWRITE_AUTHENTICATION_ENABLE\n"); GET_USER(tmp, (s32*)arg); =20 enable =3D (u8)(tmp & 0xff); @@ -911,6 +921,7 @@ case HCIREAD_ENCRYPTION_MODE: { s32 result =3D hci_read_encryption_mode(); + BT_DRIVER(FNC"HCIREAD_ENCRYPTION_MODE\n"); put_user(result, (s32*)arg); break; } @@ -919,7 +930,7 @@ { u8 enable; s32 result =3D 0; -=09=09 + BT_DRIVER(FNC"HCIWRITE_ENCRYPTION_MODE\n"); GET_USER(tmp, (s32*)arg); =20 enable =3D (u8)(tmp & 0xff); @@ -932,6 +943,7 @@ case HCISET_EVENT_FILTER: { u8 param[size]; + BT_DRIVER(FNC"HCISET_EVENT_FILTER\n"); copy_from_user(param, (s32*)arg, size); =20=09=09 hci_set_event_filter(param); @@ -967,23 +979,27 @@ /* ioctls vendor specific HCI commands */ =20=09=09 case HCISETBAUDRATE: + {=09 + s32 tmp; /* Set baudrate in hardware */=20 GET_USER(tmp, (s32*)arg); BT_DRIVER(FNC"Setting baudrate in host controller to %d\n", tmp); -=09=09 - return hci_set_baudrate(tmp); + tmp =3D hci_set_baudrate(tmp); + return tmp; + } =20 case HCIWRITEBDADDR: copy_from_user(&bd_addr, (s32*)arg, size); - BT_DRIVER(FNC"setting BD_ADDR to \n"); + BT_DRIVER(FNC"Setting BD_ADDR to \n"); print_data("bd :",(u8*)bd_addr,6); hci_set_bd_addr(bd_addr); break;=20=20 =20=20=20=20=20=20 + /* | len (1) | hci header (4) | data (max 256)| */ case HCISENDRAWDATA: { u8 len; - u8 data[261]; /* | len (1) | hci header (4) | data (max 256)| */ + u8 data[261]; =20 /* first byte contains length of whole hci message */ copy_from_user(&len, (u8*)arg, 1); @@ -1053,16 +1069,14 @@ } =20 #ifdef CONFIG_BLUETOOTH_CSR - /* | ps_key (u16) | rw_mode (u16) | len (u16) | params (u16[])| */ - case BT_CSR_PSKEY: { u16 u16_size =3D CSR_PSKEY_MSGHDR_SIZE + CSR_PSKEY_MAXPARAMS; u16 msg[size]; =20=09=09 copy_from_user(msg, (u8*)arg, u16_size*sizeof(u16)); - + BT_DRIVER("BT_CSR_PSKEY [ps:%d type:%d]\n", msg[0], msg[1]); csr_pskey(msg[0], msg[1], &msg[3], msg[2]); =20=09=09 copy_to_user((s32*)arg, msg, u16_size*sizeof(u16)); @@ -1072,14 +1086,13 @@ #ifdef CONFIG_BLUETOOTH_SUPPORT_BCSP case BTINITBCSP: { - printk("BTINITBCSP\n"); + BT_DRIVER("BTINITBCSP\n"); if (bcsp_init() < 0) printk("Sync failed\n"); return 0; } #endif - -#endif +#endif /* CONFIG_BLUETOOTH_CSR */ =20 default:=09=09 return -ENOIOCTLCMD; @@ -1089,6 +1102,19 @@ #undef FNC } =20 +static s32 +bt_ioctl(struct tty_struct *tty, struct file * file, + u32 cmd, unsigned long arg) +{ + s32 tmp; + //printk(__FUNCTION__"[%s:%x] lock !\n", current->comm, cmd); + down(&ioctl_sem); + //printk(__FUNCTION__"[%s:%x] running...\n", current->comm, cmd); + tmp =3D __bt_ioctl(tty, file, cmd, arg); + up(&ioctl_sem); + return tmp; +} + static void bt_throttle(struct tty_struct * tty) { @@ -1188,9 +1214,6 @@ u32 cmd, unsigned long arg) { #define FNC "bt_tty_ioctl: " - BT_LDISC("bt_tty_ioctl cmd 0x%x\n", cmd); -=20=20 - /* FIXME - paranoia check */ =20=20=20 switch (cmd) { =20 @@ -1355,7 +1378,6 @@ #undef FNC } =20 - /************************/ /* glue layer functions */ /************************/ @@ -1610,6 +1632,15 @@ #undef FNC } =20 +/* Used to wait for dma to finish transmission */ +void bt_wait_tx(s32 trim_delay) +{ + s32 cnt; + while ((cnt =3D sertty->driver.chars_in_buffer(sertty)) > 0) + udelay(100); + udelay(trim_delay); +} + #ifdef CONFIG_BLUETOOTH_USE_INBUFFER static void bt_handle_indata(const __u8 *data, s32 count) { @@ -2332,6 +2363,12 @@ hci_data.get =3D hci_data.head;; #endif =20 +#ifdef __KERNEL__ +#if LINUX_VERSION_CODE >=3D KERNEL_VERSION(2,4,0) + sema_init(&ioctl_sem, 1); +#endif /* LINUX_VERSION_CODE */ +#endif /* __KERNEL__ */ + return 0; /*success*/ } =20 @@ -2366,7 +2403,8 @@ } return old; } -void + +s32 bt_init_stack(void) { unsigned long page;=09 @@ -2400,10 +2438,20 @@ btmem_init(); =20 #ifdef CONFIG_BLUETOOTH_SUPPORT_BCSP - if (bt_use_bcsp(-1) && !bcsp_issyncronized()) - bcsp_init(); + if (bt_use_bcsp(-1) && !bcsp_issyncronized()) {=20=20 + if (bcsp_init() < 0){ + bcsp_shutdown(); + goto init_failed_exit0; + } + } #endif - hci_init(); + + /* Always check if hci succeeded */ + if (hci_init() < 0){ + D_ERR("HCI failed to initialize\n"); + goto init_failed_exit1; + } +=09 l2cap_init(); =20 #ifdef CONFIG_BLUETOOTH_USE_TCI @@ -2428,6 +2476,19 @@ bt_clear_led_timer.expires =3D jiffies + HZ/10; add_timer(&bt_clear_led_timer); #endif + return 0; + + init_failed_exit1:=20 + printk("init_failed_exit1\n"); + hci_shutdown(); + init_failed_exit0: + printk("init_failed_exit0\n"); + btmem_shutdown(); + if (tmp_bt_buf) { + free_page((unsigned long) tmp_bt_buf); + tmp_bt_buf =3D NULL; + } + return -1; } =20 #ifdef BT_USELINEBUF @@ -2691,8 +2752,8 @@ if (line =3D=3D BT_NBR_PORTS-BT_NBR_CTRLPORTS) { NBR_CTRL_FDS++; =20=09=09 - DSYS("Now %d open fd:s for ttyBTC\n",=20 - NBR_CTRL_FDS); + BT_DRIVER("Now %d open fd:s for ttyBTC [%s]\n",=20 + NBR_CTRL_FDS, current->comm); if (NBR_CTRL_FDS > 1) return 0; /* already registered state */ } else { |