summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRavi kumar Veeramally <ravikumar.veeramally@linux.intel.com>2013-02-28 16:01:42 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2013-02-28 16:55:47 +0100
commit0746381916ff5beeba0b36172186853cfb5383d2 (patch)
tree522644abf224b30cde19e5de385eab2aa5596d67 /src
parent848fb8258f246d3eb5ed7d334bfaeee114014f8a (diff)
downloadneard-0746381916ff5beeba0b36172186853cfb5383d2.tar.gz
neard-0746381916ff5beeba0b36172186853cfb5383d2.tar.bz2
neard-0746381916ff5beeba0b36172186853cfb5383d2.zip
ndef: Add helper funtions to create handover messages
Providing helper functions to create Hanodver select and request messages.
Diffstat (limited to 'src')
-rw-r--r--src/ndef.c187
-rw-r--r--src/near.h13
2 files changed, 194 insertions, 6 deletions
diff --git a/src/ndef.c b/src/ndef.c
index 765b401..9b9082c 100644
--- a/src/ndef.c
+++ b/src/ndef.c
@@ -77,6 +77,8 @@ enum record_tnf {
#define AC_CPS_MASK 0x03
+#define __unused __attribute__ ((unused))
+
enum record_type {
RECORD_TYPE_WKT_SMART_POSTER = 0x01,
RECORD_TYPE_WKT_URI = 0x02,
@@ -144,7 +146,7 @@ struct near_ndef_mime_payload {
char *type;
struct {
- uint8_t carrier_type;
+ enum handover_carrier carrier_type;
uint16_t properties; /* e.g.: NO_PAIRING_KEY */
} handover;
};
@@ -1984,6 +1986,121 @@ fail:
return NULL;
}
+__unused
+static struct near_ndef_message *near_ndef_prepare_cfg_message(char *mime_type,
+ uint8_t *data, int data_len,
+ char cdr, uint8_t cdr_len)
+{
+ struct near_ndef_message *msg = NULL;
+
+ DBG(" %s", mime_type);
+
+ if (mime_type == NULL || data == NULL || data_len <= 0)
+ return NULL;
+
+ msg = ndef_message_alloc_complete(mime_type, data_len, &cdr, cdr_len,
+ RECORD_TNF_MIME, TRUE, TRUE);
+ if (msg == NULL)
+ return NULL;
+
+ /* store data */
+ memcpy(msg->data + msg->offset, data, data_len);
+
+ return msg;
+}
+
+/*
+ * Prepare alternative carrier and configuration records
+ * (e.g. bluetooth or wifi or Hc)
+ */
+__unused
+static int near_ndef_prepare_ac_and_cfg_records(enum handover_carrier carrier,
+ struct near_ndef_message **ac,
+ struct near_ndef_message **cfg,
+ struct near_ndef_mime_payload *mime,
+ struct carrier_data *remote_carrier)
+{
+ struct carrier_data *local_carrier = NULL;
+ char cdr;
+ char *mime_type;
+ uint16_t prop;
+ int err;
+
+ DBG("");
+
+ if (ac == NULL || cfg == NULL)
+ return -EINVAL;
+
+ /* to be safe side */
+ *ac = NULL;
+ *cfg = NULL;
+
+ switch (carrier) {
+ case NEAR_CARRIER_BLUETOOTH:
+ cdr = '0';
+ mime_type = BT_MIME_STRING_2_1;
+ local_carrier = __near_agent_handover_request_data(
+ HO_AGENT_BT, remote_carrier);
+ if (local_carrier != NULL)
+ break;
+
+ prop = (mime != NULL) ? mime->handover.properties :
+ OOB_PROPS_EMPTY;
+ local_carrier = __near_bluetooth_local_get_properties(prop);
+
+ break;
+
+ case NEAR_CARRIER_WIFI:
+ cdr = '1';
+ mime_type = WIFI_WSC_MIME_STRING;
+ local_carrier = __near_agent_handover_request_data(
+ HO_AGENT_WIFI, remote_carrier);
+ break;
+
+ case NEAR_CARRIER_EMPTY:
+ case NEAR_CARRIER_UNKNOWN:
+ err = -EINVAL;
+ goto fail;
+ }
+
+ if (local_carrier == NULL) {
+ DBG("Unable to retrieve local carrier bluetooth data");
+ err = -ESRCH;
+ goto fail;
+ }
+
+ *cfg = near_ndef_prepare_cfg_message(mime_type, local_carrier->data,
+ local_carrier->size, cdr, 1);
+ if (*cfg == NULL) {
+ err = -ENOMEM;
+ goto fail;
+ }
+
+ *ac = near_ndef_prepare_ac_message(local_carrier->state, cdr);
+ if (*ac == NULL) {
+ err = -EINVAL;
+ goto fail;
+ }
+
+ g_free(local_carrier);
+
+ return 0;
+
+fail:
+ g_free(local_carrier);
+ free_ndef_message(*ac);
+ free_ndef_message(*cfg);
+
+ return err;
+}
+
+__unused static void free_ndef_list(gpointer data)
+{
+ struct near_ndef_message *msg = data;
+
+ free_ndef_message(msg);
+}
+
static struct near_ndef_message *prepare_handover_message_header(char *type,
uint32_t msg_len, uint32_t payload_len)
{
@@ -2007,6 +2124,74 @@ static struct near_ndef_message *prepare_handover_message_header(char *type,
return ho_msg;
}
+__unused static uint32_t ndef_message_list_length(GList *list)
+{
+ struct near_ndef_message *msg;
+ uint32_t length = 0;
+
+ if (list == NULL)
+ return 0;
+
+ while (list) {
+ msg = list->data;
+ length += msg->length;
+ list = list->next;
+ }
+
+ return length;
+}
+
+__unused static void copy_ac_records(struct near_ndef_message *ho, GList *acs)
+{
+ GList *temp = acs;
+ struct near_ndef_message *ac;
+
+ if (ho == NULL || temp == NULL)
+ return;
+
+ while (temp) {
+ ac = temp->data;
+ memcpy(ho->data + ho->offset, ac->data, ac->length);
+ /*
+ * AC records are part of handover message payoad,
+ * so modifying offset.
+ */
+ ho->offset += ac->length;
+ temp = temp->next;
+ }
+}
+
+__unused static void copy_cfg_records(struct near_ndef_message *ho, GList *cfgs)
+{
+ GList *temp = cfgs;
+ struct near_ndef_message *cfg;
+ uint32_t offset;
+
+ if (ho == NULL || temp == NULL)
+ return;
+
+ offset = ho->offset;
+
+ while (temp) {
+ cfg = temp->data;
+ memcpy(ho->data + offset, cfg->data, cfg->length);
+ /*
+ * Configuration records (e.g. bt or wifi) records are not part
+ * of handover payoad, they are consecutive ndef msgs. So
+ * here we are not modifying ho->offset.
+ */
+ offset += cfg->length;
+ temp = temp->next;
+ }
+}
+
+__unused static void set_mb_me_to_false(gpointer data, gpointer user_data)
+{
+ struct near_ndef_message *msg = data;
+
+ near_ndef_set_mb_me(msg->data, FALSE, FALSE);
+}
+
static struct near_ndef_message *near_ndef_prepare_empty_hs_message(void)
{
struct near_ndef_message *hs_msg;
diff --git a/src/near.h b/src/near.h
index 8733eb8..91b8567 100644
--- a/src/near.h
+++ b/src/near.h
@@ -166,9 +166,10 @@ void __near_plugin_cleanup(void);
/* NFC Bluetooth Secure Simple Pairing */
#define BT_MIME_V2_0 0
#define BT_MIME_V2_1 1
+#define WIFI_WSC_MIME 2
#define BT_MIME_STRING_2_0 "nokia.com:bt"
#define BT_MIME_STRING_2_1 "application/vnd.bluetooth.ep.oob"
-#define WIFI_MIME_STRING "application/vnd.wfa.wsc"
+#define WIFI_WSC_MIME_STRING "application/vnd.wfa.wsc"
/* Mime specific properties */
#define OOB_PROPS_EMPTY 0x00
@@ -183,10 +184,12 @@ void __near_plugin_cleanup(void);
#define NEAR_HANDOVER_AGENT_WIFI "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 */
+enum handover_carrier {
+ NEAR_CARRIER_EMPTY = 0x00,
+ NEAR_CARRIER_BLUETOOTH = 0x01, /* bit 0 */
+ NEAR_CARRIER_WIFI = 0x02, /* bit 1 */
+ NEAR_CARRIER_UNKNOWN = 0x80, /* Bit 7 */
+};
enum carrier_power_state {
CPS_INACTIVE = 0x00,