snep: SNEP core moved from plugins to core
authorMarcin Małagowski <marcin.malagowski@mobica.com>
Sun, 17 Mar 2013 12:59:51 +0000 (13:59 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 20 Mar 2013 00:35:25 +0000 (01:35 +0100)
This is needed for implementing SNEP unit tests.

Makefile.am
Makefile.plugins
include/snep.h [moved from plugins/snep-core.h with 53% similarity]
include/tlv.h
plugins/p2p.c
plugins/p2p.h
plugins/snep-validation.c
plugins/snep.c
src/main.c
src/near.h
src/snep.c [moved from plugins/snep-core.c with 87% similarity]

index c5d76a8..a276ed3 100644 (file)
@@ -6,7 +6,7 @@ includedir = @includedir@/near
 include_HEADERS = include/types.h include/log.h include/plugin.h \
                        include/tag.h include/adapter.h include/ndef.h \
                        include/tlv.h include/setting.h include/device.h \
-                       include/nfc_copy.h
+                       include/nfc_copy.h include/snep.h
 
 nodist_include_HEADERS = include/version.h
 
@@ -38,7 +38,7 @@ src_neard_SOURCES = $(gdbus_sources) $(gweb_sources) $(builtin_sources) \
                        src/main.c src/error.c src/near.h src/log.c \
                        src/dbus.c src/manager.c src/adapter.c src/device.c \
                        src/tag.c src/plugin.c src/netlink.c src/ndef.c \
-                       src/tlv.c src/bluetooth.c src/agent.c
+                       src/tlv.c src/bluetooth.c src/agent.c src/snep.c
 
 src_neard_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @NETLINK_LIBS@ -lresolv -ldl
 
index 3ca1118..1207318 100644 (file)
@@ -26,7 +26,6 @@ endif
 if P2P
 builtin_modules += p2p
 builtin_sources += plugins/p2p.c plugins/npp.c \
-                               plugins/snep-core.c plugins/snep-core.h \
                                plugins/snep.c \
                                plugins/snep-validation.c \
                                plugins/handover.c plugins/p2p.h
similarity index 53%
rename from plugins/snep-core.h
rename to include/snep.h
index 08569d4..cdb9e65 100644 (file)
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
-#define SNEP_VERSION           0x10
-#define SNEP_MAJOR(version) (((version) >> 4) & 0xf)
-#define SNEP_MINOR(version) ((version) & 0xf)
 
-#define SNEP_MSG_SIZE                  0x06
-#define SNEP_ACCEPTABLE_LENGTH         1024
-#define SNEP_ACC_LENGTH_SIZE           4
+#ifndef __NEAR_SNEP_CORE_H
+#define __NEAR_SNEP_CORE_H
+
+#include <near/device.h>
+
+#define NEAR_SNEP_VERSION              0x10
+#define NEAR_SNEP_MAJOR(version) (((version) >> 4) & 0xf)
+#define NEAR_SNEP_MINOR(version) ((version) & 0xf)
+
+#define NEAR_SNEP_MSG_SIZE                     0x06
+#define NEAR_SNEP_ACCEPTABLE_LENGTH            1024
+#define NEAR_SNEP_ACC_LENGTH_SIZE              4
 
 /* Request codes */
-#define SNEP_REQ_CONTINUE 0x00
-#define SNEP_REQ_GET      0x01
-#define SNEP_REQ_PUT      0x02
-#define SNEP_REQ_REJECT   0x7f
+#define NEAR_SNEP_REQ_CONTINUE 0x00
+#define NEAR_SNEP_REQ_GET      0x01
+#define NEAR_SNEP_REQ_PUT      0x02
+#define NEAR_SNEP_REQ_REJECT   0x7f
 
 /* Response codes */
-#define SNEP_RESP_CONTINUE  0x80
-#define SNEP_RESP_SUCCESS   0x81
-#define SNEP_RESP_NOT_FOUND 0xc0
-#define SNEP_RESP_EXCESS    0xc1
-#define SNEP_RESP_BAD_REQ   0xc2
-#define SNEP_RESP_NOT_IMPL  0xe0
-#define SNEP_RESP_VERSION   0xe1
-#define SNEP_RESP_REJECT    0xff
-
-#define SNEP_REQ_PUT_HEADER_LENGTH     6
-#define SNEP_REQ_GET_HEADER_LENGTH     10
+#define NEAR_SNEP_RESP_CONTINUE  0x80
+#define NEAR_SNEP_RESP_SUCCESS   0x81
+#define NEAR_SNEP_RESP_NOT_FOUND 0xc0
+#define NEAR_SNEP_RESP_EXCESS    0xc1
+#define NEAR_SNEP_RESP_BAD_REQ   0xc2
+#define NEAR_SNEP_RESP_NOT_IMPL  0xe0
+#define NEAR_SNEP_RESP_VERSION   0xe1
+#define NEAR_SNEP_RESP_REJECT    0xff
+
+#define NEAR_SNEP_REQ_PUT_HEADER_LENGTH        6
+#define NEAR_SNEP_REQ_GET_HEADER_LENGTH        10
 
 /* Default SNEP Resp message header length: Version + code + len */
-#define SNEP_RESP_HEADER_LENGTH                (1 + 1 + 4)
+#define NEAR_SNEP_RESP_HEADER_LENGTH           (1 + 1 + 4)
 
 /* Offset of 'H' in Android frame: 3 is the offset in NDEF */
-#define SNEP_REQ_ANDROID               (SNEP_ACC_LENGTH_SIZE + 3)
+#define NEAR_SNEP_REQ_ANDROID          (NEAR_SNEP_ACC_LENGTH_SIZE + 3)
 
 
 /* TODO: Right now it is dummy, need to get correct value
  * from lower layers */
-#define SNEP_REQ_MAX_FRAGMENT_LENGTH 128
+#define NEAR_SNEP_REQ_MAX_FRAGMENT_LENGTH 128
 
 typedef near_bool_t (*near_server_io) (int client_fd, void *snep_data);
 
@@ -70,26 +76,22 @@ struct p2p_snep_data {
        struct p2p_snep_put_req_data *req;
 };
 
-near_bool_t snep_core_read(int client_fd,
+near_bool_t near_snep_core_read(int client_fd,
                                uint32_t adapter_idx, uint32_t target_idx,
                                near_tag_io_cb cb,
                                near_server_io req_get,
                                near_server_io req_put);
 
-int snep_core_push(int fd, uint32_t adapter_idx, uint32_t target_idx,
+int near_snep_core_push(int fd, uint32_t adapter_idx, uint32_t target_idx,
                                                struct near_ndef_message *ndef,
                                                near_device_io_cb cb);
 
-void snep_core_close(int client_fd, int err);
+void near_snep_core_close(int client_fd, int err);
 
-void snep_core_response_noinfo(int client_fd, uint8_t response);
-void snep_core_response_with_info(int client_fd, uint8_t response,
+void near_snep_core_response_noinfo(int client_fd, uint8_t response);
+void near_snep_core_response_with_info(int client_fd, uint8_t response,
                                                uint8_t *data, int length);
-void snep_core_parse_handover_record(int client_fd, uint8_t *ndef,
+void near_snep_core_parse_handover_record(int client_fd, uint8_t *ndef,
                                                uint32_t nfc_data_length);
-int snep_init(void);
-void snep_exit(void);
-
-int snep_validation_init(void);
-void snep_validation_exit(void);
 
+#endif
index 2142512..b4db3ea 100644 (file)
@@ -29,6 +29,8 @@
 #define TLV_PROP 0xfd
 #define TLV_END  0xfe
 
+#define TLV_SIZE 2
+
 uint16_t near_tlv_length(uint8_t *tlv);
 uint8_t *near_tlv_next(uint8_t *tlv);
 uint8_t *near_tlv_data(uint8_t *tlv);
index a32c39c..378db87 100644 (file)
@@ -396,7 +396,8 @@ static int p2p_init(void)
        DBG("");
 
        npp_init();
-       snep_core_init();
+       snep_init();
+       snep_validation_init();
        handover_init();
 
        return near_device_driver_register(&p2p_driver);
@@ -408,7 +409,8 @@ static void p2p_exit(void)
 
        g_list_free_full(server_list, free_server_data);
 
-       snep_core_exit();
+       snep_exit();
+       snep_validation_exit();
        npp_exit();
        handover_exit();
 
index ceb5a77..0b5349c 100644 (file)
@@ -35,16 +35,17 @@ struct near_p2p_driver {
        void (*close)(int client_fd, int err);
 };
 
-#define TLV_SIZE 2
-
 int npp_init(void);
 void npp_exit(void);
 
-int snep_core_init(void);
-void snep_core_exit(void);
-
 int handover_init(void);
 void handover_exit(void);
 
+int snep_init(void);
+void snep_exit(void);
+
+int snep_validation_init(void);
+void snep_validation_exit(void);
+
 int near_p2p_register(struct near_p2p_driver *driver);
 void near_p2p_unregister(struct near_p2p_driver *driver);
index d64e30c..2094630 100644 (file)
@@ -38,9 +38,9 @@
 #include <near/device.h>
 #include <near/ndef.h>
 #include <near/tlv.h>
+#include <near/snep.h>
 
 #include "p2p.h"
-#include "snep-core.h"
 
 /* Would store incoming ndefs per client */
 static GHashTable *snep_validation_hash = NULL;
@@ -102,12 +102,12 @@ static near_bool_t snep_validation_server_req_put(int client_fd, void *data)
                                                        incoming_ndefs);
 
 
-       snep_core_response_noinfo(client_fd, SNEP_RESP_SUCCESS);
+       near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_SUCCESS);
 
        return TRUE;
 
 error:
-       snep_core_response_noinfo(client_fd, SNEP_RESP_REJECT);
+       near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_REJECT);
 
        return TRUE;
 }
@@ -134,8 +134,8 @@ static near_bool_t snep_validation_server_req_get(int client_fd, void *data)
         * 1 record (a mime type !) with an ID
         */
        records = near_ndef_parse_msg(snep_data->nfc_data +
-                       SNEP_ACC_LENGTH_SIZE,
-                       snep_data->nfc_data_length - SNEP_ACC_LENGTH_SIZE,
+                       NEAR_SNEP_ACC_LENGTH_SIZE,
+                       snep_data->nfc_data_length - NEAR_SNEP_ACC_LENGTH_SIZE,
                        NULL);
 
        if (g_list_length(records) != 1) {
@@ -150,7 +150,7 @@ static near_bool_t snep_validation_server_req_get(int client_fd, void *data)
        }
 
        /* check if the acceptable length is higher than the data_len
-        * otherwise returns a SNEP_RESP_EXCESS
+        * otherwise returns a NEAR_SNEP_RESP_EXCESS
         */
        acceptable_length = GUINT32_FROM_BE(*(uint32_t *)snep_data->nfc_data);
 
@@ -175,8 +175,8 @@ static near_bool_t snep_validation_server_req_get(int client_fd, void *data)
 
                /* Found a record, check the length */
                if (acceptable_length >= near_ndef_data_length(rec_store)) {
-                       snep_core_response_with_info(client_fd,
-                                       SNEP_RESP_SUCCESS,
+                       near_snep_core_response_with_info(client_fd,
+                                       NEAR_SNEP_RESP_SUCCESS,
                                        near_ndef_data_ptr(rec_store),
                                        near_ndef_data_length(rec_store));
 
@@ -191,19 +191,19 @@ static near_bool_t snep_validation_server_req_get(int client_fd, void *data)
                                                        incoming_ndefs);
 
                } else
-                       snep_core_response_noinfo(client_fd, SNEP_RESP_EXCESS);
+                       near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_EXCESS);
 
                return TRUE;
        }
 
 done:
        /* If not found */
