From d70849d9b843793034d89e50638cb7359c34d07c Mon Sep 17 00:00:00 2001 From: Olivier Guiter Date: Mon, 22 Oct 2012 15:52:53 +0200 Subject: [PATCH] handover: Change carriers type to bitfield This would allow multiple carriers at the same time (e.g. Bluetooth and Wifi) --- include/ndef.h | 11 ++++++----- plugins/handover.c | 2 +- src/ndef.c | 30 +++++++++++++++++------------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/include/ndef.h b/include/ndef.h index 943811c..fdc5006 100644 --- a/include/ndef.h +++ b/include/ndef.h @@ -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, diff --git a/plugins/handover.c b/plugins/handover.c index 67506b5..10f7be6 100644 --- a/plugins/handover.c +++ b/plugins/handover.c @@ -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; diff --git a/src/ndef.c b/src/ndef.c index d48a36a..9168cd1 100644 --- a/src/ndef.c +++ b/src/ndef.c @@ -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; } -- 2.7.4