libaltos: Add support for TeleBT-v4.0 bluetooth channel change
authorKeith Packard <keithp@keithp.com>
Sat, 13 May 2017 22:24:20 +0000 (15:24 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 13 May 2017 22:29:13 +0000 (15:29 -0700)
The RN4678 in TeleBT v4.0 uses channel 6 instead of channel 1.
There is code in the linux bits which discovers this value, but that
crashes when run under java for unknown reasons.

Signed-off-by: Keith Packard <keithp@keithp.com>
libaltos/libaltos_common.c
libaltos/libaltos_linux.c
libaltos/libaltos_private.h
libaltos/libaltos_windows.c

index dfafcc7a790fa9d325fe70103caea3ff235b9d22..f577de022a16b2de0413c32bde610cf35e6c0083 100644 (file)
@@ -75,6 +75,27 @@ altos_putchar(struct altos_file *file, char c)
        return ret;
 }
 
+struct bt_vendor_map {
+       char    vendor[10];
+       int     port;
+};
+
+static const struct bt_vendor_map altos_bt_vendor_map[] = {
+       { .vendor = "00:12:6f:", 1 },   /* Rayson */
+       { .vendor = "8C:DE:52:", 6 },   /* ISSC */
+       { .vendor = "D8:80:39:", 6 },   /* Microchip */
+};
+
+#define NUM_BT_VENDOR_MAP      (sizeof altos_bt_vendor_map / sizeof altos_bt_vendor_map[0])
+#define BT_PORT_DEFAULT                1
+
+int altos_bt_port(struct altos_bt_device *device) {
+       unsigned i;
+       for (i = 0; i < NUM_BT_VENDOR_MAP; i++)
+               if (strncmp (device->addr, altos_bt_vendor_map[i].vendor, strlen(altos_bt_vendor_map[i].vendor)) == 0)
+                       return altos_bt_vendor_map[i].port;
+       return BT_PORT_DEFAULT;
+}
 
 PUBLIC void
 altos_free(struct altos_file *file)
index b187bb19c9a948a28c83f261485f15c49836a0f5..255b977347296078d66bf31220cd742e542cbd78 100644 (file)
@@ -501,32 +501,33 @@ altos_bt_fill_in(char *name, char *addr, struct altos_bt_device *device)
 struct altos_file *
 altos_bt_open(struct altos_bt_device *device)
 {
-       static const uint8_t svc_uuid_int[] = {
-               0, 0, 0, 0, 0, 0, 0, 0,
-               0, 0, 0, 0, 0, 0, 0x11, 0x01
-       };
-       uuid_t                  svc_uuid;
        struct sockaddr_rc      addr = { 0 };
        int                     status, i;
        struct altos_file_posix *file;
        sdp_session_t           *session = NULL;
-       sdp_list_t              *search_list, *attrid_list;
-       sdp_list_t              *response_list = NULL, *r;
-       uint32_t                range;
-       int                     err;
-       int                     channel = 1;
+       int                     channel = 0;
 
        if (str2ba(device->addr, &addr.rc_bdaddr) < 0) {
                altos_set_last_posix_error();
                goto no_file;
        }
 
+#if 0
        /*
         * Search for the RFCOMM service to get the right channel
         */
        session = sdp_connect(BDADDR_ANY, &addr.rc_bdaddr, SDP_RETRY_IF_BUSY);
 
        if (session) {
+               static const uint8_t svc_uuid_int[] = {
+                       0, 0, 0, 0, 0, 0, 0, 0,
+                       0, 0, 0, 0, 0, 0, 0x11, 0x01
+               };
+               int                     err;
+               uuid_t                  svc_uuid;
+               uint32_t                range;
+               sdp_list_t              *search_list, *attrid_list;
+               sdp_list_t              *response_list = NULL, *r;
                sdp_uuid16_create(&svc_uuid, PUBLIC_BROWSE_GROUP);
                search_list = sdp_list_append(NULL, &svc_uuid);
 
@@ -560,6 +561,9 @@ altos_bt_open(struct altos_bt_device *device)
                 * the RFCOMM channel
                 */
        }
+#endif
+       if (channel == 0)
+               channel = altos_bt_port(device);
 
        /* Connect to the channel */
        file = calloc(1, sizeof (struct altos_file_posix));
index f8e5231bf26b488d901b617e385d168d8f77607a..ee3dd708873d39a1e05fbb51c488e0748a0a8b94 100644 (file)
@@ -61,4 +61,7 @@ altos_flush(struct altos_file *file);
 int
 altos_fill(struct altos_file *file, int timeout);
 
+int
+altos_bt_port(struct altos_bt_device *device);
+
 #endif /* _LIBALTOS_PRIVATE_H_ */
index e53aa72bf87400583cd6819cf9b6cea415c8d5f8..4f9f18075e02c9744a6f6509ce6a9bcd6567e7d4 100644 (file)
@@ -747,7 +747,7 @@ altos_bt_open(struct altos_bt_device *device)
        memset(&sockaddr_bth, '\0', sizeof (sockaddr_bth));
        sockaddr_bth.addressFamily = AF_BTH;
        sockaddr_bth.btAddr = str2ba(device->addr);
-       sockaddr_bth.port = 1;
+       sockaddr_bth.port = altos_bt_port(device);
 
        ret = connect(file->socket, (SOCKADDR *) &sockaddr_bth, sizeof (sockaddr_bth));