libaltos: Add new microchip MAC address to bluetooth map
authorKeith Packard <keithp@keithp.com>
Mon, 16 Aug 2021 00:08:44 +0000 (17:08 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 16 Aug 2021 00:10:53 +0000 (17:10 -0700)
The new batch of BT modules use a new MAC prefix.  On Linux, also add
the RFCOMM channel discovery code in case this happens again. On
windows, suffer.

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

index 3a3aca0e3092399dd5b29c645554eb8689712882..8062fcb2251b433dd11593faef7e0340fc73140e 100755 (executable)
Binary files a/libaltos/altos.dll and b/libaltos/altos.dll differ
index c83c59e9293cf09f4365a583cdb320f8b65fa1a6..91ab068f8bddc3a7f999b588ce67b0f2510b8fd4 100755 (executable)
Binary files a/libaltos/altos64.dll and b/libaltos/altos64.dll differ
index fb8c314e3ae1b5f233d605090bbed39147f8a8e2..a2f257358ab973b11dca67e01fdc1413b6e90842 100644 (file)
@@ -89,10 +89,10 @@ 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 */
+       { .vendor = "04:91:62:", 6 },   /* New Microchip */
 };
 
 #define NUM_BT_VENDOR_MAP      (sizeof altos_bt_vendor_map / sizeof altos_bt_vendor_map[0])
-#define BT_PORT_DEFAULT                1
 
 static inline int
 ao_tolower(int c) {
@@ -114,7 +114,7 @@ int altos_bt_port(struct altos_bt_device *device) {
                                break;
                }
        }
-       return BT_PORT_DEFAULT;
+       return 0;
 }
 
 PUBLIC void
index 255b977347296078d66bf31220cd742e542cbd78..55038ff0b856d9b4108bf007706070879166d941 100644 (file)
@@ -512,58 +512,66 @@ altos_bt_open(struct altos_bt_device *device)
                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);
-
-               range = 0x0000ffff;
-               attrid_list = sdp_list_append(NULL, &range);
-
-               err = sdp_service_search_attr_req(session, search_list,
-                                                 SDP_ATTR_REQ_RANGE, attrid_list, &response_list);
-
-               if (err >= 0) {
-                       for (r = response_list; r; r = r->next) {
-                               sdp_record_t *rec = (sdp_record_t*) r->data;
-                               sdp_list_t *proto_list;
-                               sdp_list_t *access = NULL;
-                               int proto;
-
-                               proto = sdp_uuid_to_proto(&rec->svclass);
-
-                               if (proto == SERIAL_PORT_SVCLASS_ID) {
-                                       sdp_get_access_protos(rec, &access);
-                                       if (access) {
-                                               int this_chan = sdp_get_proto_port(access, RFCOMM_UUID);
-                                               if (this_chan)
-                                                       channel = this_chan;
+       /* Try the built-in vendor list */
+       channel = altos_bt_port(device);
+
+       /* Not present, try to discover an RFCOMM service */
+       if (channel == 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);
+
+                       range = 0x0000ffff;
+                       attrid_list = sdp_list_append(NULL, &range);
+
+                       err = sdp_service_search_attr_req(session, search_list,
+                                                         SDP_ATTR_REQ_RANGE, attrid_list, &response_list);
+
+                       if (err >= 0) {
+                               for (r = response_list; r; r = r->next) {
+                                       sdp_record_t *rec = (sdp_record_t*) r->data;
+                                       sdp_list_t *proto_list;
+                                       sdp_list_t *access = NULL;
+                                       int proto;
+
+                                       proto = sdp_uuid_to_proto(&rec->svclass);
+
+                                       if (proto == SERIAL_PORT_SVCLASS_ID) {
+                                               sdp_get_access_protos(rec, &access);
+                                               if (access) {
+                                                       int this_chan = sdp_get_proto_port(access, RFCOMM_UUID);
+                                                       if (this_chan) {
+                                                               printf("found service on channel %d\n", this_chan);
+                                                               channel = this_chan;
+                                                       }
+                                               }
                                        }
                                }
                        }
-               }
 
-               /* Leave the session open so we don't disconnect from the device before opening
-                * the RFCOMM channel
-                */
+                       /* Leave the session open so we don't disconnect from the device before opening
+                        * the RFCOMM channel
+                        */
+               }
        }
-#endif
+
+       /* Still nothing, try the default */
        if (channel == 0)
-               channel = altos_bt_port(device);
+               channel = BT_PORT_DEFAULT;
 
        /* Connect to the channel */
        file = calloc(1, sizeof (struct altos_file_posix));
index f356eb6b4907996f4cfda52d0fa3588e80b06cac..9b9b4ec40a53f9de85ccd0ed3d048bc771469bf8 100644 (file)
@@ -25,6 +25,7 @@
 #include <string.h>
 
 #define BLUETOOTH_PRODUCT_TELEBT       "TeleBT"
+#define BT_PORT_DEFAULT                6
 
 #define USB_BUF_SIZE   64
 
index 43e347c40cb70ce96bb0bbf9dd19875a6e551881..33eb77c7ac7c1149f4e03823e8218ca49e399989 100644 (file)
@@ -757,6 +757,7 @@ altos_bt_open(struct altos_bt_device *device)
        struct altos_file_windows       *file;
        SOCKADDR_BTH            sockaddr_bth;
        int                     ret;
+       int                     channel = 0;
 
        file = calloc(1, sizeof (struct altos_file_windows));
        if (!file) {
@@ -775,7 +776,12 @@ 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 = altos_bt_port(device);
+
+       channel = altos_bt_port(device);
+       if (channel == 0)
+               channel = BT_PORT_DEFAULT;
+
+       sockaddr_bth.port = channel;
 
        ret = connect(file->socket, (SOCKADDR *) &sockaddr_bth, sizeof (sockaddr_bth));