|
From: Peter K. <pk...@us...> - 2001-04-20 16:12:14
|
The following files were modified in apps/bluetooth/btd:
Name Old version New version Comment
---- ----------- ----------- -------
btd.c 1.93 1.94=20=20=20=20=20=20=20=20=20=20=20=20
btd.h 1.35 1.36=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Use bt_hw_vendor() to identify which kind of hardware is used,
instead of deciding this when compiling.
The diff of the modified file(s):
--- btd.c 2001/04/18 11:50:32 1.93
+++ btd.c 2001/04/20 16:12:14 1.94
@@ -300,6 +300,9 @@
static void read_local_bd(int bt_cfd, unsigned char *bd_addr);
static void read_remote_bd(int bt_cfd, unsigned char *bd_addr);
static void role_switch(int bt_cfd, unsigned char *bd_addr, int role);
+#ifndef BTD_USERSTACK
+static char* bt_hw_vendor(void);
+#endif
static void reset_hw(void);
static void bt_set_classofdevice(int bt_fd, unsigned short service_class, =
unsigned char major_class, unsigned char minor_class, unsigned char format);
=20
@@ -307,10 +310,25 @@
/* Misc */
static void show_menu(void);
=20
-#if defined(CONFIG_BLUETOOTH_ERICSSON)&&defined(__CRIS__)
-#define ECS_TEST_FUNCTIONS
-#endif
+static int hw_vendor(void);
+
+static void ericsson_init_phys(int fd);
+static void ericsson_init_hw(int spd);
+static void csr_init_phys(int fd);
+static void csr_init_hw(int spd);
+static void digianswer_init_phys(int fd);
+static void digianswer_init_hw(int spd);
+static void usb_init_phys(int fd);
+static void usb_init_hw(int spd);
+static void generic_init_phys(int fd);
+static void generic_init_hw(int spd);
+static void no_init_phys(int fd);
+static void no_init_hw(int spd);
+static void unknown_init_phys(int fd);
+static void unknown_init_hw(int spd);
=20
+#undef ECS_TEST_FUNCTIONS
+
#ifdef ECS_TEST_FUNCTIONS
static void enable_dut(int bt_cfd);
static void test_connection_req(int* bd);
@@ -396,6 +414,15 @@
=20
#define BTD_HISTORY_FILE "/tmp/btd_history"
=20
+#define HW_NOT_PROBED -1
+#define HW_ERICSSON 0
+#define HW_CSR 1
+#define HW_DIGIANSWER 2
+#define HW_USB 3
+#define HW_GENERIC 4
+#define HW_NO_INIT 5
+#define HW_UNKNOWN 6
+
/*=20
Bluetooth discipline define. Should reside in /include/asm/termios.h
However, if compiling this standalone simply use the define in bluetoot=
h.h
@@ -2854,7 +2881,6 @@
bt_disconnect(int bt_fd, unsigned int con_id)
{
#ifndef BTD_USERSTACK
-
if (ioctl(bt_fd, BTDISCONNECT, &con_id) < 0)
{
perror("Disconnect");
@@ -3111,6 +3137,23 @@
#endif
}
=20
+#ifndef BTD_USERSTACK
+char*
+bt_hw_vendor(void)
+{
+ int bt_cfd =3D open(BT_CTRL_TTY, O_RDWR | O_NOCTTY);
+ static char buffer[20];
+
+ if (bt_cfd < 0 || ioctl(bt_cfd, BTHWVENDOR, buffer) < 0)
+ {
+ perror(__FUNCTION__);
+ return NULL;
+ }
+ close(bt_cfd);
+ return buffer;
+}
+#endif
+
void
reset_hw(void)
{
@@ -3145,26 +3188,130 @@
/****************** Vendor dependent functions ***********************/
/*********************************************************************/
=20
-#if defined(CONFIG_BLUETOOTH_ERICSSON)
+void
+init_phys(int fd)
+{
+ switch (hw_vendor())
+ {
+ case HW_ERICSSON:
+ ericsson_init_phys(fd);
+ break;
+
+ case HW_CSR:
+ csr_init_phys(fd);
+ break;
+
+ case HW_DIGIANSWER:
+ digianswer_init_phys(fd);
+ break;
+
+ case HW_USB:
+ usb_init_phys(fd);
+ break;
+
+ case HW_GENERIC:
+ generic_init_phys(fd);
+ break;
+
+ case HW_NO_INIT:
+ no_init_phys(fd);
+ break;
=20
+ case HW_UNKNOWN:
+ default:
+ unknown_init_phys(fd);
+ break;
+ }
+}
+
+void
+init_hw(int spd)
+{
+ switch (hw_vendor())
+ {
+ case HW_ERICSSON:
+ ericsson_init_hw(spd);
+ break;
+
+ case HW_CSR:
+ csr_init_hw(spd);
+ break;
+
+ case HW_DIGIANSWER:
+ digianswer_init_hw(spd);
+ break;
+
+ case HW_USB:
+ usb_init_hw(spd);
+ break;
+
+ case HW_GENERIC:
+ generic_init_hw(spd);
+ break;
+
+ case HW_NO_INIT:
+ no_init_hw(spd);
+ break;
+
+ case HW_UNKNOWN:
+ default:
+ unknown_init_hw(spd);
+ break;
+ }
+}
+
+int
+hw_vendor(void)
+{
+ static int hw_vendor =3D HW_NOT_PROBED;
+
+ if (hw_vendor =3D=3D HW_NOT_PROBED)
+ {
+ char *vendor =3D bt_hw_vendor();
+
+ if (!vendor)
+ hw_vendor =3D HW_UNKNOWN;
+ else if (!strcmp(vendor, "Ericsson"))
+ hw_vendor =3D HW_ERICSSON;
+ else if (!strcmp(vendor, "CSR"))
+ hw_vendor =3D HW_CSR;
+ else if (!strcmp(vendor, "Digianswer"))
+ hw_vendor =3D HW_DIGIANSWER;
+ else if (!strcmp(vendor, "USB"))
+ hw_vendor =3D HW_USB;
+ else if (!strcmp(vendor, "Generic"))
+ hw_vendor =3D HW_GENERIC;
+ else if (!strcmp(vendor, "No Init"))
+ hw_vendor =3D HW_NO_INIT;
+ else
+ hw_vendor =3D HW_UNKNOWN;
+ }
+
+ return hw_vendor;
+}
+
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
+/* Ericsson specific commands */
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
+
/* Set the phys device to Ericsson default speed, 57600 */
-void init_phys(int fd)
+void
+ericsson_init_phys(int fd)
{
fd_setup(fd, 57600, USE_FLOW_CTRL);
}
=20
void
-init_hw(int spd)
+ericsson_init_hw(int spd)
{
- /*
- wait for Ericsson module to boot if running this app
- directly at startup=20
- */
#ifndef BTD_USERSTACK
unsigned int wrscan =3D (PAGE_SCAN_ENABLE | INQUIRY_SCAN_ENABLE);
unsigned char evfilter[3];
=20=20=20
+ /* wait for Ericsson module to boot if running this app directly at star=
tup=20
+ */
sleep(1);
+
printf("Setting write_scan_enable in Ericsson module!\n");
if (ioctl(bt_cfd, HCIWRITESCANENABLE, &wrscan) < 0)
{=20
@@ -3191,7 +3338,6 @@
perror("HCISETBAUDRATE");
exit(1);
}
-=20=20=20=20=20
#else=20=20
printf("Setting write_scan_enable in Ericsson module!\n");
hci_write_scan_enable(PAGE_SCAN_ENABLE|INQUIRY_SCAN_ENABLE);=09=09
@@ -3203,49 +3349,21 @@
hci_set_baudrate(spd);=20=20
#endif
}
-
-#elif defined(CONFIG_BLUETOOTH_DIGIANSWER)
-/*********************************************************************/
-/*********************************************************************/
-
-/* Set the phys device to Digianswer default, 9600 */=20
-void init_phys(int fd)
-{
- fd_setup(fd, 9600, USE_FLOW_CTRL);
-}
-
-void
-init_hw(int spd)
-{
- printf("Setting baudrate in Digianswer PC card\n");
-#ifndef BTD_USERSTACK
- if (ioctl(bt_cfd, HCISETBAUDRATE, &spd) < 0)
- {
- perror("HCISETBAUDRATE");
- exit(1);
- }
-#else
- hci_set_baudrate(spd);
-#if DIGI_DONGLE_SUPPORT
- // FIXME - what to do about this?
- hci_set_baudrate(115200);
-#endif
-
-#endif
-}
=20
-#elif defined(CONFIG_BLUETOOTH_CSR)
-/*********************************************************************/
-/*********************************************************************/
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
+/* CSR specific commands */
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
=20
/* Set the phys device to CSR default, 115200 */=20
-void init_phys(int fd)
+void
+csr_init_phys(int fd)
{
fd_setup(fd, 115200, USE_FLOW_CTRL);
}
=20
+/* fixme -- remove hardcoded values */
void
-init_hw(int spd)
+csr_init_hw(int spd)
{=20=20
#ifndef BTD_USERSTACK
unsigned int wrscan =3D (PAGE_SCAN_ENABLE | INQUIRY_SCAN_ENABLE);
@@ -3281,8 +3399,6 @@
perror("HCISET_EVENT_FILTER");
exit(1);
}
-
-
#else
printf("Setting write_scan_enable in CSR module!\n");
hci_write_scan_enable(PAGE_SCAN_ENABLE|INQUIRY_SCAN_ENABLE);
@@ -3292,18 +3408,49 @@
#endif
}
=20
-#elif defined(CONFIG_BLUETOOTH_GENERIC)
-/*********************************************************************/
-/*********************************************************************/
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
+/* Digianswer specific commands */
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
=20
-/* Set the phys device to something, e.g. 115200 */=20
-void init_phys(int fd)
+/* Set the phys device to Digianswer default, 9600 */=20
+void
+digianswer_init_phys(int fd)
+{
+ fd_setup(fd, 9600, USE_FLOW_CTRL);
+}
+
+void
+digianswer_init_hw(int spd)
+{
+ printf("Setting baudrate in Digianswer PC card\n");
+#ifndef BTD_USERSTACK
+ if (ioctl(bt_cfd, HCISETBAUDRATE, &spd) < 0)
{
+ perror("HCISETBAUDRATE");
+ exit(1);
+ }
+#else
+ hci_set_baudrate(spd);
+#if DIGI_DONGLE_SUPPORT
+ // FIXME - what to do about this?
+ hci_set_baudrate(115200);
+#endif
+
+#endif /* BTD_USERSTACK */
+}
+
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
+/* USB specific commands */
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
+
+void
+usb_init_phys(int fd)
+{
fd_setup(fd, 115200, USE_FLOW_CTRL);
}
=20
void
-init_hw(int spd)
+usb_init_hw(int spd)
{
#ifndef BTD_USERSTACK
unsigned int wrscan =3D (PAGE_SCAN_ENABLE | INQUIRY_SCAN_ENABLE);
@@ -3321,39 +3468,65 @@
#endif
}
=20
-#elif defined(CONFIG_BLUETOOTH_NOINIT)
-/*********************************************************************/
-/*********************************************************************/
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
+/* Generic commands */
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
=20
-/* Set the phys device to something, e.g. 115200 */=20
-void init_phys(int fd)
+void
+generic_init_phys(int fd)
{
- printf("init_phys: No hardware.\n");
+ fd_setup(fd, 115200, USE_FLOW_CTRL);
}
=20
void
-init_hw(int spd)
+generic_init_hw(int spd)
{
- printf("No hw init done\n");
-}
+#ifndef BTD_USERSTACK
+ unsigned int wrscan =3D (PAGE_SCAN_ENABLE | INQUIRY_SCAN_ENABLE);
+ sleep(1);
+ printf("Setting write_scan_enable in USB module!\n");
=20
+ if (ioctl(bt_cfd, HCIWRITESCANENABLE, &wrscan) < 0)
+ {=20
+ perror("HCIWRITESCANENABLE");
+ exit(1);
+ }
#else
-/*********************************************************************/
-/*********************************************************************/
+ hci_write_scan_enable(PAGE_SCAN_ENABLE|INQUIRY_SCAN_ENABLE);
+ sleep(1); /* wait for HW */
+#endif
+}
=20
-void init_phys(int fd)
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
+/* No HW init commands */
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
+
+void
+no_init_phys(int fd)
+{
+}
+
+void
+no_init_hw(int spd)
{
+}
+
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
+/* Default */
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
+
+void
+unknown_init_phys(int fd)
+{
printf("ERROR: init_phys() not implemented!\n");
}
=20
void
-init_hw(int spd)
+unknown_init_hw(int spd)
{
printf("ERROR: init_hw() not implemented!\n");
}
=20
-#endif /* HW_USED() */
-
/*********************************************************************/
/***************** Ericsson test functions ***************************/
/***************** This will be moved later **************************/
@@ -3463,7 +3636,6 @@
{
perror("test con req");
}
-=20=20
#else
hdl =3D hci_test_connect_req(btcon.bd);
#endif
@@ -3479,7 +3651,6 @@
unsigned char test_msg[17];
int i;
=20
-=20=20
ecs_test_msg[0] =3D CMD_PKT;
ecs_test_msg[1] =3D OPCODE_LSB(ERICSSON_TX_TEST, MANUFACTURER_SPEC);
ecs_test_msg[2] =3D OPCODE_MSB(ERICSSON_TX_TEST, MANUFACTURER_SPEC);
@@ -3510,7 +3681,6 @@
printf("Length_Of_Test_Data : 0x%x\n", tmp[10]);
=20=20=20
#ifndef BTD_USERSTACK
-
test_msg[0] =3D 17;
memcpy(test_msg + 1, ecs_test_msg, 17);
=20=20=20
@@ -3521,9 +3691,10 @@
#else
hci_send_raw_data(test_msg, 17);
#endif
+
printf("TX test starting.\n");
}
-#endif
+#endif /* ECS_TEST_FUNCTIONS */
=20
/*********************************************************************/
/*********************************************************************/
--- btd.h 2001/03/05 16:57:54 1.35
+++ btd.h 2001/04/20 16:12:14 1.36
@@ -46,24 +46,6 @@
=20
/****************** CONSTANT AND MACRO SECTION ***************************=
***/
=20
-/* HW init defines */
-
-/* Let us assume that if CONFIG_BLUETOOTH is definend (from the kernel
- includes), then CONFIG_BLUETOOTH_<hardware> is also defined correctly */
-#ifndef CONFIG_BLUETOOTH
-
-/* Define the one of these that matches the used hardware */
-#undef CONFIG_BLUETOOTH_NOINIT=20=20=20=20=20
-#undef CONFIG_BLUETOOTH_CSR=20=20=20=20=20=20=20=20
-#undef CONFIG_BLUETOOTH_DIGIANSWER=20
-#define CONFIG_BLUETOOTH_ERICSSON
-#undef CONFIG_BLUETOOTH_GENERIC=20=20=20=20
-#undef CONFIG_BLUETOOTH_USBMODULE /* Not implemented */
-
-#endif CONFIG_BLUETOOTH
-
-/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */
-
/* Ioctls for the BT driver */
=20
#define BT_IOC_MAGIC 'B' /* Use B as a magic number */
@@ -81,6 +63,7 @@
#define BTREADREMOTEBDADDR _IOR(BT_IOC_MAGIC, 0x07, unsigned char[6])
#define BTRESETPHYSICALHW _IO(BT_IOC_MAGIC, 0x08)
#define BTISINITIATED _IOR(BT_IOC_MAGIC, 0x09, int)
+#define BTHWVENDOR _IOR(BT_IOC_MAGIC, 0x0A, char[20])
=20
/* ioctls executing HCI commands */
=20
@@ -144,8 +127,6 @@
#define INQUIRY_SCAN_ENABLE 1
#define PAGE_SCAN_ENABLE 2
=20
-/****************** TYPE DEFINITION SECTION ******************************=
***/
-
#define SDP_LAYER 1
#define RFCOMM_LAYER 3
#define TCS_LAYER 5
@@ -153,13 +134,16 @@
#define CREATE_RFCOMM_ID(line, dlci) ( ((RFCOMM_LAYER << 16)&0xffff0000) |=
((line<<8)&0xff00) | ((dlci) & 0xff) )
#define GET_PSM(con_id) (con_id >> 16)
=20
+/****************** TYPE DEFINITION SECTION ******************************=
***/
=20
-typedef struct bt_connection{
+typedef struct bt_connection
+{
unsigned char bd[6];
unsigned int id; /* | psm(16 bits)=A0| layer_specific (16 bits)=A0|=A0*/
} bt_connection;
=20
-typedef struct inquiry_results {
+typedef struct inquiry_results
+{
unsigned int nbr_of_units;
unsigned int inq_time;
unsigned char bd_addr[0];
|