-       snep_core_response_noinfo(client_fd, SNEP_RESP_NOT_FOUND);
+       near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_NOT_FOUND);
        return TRUE;
 
 error:
         /* Not found */
-       snep_core_response_noinfo(client_fd, SNEP_RESP_REJECT);
+       near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_REJECT);
        return FALSE;
 }
 
@@ -214,7 +214,7 @@ static near_bool_t snep_validation_read(int client_fd, uint32_t adapter_idx,
 {
        DBG("");
 
-       return snep_core_read(client_fd, adapter_idx, target_idx, cb,
+       return near_snep_core_read(client_fd, adapter_idx, target_idx, cb,
                                                snep_validation_server_req_get,
                                                snep_validation_server_req_put);
 
@@ -227,7 +227,7 @@ static void snep_validation_close(int client_fd, int err)
        g_hash_table_remove(snep_validation_hash, GINT_TO_POINTER(client_fd));
 
        /* Call core server close */
-       snep_core_close(client_fd, err);
+       near_snep_core_close(client_fd, err);
 }
 
 struct near_p2p_driver validation_snep_driver = {
@@ -235,7 +235,7 @@ struct near_p2p_driver validation_snep_driver = {
        .service_name = "urn:nfc:xsn:nfc-forum.org:snep-validation",
        .fallback_service_name = NULL,
        .read = snep_validation_read,
-       .push = snep_core_push,
+       .push = near_snep_core_push,
        .close = snep_validation_close,
 };
 
index 6e6ba5f..4cb4f7c 100644 (file)
@@ -38,9 +38,9 @@
 #include <near/device.h>
 #include <near/ndef.h>
 #include <near/tlv.h>
+#include <near/snep.h>
 
 #include "p2p.h"
-#include "snep-core.h"
 
 /*
  * This is the Default server REQ PUT function.
@@ -57,7 +57,7 @@ static near_bool_t snep_default_server_req_put(int client_fd, void *data)
        DBG("");
 
        /* The request is ok, so we notify the client */
-       snep_core_response_noinfo(client_fd, SNEP_RESP_SUCCESS);
+       near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_SUCCESS);
 
        /* On PUT request, we add the data */
        if (near_device_add_data(snep_data->adapter_idx,
@@ -81,7 +81,7 @@ static near_bool_t snep_default_server_req_put(int client_fd, void *data)
 
 /*
  * This is the Default server REQ GET function.
- * On REQ GET, server should return SNEP_RESP_NOT_IMPL.
+ * On REQ GET, server should return NEAR_SNEP_RESP_NOT_IMPL.
  *
  * !!! We check if the incoming NDEF looks like a handover frame,
  * because of Android 4.1.1 ...
@@ -98,13 +98,13 @@ static near_bool_t snep_default_server_req_get(int client_fd, void *data)
         * and we check the 3 byte in the NDEF message
         * */
 
-       if (*(snep_data->nfc_data + SNEP_REQ_ANDROID) != 'H') {
-               snep_core_response_noinfo(client_fd, SNEP_RESP_NOT_IMPL);
+       if (*(snep_data->nfc_data + NEAR_SNEP_REQ_ANDROID) != 'H') {
+               near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_NOT_IMPL);
        } else {
-               snep_core_parse_handover_record(client_fd, snep_data->nfc_data +
-                                               SNEP_ACC_LENGTH_SIZE,
+               near_snep_core_parse_handover_record(client_fd, snep_data->nfc_data +
+                                               NEAR_SNEP_ACC_LENGTH_SIZE,
                                                snep_data->nfc_data_length -
-                                               SNEP_ACC_LENGTH_SIZE);
+                                               NEAR_SNEP_ACC_LENGTH_SIZE);
        }
 
        return TRUE;
@@ -117,7 +117,7 @@ static near_bool_t snep_default_read(int client_fd, uint32_t adapter_idx,
 {
        DBG("");
 
-       return snep_core_read(client_fd, adapter_idx, target_idx, cb,
+       return near_snep_core_read(client_fd, adapter_idx, target_idx, cb,
                                                snep_default_server_req_get,
                                                snep_default_server_req_put);
 
@@ -128,8 +128,8 @@ struct near_p2p_driver snep_driver = {
        .service_name = NEAR_DEVICE_SN_SNEP,
        .fallback_service_name = NEAR_DEVICE_SN_NPP,
        .read = snep_default_read,
-       .push = snep_core_push,
-       .close = snep_core_close,
+       .push = near_snep_core_push,
+       .close = near_snep_core_close,
 };
 
 int snep_init(void)
index 32934c3..a121f63 100644 (file)
@@ -211,6 +211,7 @@ int main(int argc, char *argv[])
        __near_device_init();
        __near_adapter_init();
        __near_ndef_init();
+       __near_snep_core_init();
        __near_manager_init(conn);
        __near_agent_init();
        __near_bluetooth_init();
@@ -230,6 +231,7 @@ int main(int argc, char *argv[])
        __near_bluetooth_cleanup();
        __near_manager_cleanup();
        __near_ndef_cleanup();
+       __near_snep_core_cleanup();
        __near_adapter_cleanup();
        __near_device_cleanup();
        __near_tag_cleanup();
index a6401c7..9e89d7c 100644 (file)
@@ -111,6 +111,11 @@ void __near_ndef_append_records(DBusMessageIter *iter, GList *record);
 const char *__near_ndef_get_uri_prefix(uint8_t id);
 struct near_ndef_message *__ndef_build_from_message(DBusMessage *msg);
 
+#include <near/snep.h>
+
+int __near_snep_core_init(void);
+void __near_snep_core_cleanup(void);
+
 #include <near/tag.h>
 
 int __near_tag_init(void);
similarity index 87%
rename from plugins/snep-core.c
rename to src/snep.c
index 558bd86..f57b45a 100644 (file)
 
 #include <near/nfc_copy.h>
 #include <near/plugin.h>
-#include <near/log.h>
 #include <near/types.h>
 #include <near/adapter.h>
 #include <near/device.h>
 #include <near/ndef.h>
 #include <near/tlv.h>
+#include <near/snep.h>
 
-#include "p2p.h"
-#include "snep-core.h"
+#include "near.h"
 
 struct snep_fragment {
        uint32_t len;
@@ -85,13 +84,13 @@ static void free_snep_core_client(gpointer data)
 }
 
 /* Send a short response code */
-void snep_core_response_noinfo(int client_fd, uint8_t response)
+void near_snep_core_response_noinfo(int client_fd, uint8_t response)
 {
        struct p2p_snep_resp_frame resp;
 
        DBG("Response 0x%x", response);
 
-       resp.version = SNEP_VERSION;
+       resp.version = NEAR_SNEP_VERSION;
        resp.response = response;
        resp.length = 0;
 
@@ -99,7 +98,7 @@ void snep_core_response_noinfo(int client_fd, uint8_t response)
 }
 
 /*
- * snep_core_parse_handover_record
+ * near_snep_core_parse_handover_record
  *
  * The hr frame should be here BUT:
  *     The first 4 bytes are the Max Allowed Length
@@ -115,7 +114,7 @@ void snep_core_response_noinfo(int client_fd, uint8_t response)
  *
  * The hack fixes the first issue (bluetooth.c fixes the second) !
  * */
-void snep_core_parse_handover_record(int client_fd, uint8_t *ndef,
+void near_snep_core_parse_handover_record(int client_fd, uint8_t *ndef,
                uint32_t nfc_data_length)
 {
        GList *records;
@@ -145,8 +144,8 @@ void snep_core_parse_handover_record(int client_fd, uint8_t *ndef,
 
        near_info("Send SNEP / Hs frame");
 
-       snep_core_response_with_info(client_fd, SNEP_RESP_SUCCESS, msg->data,
-                                                               msg->length);
+       near_snep_core_response_with_info(client_fd, NEAR_SNEP_RESP_SUCCESS,
+                                                               msg->data, msg->length);
 
        g_free(msg->data);
        g_free(msg);
@@ -189,7 +188,7 @@ static int snep_core_read_ndef(int client_fd,
 
        if (snep_data->respond_continue == FALSE) {
                snep_data->respond_continue = TRUE;
-               snep_core_response_noinfo(client_fd, SNEP_RESP_CONTINUE);
+               near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_CONTINUE);
        }
 
        return 1;
@@ -277,7 +276,7 @@ static int snep_core_push_response(struct p2p_snep_put_req_data *req)
 
        DBG("Response 0x%x %p", frame.response, &frame);
        switch (frame.response) {
-       case SNEP_RESP_CONTINUE:
+       case NEAR_SNEP_RESP_CONTINUE:
                while (g_slist_length(req->fragments) != 0) {
                        err = snep_core_send_fragment(req);
                        if (err < 0)
@@ -286,7 +285,7 @@ static int snep_core_push_response(struct p2p_snep_put_req_data *req)
 
                return frame.response;
 
-       case SNEP_RESP_SUCCESS:
+       case NEAR_SNEP_RESP_SUCCESS:
                if (frame.length == 0)
                        return 0;
 
@@ -308,7 +307,7 @@ static int snep_core_push_response(struct p2p_snep_put_req_data *req)
                        return -EINVAL;
 
                if (strncmp((char *)(ndef + 3), "Hs", 2) == 0)
-                       snep_core_parse_handover_record(req->fd, ndef,
+                       near_snep_core_parse_handover_record(req->fd, ndef,
                                                                ndef_len);
 
                g_free(ndef);
@@ -353,7 +352,7 @@ static int snep_core_push_prepare_fragments(struct p2p_snep_put_req_data *req,
 
        DBG("");
 
-       max_fragment_len = SNEP_REQ_MAX_FRAGMENT_LENGTH;
+       max_fragment_len = NEAR_SNEP_REQ_MAX_FRAGMENT_LENGTH;
 
        while (ndef->offset < ndef->length) {
 
@@ -394,13 +393,13 @@ static near_bool_t snep_core_process_request(int client_fd,
 
        /* Now, we process the request code */
        switch (frame->request) {
-       case SNEP_REQ_PUT:
-               DBG("SNEP_REQ_PUT");
+       case NEAR_SNEP_REQ_PUT:
+               DBG("NEAR_SNEP_REQ_PUT");
                if (req_put != NULL)
                        ret = (*req_put)(client_fd, snep_data);
                else {
-                       snep_core_response_noinfo(client_fd,
-                                                       SNEP_RESP_NOT_IMPL);
+                       near_snep_core_response_noinfo(client_fd,
+                                                       NEAR_SNEP_RESP_NOT_IMPL);
                        ret = TRUE;
                }
 
@@ -409,13 +408,13 @@ static near_bool_t snep_core_process_request(int client_fd,
                                                GINT_TO_POINTER(client_fd));
                break;
 
-       case SNEP_REQ_GET:
-               DBG("SNEP_REQ_GET");
+       case NEAR_SNEP_REQ_GET:
+               DBG("NEAR_SNEP_REQ_GET");
                if (req_get != NULL)
                        ret =  (*req_get)(client_fd, snep_data);
                else {
-                       snep_core_response_noinfo(client_fd,
-                                                       SNEP_RESP_NOT_IMPL);
+                       near_snep_core_response_noinfo(client_fd,
+                                                       NEAR_SNEP_RESP_NOT_IMPL);
                        ret = TRUE;
                }
 
@@ -428,14 +427,14 @@ static near_bool_t snep_core_process_request(int client_fd,
                }
                break;
 
-       case SNEP_REQ_CONTINUE:
+       case NEAR_SNEP_REQ_CONTINUE:
                /*
-                * SNEP_REQ_CONTINUE indicates that we have to send the
+                * NEAR_SNEP_REQ_CONTINUE indicates that we have to send the
                 * remaining fragments...
                 */
-               DBG("SNEP_REQ_CONTINUE");
+               DBG("NEAR_SNEP_REQ_CONTINUE");
                if (snep_data->req->fragments == NULL) {
-                       near_error("error: SNEP_REQ_CONTINUE but no fragment");
+                       near_error("error: NEAR_SNEP_REQ_CONTINUE but no fragment");
                        ret = FALSE;
                        goto leave_cont;
                }
@@ -493,7 +492,7 @@ leave_cont:
  *     missing bytes (llcp removes fragmentation issues)
  *
  */
-near_bool_t snep_core_read(int client_fd,
+near_bool_t near_snep_core_read(int client_fd,
                                uint32_t adapter_idx, uint32_t target_idx,
                                near_tag_io_cb cb,
                                near_server_io req_get,
@@ -525,9 +524,9 @@ near_bool_t snep_core_read(int client_fd,
        }
 
        /* If major is different, send UNSUPPORTED VERSION */
-       if (SNEP_MAJOR(frame.version) != SNEP_MAJOR(SNEP_VERSION)) {
+       if (NEAR_SNEP_MAJOR(frame.version) != NEAR_SNEP_MAJOR(NEAR_SNEP_VERSION)) {
                near_error("Unsupported version (%d)", frame.version);
-               snep_core_response_noinfo(client_fd, SNEP_RESP_VERSION);
+               near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_VERSION);
                return TRUE;
        }
 
@@ -566,8 +565,8 @@ near_bool_t snep_core_read(int client_fd,
                                        GINT_TO_POINTER(client_fd), snep_data);
 
        if (ndef_length > 0) {
-               if ((frame.request == SNEP_REQ_GET) ||
-                               (frame.request == SNEP_REQ_PUT)) {
+               if ((frame.request == NEAR_SNEP_REQ_GET) ||
+                               (frame.request == NEAR_SNEP_REQ_PUT)) {
                        /* We should read the missing bytes */
                        snep_core_read_ndef(client_fd, snep_data);
                }
@@ -589,7 +588,7 @@ jumptocontinue:
  * > 0 if there's still some fragments
  *
  */
-static int snep_core_response(int fd, struct p2p_snep_put_req_data *req,
+static int near_snep_core_response(int fd, struct p2p_snep_put_req_data *req,
                uint8_t resp_code, struct near_ndef_message *ndef)
 {
        struct p2p_snep_req_frame header;
@@ -601,14 +600,14 @@ static int snep_core_response(int fd, struct p2p_snep_put_req_data *req,
 
        DBG("resp: 0x%02X", resp_code);
 
-       max_fragment_len = SNEP_REQ_MAX_FRAGMENT_LENGTH;
-       header.version = SNEP_VERSION;
+       max_fragment_len = NEAR_SNEP_REQ_MAX_FRAGMENT_LENGTH;
+       header.version = NEAR_SNEP_VERSION;
 
-       if (resp_code == SNEP_REQ_GET) {        /* Get for android */
-               snep_req_header_length = SNEP_REQ_GET_HEADER_LENGTH;
+       if (resp_code == NEAR_SNEP_REQ_GET) {   /* Get for android */
+               snep_req_header_length = NEAR_SNEP_REQ_GET_HEADER_LENGTH;
                snep_additional_length = 4;     /* 4 Acceptable Length */
        } else {
-               snep_req_header_length = SNEP_REQ_PUT_HEADER_LENGTH;
+               snep_req_header_length = NEAR_SNEP_REQ_PUT_HEADER_LENGTH;
                snep_additional_length = 0;
        }
 
@@ -638,12 +637,12 @@ static int snep_core_response(int fd, struct p2p_snep_put_req_data *req,
        }
 
        /* Header to data - common header */
-       memcpy(fragment->data, (uint8_t *)&header, SNEP_REQ_PUT_HEADER_LENGTH);
+       memcpy(fragment->data, (uint8_t *)&header, NEAR_SNEP_REQ_PUT_HEADER_LENGTH);
 
        /* if GET, we add the Acceptable length */
-       if (header.request == SNEP_REQ_GET)
+       if (header.request == NEAR_SNEP_REQ_GET)
                near_put_be32(snep_req_header_length,
-                               fragment->data + SNEP_REQ_PUT_HEADER_LENGTH);
+                               fragment->data + NEAR_SNEP_REQ_PUT_HEADER_LENGTH);
 
        if (fragmenting == TRUE) {
                memcpy(fragment->data + snep_req_header_length, ndef->data,
@@ -681,7 +680,7 @@ error:
        return err;
 }
 
-void snep_core_response_with_info(int client_fd, uint8_t response,
+void near_snep_core_response_with_info(int client_fd, uint8_t response,
                                uint8_t *data, int length)
 {
        struct p2p_snep_data *snep_data;
@@ -734,7 +733,7 @@ void snep_core_response_with_info(int client_fd, uint8_t response,
        req->cb = snep_data->cb;
 
        /* send it !*/
-       snep_core_response(client_fd, req, response, ndef);
+       near_snep_core_response(client_fd, req, response, ndef);
 
 done:
        /* If no fragment, free mem */
@@ -751,7 +750,7 @@ done:
 }
 
 /* SNEP Core: on P2P push */
-int snep_core_push(int fd, uint32_t adapter_idx, uint32_t target_idx,
+int near_snep_core_push(int fd, uint32_t adapter_idx, uint32_t target_idx,
                        struct near_ndef_message *ndef,
                        near_device_io_cb cb)
 {
@@ -782,11 +781,11 @@ int snep_core_push(int fd, uint32_t adapter_idx, uint32_t target_idx,
 
        /* Check if Hr or Hs for Handover over SNEP */
        if (*(char *)(ndef->data + 3) == 'H')
-               resp_code = SNEP_REQ_GET;               /* Get for android */
+               resp_code = NEAR_SNEP_REQ_GET;          /* Get for android */
        else
-               resp_code = SNEP_REQ_PUT;
+               resp_code = NEAR_SNEP_REQ_PUT;
 
-       return snep_core_response(fd, req, resp_code, ndef);
+       return near_snep_core_response(fd, req, resp_code, ndef);
 
 error:
        free_snep_core_push_data(req, err);
@@ -796,7 +795,7 @@ error:
 }
 
 /* SNEP core functions: close */
-void snep_core_close(int client_fd, int err)
+void near_snep_core_close(int client_fd, int err)
 {
        struct p2p_snep_data *snep_data;
 
@@ -812,22 +811,17 @@ void snep_core_close(int client_fd, int err)
        g_hash_table_remove(snep_client_hash, GINT_TO_POINTER(client_fd));
 }
 
-int snep_core_init(void)
+int __near_snep_core_init(void)
 {
        snep_client_hash = g_hash_table_new_full(g_direct_hash,
                                                        g_direct_equal, NULL,
                                                        free_snep_core_client);
-       snep_init();
-       snep_validation_init();
 
        return 0;
 }
 
-void snep_core_exit(void)
+void __near_snep_core_cleanup(void)
 {
-       snep_validation_exit();
-       snep_exit();
-
        g_hash_table_destroy(snep_client_hash);
        snep_client_hash = NULL;
 }