GFRMx00: Remove OUI-based discovery and pairing

plugins/gfrm.c:
Change GFRMx00 IR discovery to use BD_ADDR type for determining whether
the newly discovered remote is GFRM100 or GFRM200. The BD_ADDR type is
the 7th byte read from /tmp/bd-addr-fifo. It is BDADDR_BREDR (0x0) for
GFRM100 and BDADDR_LE_PUBLIC (0x1) for GFRM200. This information is
provided by the FIFO writer (miniclient).

test/gfiber-agent:
Change GFRMx00 pairing to use GFRMx00 device name only. The device name
is always available since it is set by plugins/gfrm.c at discovery time.

Change-Id: I8f7277a4fc375311b2b7f37a72ccb3943bb9ed4d
diff --git a/plugins/gfrm.c b/plugins/gfrm.c
index 364d5ab..4a542aa 100644
--- a/plugins/gfrm.c
+++ b/plugins/gfrm.c
@@ -41,24 +41,23 @@
 
 struct gfrm_device {
 	char *name;
-	uint8_t oui[3];
 	uint8_t bdaddr_type;
 	uint16_t vid;
 	uint16_t pid;
 };
 
 static struct gfrm_device gfrm_devs[] = {
-	{ "GFRM100", {0x00, 0x24, 0x1C}, BDADDR_BREDR, 0x58, 0x2000 },
-	{ "GFRM200", {0x88, 0x33, 0x14}, BDADDR_LE_PUBLIC, 0x471, 0x2210 },
-	{ "HID AdvRemote", {0x90, 0x59, 0xAF}, BDADDR_LE_PUBLIC, 0xD, 0x0 },
+	{ "GFRM100", BDADDR_BREDR, 0x58, 0x2000 },
+	{ "GFRM200", BDADDR_LE_PUBLIC, 0x471, 0x2210 },
+	{ "HID AdvRemote", BDADDR_LE_PUBLIC, 0xD, 0x0 },
 };
 
-static struct gfrm_device *gfrm_find_dev_by_vid_pid(uint16_t vid, uint16_t pid)
+static struct gfrm_device *gfrm_find_dev_by_bdaddr_type(uint8_t bdaddr_type)
 {
 	uint16_t i;
 
 	for (i = 0; i < G_N_ELEMENTS(gfrm_devs); ++i) {
-		if (vid == gfrm_devs[i].vid && pid == gfrm_devs[i].pid) {
+		if (bdaddr_type == gfrm_devs[i].bdaddr_type) {
 			return &gfrm_devs[i];
 		}
 	}
@@ -66,15 +65,12 @@
 	return NULL;
 }
 
-static struct gfrm_device *gfrm_find_dev_by_oui(uint8_t oui0, uint8_t oui1,
-								uint8_t oui2)
+static struct gfrm_device *gfrm_find_dev_by_vid_pid(uint16_t vid, uint16_t pid)
 {
 	uint16_t i;
 
 	for (i = 0; i < G_N_ELEMENTS(gfrm_devs); ++i) {
-		if (oui0 == gfrm_devs[i].oui[0] &&
-		    oui1 == gfrm_devs[i].oui[1] &&
-		    oui2 == gfrm_devs[i].oui[2]) {
+		if (vid == gfrm_devs[i].vid && pid == gfrm_devs[i].pid) {
 			return &gfrm_devs[i];
 		}
 	}
@@ -143,7 +139,8 @@
 				gpointer data)
 {
 	int fd;
-	bdaddr_t bdaddr_be;
+	uint8_t bdaddr_and_type[7] = { 0 };
+	uint8_t bdaddr_type;
 	bdaddr_t bdaddr;
 	char bdaddr_str[18];
 	struct gfrm_device *gfrm_dev;
@@ -162,15 +159,16 @@
 	/* Read BD address from FIFO */
 	fd = g_io_channel_unix_get_fd(io);
 
-	if (read(fd, &bdaddr_be, sizeof(bdaddr_be)) != 6) {
+	if (read(fd, &bdaddr_and_type, sizeof(bdaddr_and_type)) != 7) {
 		DBG("read failed");
 		goto reopen;
 	}
 
-	baswap(&bdaddr, &bdaddr_be);
+	bdaddr_type = bdaddr_and_type[6];
+	baswap(&bdaddr, &bdaddr_and_type);
 	ba2str(&bdaddr, bdaddr_str);
 
-	gfrm_dev = gfrm_find_dev_by_oui(bdaddr.b[5], bdaddr.b[4], bdaddr.b[3]);
+	gfrm_dev = gfrm_find_dev_by_bdaddr_type(bdaddr_type);
 	if (!gfrm_dev)
 		goto reopen;
 
@@ -183,13 +181,13 @@
 		goto reopen;
 	}
 
-	device = btd_adapter_find_device(adapter, &bdaddr, gfrm_dev->bdaddr_type);
+	device = btd_adapter_find_device(adapter, &bdaddr, bdaddr_type);
 	if (device) {
 		btd_device_set_temporary(device, TRUE);
 		btd_adapter_remove_device(adapter, device);
 	}
 
-	device = btd_adapter_get_device(adapter, &bdaddr, gfrm_dev->bdaddr_type);
+	device = btd_adapter_get_device(adapter, &bdaddr, bdaddr_type);
 	btd_device_device_set_name(device, gfrm_dev->name);
 	btd_device_set_pnpid(device, 0x1, gfrm_dev->vid, gfrm_dev->pid, 0x0);
 	btd_device_set_temporary(device, FALSE);
diff --git a/test/gfiber-agent b/test/gfiber-agent
index 87fe9d2..f3cf142 100755
--- a/test/gfiber-agent
+++ b/test/gfiber-agent
@@ -23,8 +23,6 @@
 DEV_NAME_GFRM100 = 'GFRM100'
 DEV_NAME_GFRM200 = 'GFRM200'
 DEV_NAME_TIARC = 'HID AdvRemote'
-DEV_OUI_GFRM100 = '00:24:1C'
-DEV_OUI_GFRM200 = '88:33:14'
 DEV_OUI_TIARC = '90:59:AF'
 
 bus = None
@@ -130,8 +128,6 @@
 	if (name == DEV_NAME_GFRM100 or
 	    name == DEV_NAME_GFRM200 or
 	    name == DEV_NAME_TIARC or
-	    addr.startswith(DEV_OUI_GFRM100) or
-	    addr.startswith(DEV_OUI_GFRM200) or
 	    addr.startswith(DEV_OUI_TIARC)):
 		print("Pair with  %s [%s] [%s]" % (path, addr, name))
 		dev_pair_and_connect(path)