handover: Change carriers type to bitfield
authorOlivier Guiter <olivier.guiter@linux.intel.com>
Mon, 22 Oct 2012 13:52:53 +0000 (15:52 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 24 Oct 2012 15:50:14 +0000 (17:50 +0200)
This would allow multiple carriers at the same time (e.g. Bluetooth
and Wifi)

include/ndef.h
plugins/handover.c
src/ndef.c

index 943811c..fdc5006 100644 (file)
@@ -32,10 +32,11 @@ struct near_ndef_message {
        uint8_t *data;
 };
 
-enum near_ndef_handover_carrier {
-       NEAR_CARRIER_BLUETOOTH,
-       NEAR_CARRIER_WIFI,
-};
+/* near_ndef_handover_carrier*/
+#define                NEAR_CARRIER_EMPTY      0x00
+#define                NEAR_CARRIER_BLUETOOTH  0x01    /* bit 0 */
+#define                NEAR_CARRIER_WIFI       0x02    /* bit 1 */
+#define                NEAR_CARRIER_UNKNOWN    0x80    /* Bit 7 */
 
 int near_ndef_count_records(uint8_t *ndef_in, size_t ndef_in_length,
                                                uint8_t record_type);
@@ -54,7 +55,7 @@ struct near_ndef_message *near_ndef_prepare_uri_record(uint8_t identifier,
 
 struct near_ndef_message *near_ndef_prepare_handover_record(char* type_name,
                                                struct near_ndef_record *record,
-                                               enum near_ndef_handover_carrier carrier);
+                                               uint8_t carriers);
 
 struct near_ndef_message *
 near_ndef_prepare_smartposter_record(uint8_t uri_identifier,
index 67506b5..10f7be6 100644 (file)
@@ -141,7 +141,7 @@ static int handover_ndef_parse(int client_fd, struct hr_ndef *ndef)
                 * We build the Hs based on it.
                 */
                msg = near_ndef_prepare_handover_record("Hs", records->data,
-                                                       NEAR_CARRIER_BLUETOOTH);
+                                                       NEAR_CARRIER_UNKNOWN);
                if (msg == NULL) {
                        err = -EINVAL;
                        goto fail;
index d48a36a..9168cd1 100644 (file)
@@ -1683,7 +1683,8 @@ fail:
  */
 struct near_ndef_message *near_ndef_prepare_handover_record(char* type_name,
                                        struct near_ndef_record *record,
-                                       enum near_ndef_handover_carrier carrier)
+                                       uint8_t carriers)
+
 {
        uint8_t *oob_data = NULL;
        int oob_size;
@@ -1718,8 +1719,7 @@ struct near_ndef_message *near_ndef_prepare_handover_record(char* type_name,
        if (ac_msg == NULL)
                goto fail;
 
-       switch (carrier) {
-       case NEAR_CARRIER_BLUETOOTH:
+       if (carriers & NEAR_CARRIER_BLUETOOTH) {
                /* Retrieve the bluetooth settings */
                oob_data = __near_bluetooth_local_get_properties(&oob_size);
                if (oob_data == NULL) {
@@ -1733,10 +1733,10 @@ struct near_ndef_message *near_ndef_prepare_handover_record(char* type_name,
                        goto fail;
 
                near_ndef_set_mb_me(bt_msg->data, FALSE, TRUE);
+       }
 
-               break;
-
-       case NEAR_CARRIER_WIFI:
+       if (carriers & NEAR_CARRIER_WIFI) {
+               /* TODO LATER */
                goto fail;
        }
 
@@ -1763,8 +1763,10 @@ struct near_ndef_message *near_ndef_prepare_handover_record(char* type_name,
         */
        hs_msg->data[NDEF_PAYLOAD_LENGTH_OFFSET] = hs_length;
 
-       /* Fill the message .... */
-       near_ndef_set_mb_me(hs_msg->data, TRUE, FALSE);
+       if (carriers == NEAR_CARRIER_EMPTY)
+               near_ndef_set_mb_me(hs_msg->data, TRUE, TRUE);
+       else
+               near_ndef_set_mb_me(hs_msg->data, TRUE, FALSE);
 
        /* Add version */
        hs_msg->data[hs_msg->offset++] = HANDOVER_VERSION;
@@ -2752,7 +2754,7 @@ static struct near_ndef_ac_payload *build_ho_local_ac_record(void)
 static struct near_ndef_message *build_ho_record(DBusMessage *msg)
 {
        char *carrier_type = NULL;
-       enum near_ndef_handover_carrier carrier;
+       uint8_t carrier;
        struct near_ndef_record *record = NULL;
 
        DBG("");
@@ -2763,11 +2765,13 @@ static struct near_ndef_message *build_ho_record(DBusMessage *msg)
                return NULL;
        }
 
+       carrier = NEAR_CARRIER_EMPTY;
        if (g_strcmp0(carrier_type, "bluetooth") == 0)
-               carrier = NEAR_CARRIER_BLUETOOTH;
-       else if (g_strcmp0(carrier_type, "wifi") == 0)
-               carrier = NEAR_CARRIER_WIFI;
-       else {
+               carrier |= NEAR_CARRIER_BLUETOOTH;
+       if (g_strcmp0(carrier_type, "wifi") == 0)
+               carrier |= NEAR_CARRIER_WIFI;
+
+       if (carrier == NEAR_CARRIER_EMPTY) {
                DBG("Invalid carrier name");
                return NULL;
        }