bluetooth: Add pairing flag on parsing
authorOlivier Guiter <olivier.guiter@linux.intel.com>
Mon, 14 May 2012 12:36:34 +0000 (12:36 +0000)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 14 May 2012 16:36:29 +0000 (18:36 +0200)
The action flag allows a simple "parse oob data" or a "parse and
pair the devices" call.

src/bluetooth.c
src/ndef.c
src/near.h

index e8a13e6..0b84192 100644 (file)
@@ -334,17 +334,6 @@ cb_fail:
        return;
 }
 
-static int bt_get_default_adapter(DBusConnection *conn,
-                                       struct near_oob_data *oob)
-{
-       DBG("");
-
-       return bt_generic_call(bt_conn, oob, BLUEZ_SERVICE,
-                       MANAGER_PATH, MANAGER_INTF, "DefaultAdapter",
-                       bt_get_default_adapter_cb,
-                       DBUS_TYPE_INVALID);
-}
-
 static int bt_refresh_adapter_props(DBusConnection *conn, void *user_data)
 {
        DBG("%p %p", conn, user_data);
@@ -442,13 +431,13 @@ static void bt_parse_eir(uint8_t *ptr, uint16_t bt_oob_data_size,
  * Some specifications are proprietary (eg. "short mode")
  * and are not fully documented.
  */
-int __near_bt_parse_oob_record(uint8_t version, uint8_t *bt_data)
+int __near_bluetooth_parse_oob_record(uint8_t version, uint8_t *bt_data,
+               near_bool_t pair)
 {
        struct near_oob_data *oob;
        uint16_t bt_oob_data_size;
        uint8_t *ptr = bt_data;
        uint8_t marker;
-       int err;
        char *tmp;
 
        DBG("");
@@ -511,15 +500,33 @@ int __near_bt_parse_oob_record(uint8_t version, uint8_t *bt_data)
                return -EINVAL;
        }
 
+       if (pair == FALSE)
+               return 0;
+
        /* check and get the default adapter */
-       err = bt_get_default_adapter(bt_conn, oob);
-       if (err  < 0) {
-               near_error("bt_get_default_adapter failed: %d", err);
+       oob->def_adapter = g_strdup(bt_def_oob_data.def_adapter);
+       if (oob->bt_name == NULL) {
+               near_error("bt_get_default_adapter failed");
                bt_eir_free(oob);
-               return err;
+               return -EIO;
        }
 
-       return 0;
+       return  bt_do_pairing(oob);
+}
+
+int __near_bluetooth_pair(void *data)
+{
+       struct near_oob_data *oob = data;
+
+       /* check and get the default adapter */
+       oob->def_adapter = g_strdup(bt_def_oob_data.def_adapter);
+       if (oob->bt_name == NULL) {
+               near_error("bt_get_default_adapter failed: %d", -EIO);
+               bt_eir_free(oob);
+               return -EIO;
+       }
+
+       return bt_do_pairing(oob);
 }
 
 /* This function is synchronous as oob datas change on each session */
index 125d563..87d82ec 100644 (file)
@@ -1194,11 +1194,11 @@ parse_mime_type(struct near_ndef_record *record,
 
        DBG("MIME Type  '%s'", mime->type);
        if (strcmp(mime->type, "application/vnd.bluetooth.ep.oob") == 0) {
-               err = __near_bt_parse_oob_record(BT_MIME_V2_1,
-                               &ndef_data[offset]);
+               err = __near_bluetooth_parse_oob_record(BT_MIME_V2_1,
+                               &ndef_data[offset], TRUE);
        } else if (strcmp(mime->type, "nokia.com:bt") == 0) {
-               err = __near_bt_parse_oob_record(BT_MIME_V2_0,
-                               &ndef_data[offset]);
+               err = __near_bluetooth_parse_oob_record(BT_MIME_V2_0,
+                               &ndef_data[offset], TRUE);
        }
 
        if (err < 0) {
index 6f30a85..52e0aeb 100644 (file)
@@ -161,5 +161,7 @@ void __near_plugin_cleanup(void);
 
 int __near_bluetooth_init(void);
 void __near_bluetooth_cleanup(void);
-int __near_bt_parse_oob_record(uint8_t version, uint8_t *bt_data);
+int __near_bluetooth_parse_oob_record(uint8_t version, uint8_t *bt_data,
+                                                       near_bool_t pair);
+int __near_bluetooth_pair(void *data);
 uint8_t *__near_bluetooth_local_get_properties(int *bt_data_len);