diff --git a/src/cntlr.c b/src/cntlr.c index bb857d338e8adbe48cc02be60c17b79897d7db0c..f2d75d829a0404eb8e6b830a95021ba374af4242 100644 --- a/src/cntlr.c +++ b/src/cntlr.c @@ -34,7 +34,9 @@ #include "timer.h" #if (EASYMESH_VERSION > 2) +#ifdef USE_LIBDPP #include <dpp_api.h> +#endif #include "dpp.h" #endif @@ -2192,6 +2194,7 @@ void run_controller(void) #if (EASYMESH_VERSION > 2) { +#ifdef USE_LIBDPP char *argv[] = {"-I", "-C", "-V", "2"}; int argc = 4; int ret; @@ -2205,7 +2208,7 @@ void run_controller(void) dpp_register_cb(c->dpp, dpp_frame_handler); dpp_set_ctx_private_data(c->dpp, c); - +#endif dpp_cntlr_read_uris(c); } #endif diff --git a/src/cntlr_map.c b/src/cntlr_map.c index 6d27189b2cc74864b8455ae56d29b4939cd8155d..6c0c3a9fb5b187a53a063d6e98babb2f5fe18fcc 100644 --- a/src/cntlr_map.c +++ b/src/cntlr_map.c @@ -45,8 +45,9 @@ #include "timer.h" #if (EASYMESH_VERSION > 2) +#ifdef USE_LIBDPP #include <dpp_api.h> - +#endif #include "dpp.h" #include "utils/dpp_sock.h" #endif @@ -960,7 +961,9 @@ int handle_ap_autoconfig_search(void *cntlr, struct cmdu_buff *rx_cmdu, struct tlv_autoconfig_band *freq; struct tlv_aladdr *aladdr; #if (EASYMESH_VERSION > 2) +#ifdef USE_LIBDPP void *event = NULL; +#endif bool hash_known = false; bool hash_validity; uint8_t hashlen; @@ -1080,7 +1083,7 @@ int handle_ap_autoconfig_search(void *cntlr, struct cmdu_buff *rx_cmdu, hash = &tv[6][0]->data[offset]; dump(hash, hashlen, "autoconf search chirp hash"); - +#ifdef USE_LIBDPP hash_known = dpp_is_peer_bootstrap_hash_known(c->dpp, hash, NULL); if (hash_known) { ret = dpp_process_virt_presence_announcement(c->dpp, @@ -1095,6 +1098,7 @@ int handle_ap_autoconfig_search(void *cntlr, struct cmdu_buff *rx_cmdu, } else { err("%s: Hash was not known!\n", __func__); } +#endif } #endif @@ -1117,10 +1121,12 @@ int handle_ap_autoconfig_search(void *cntlr, struct cmdu_buff *rx_cmdu, cmdu_free(cmdu); #if (EASYMESH_VERSION > 2) +#ifdef USE_LIBDPP if (event) { dbg("|%s:%d| Trigger dpp event\n", __func__, __LINE__); dpp_trigger(c->dpp, rx_cmdu->origin, event); } +#endif #endif return !!ret; @@ -3630,6 +3636,7 @@ int handle_direct_encap_dpp(void *cntlr, struct cmdu_buff *cmdu, struct node *n) { trace("%s: --->\n", __func__); +#ifdef USE_LIBDPP struct controller *c = (struct controller *)cntlr; struct tlv *tlv; struct tlv *tlvs[DIRECT_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES][TLV_MAXNUM] = { 0 }; @@ -3695,7 +3702,7 @@ int handle_direct_encap_dpp(void *cntlr, struct cmdu_buff *cmdu, dbg("Unknown frame!\n"); break; } - +#endif //USE_LIBDPPS return 0; } diff --git a/src/cntlr_ubus.c b/src/cntlr_ubus.c index d4afb4cde4f72106f89d4e2cb36d888a3fa575be..84b973d559b8d4d85e30aa544969c82992b4b5e4 100644 --- a/src/cntlr_ubus.c +++ b/src/cntlr_ubus.c @@ -37,7 +37,9 @@ #include "timer.h" #if (EASYMESH_VERSION > 2) +#ifdef USE_LIBDPP #include <dpp_api.h> +#endif #include "dpp.h" #endif @@ -837,6 +839,7 @@ static int cntlr_steer_history(struct ubus_context *ctx, struct ubus_object *obj } #if (EASYMESH_VERSION > 2) +#ifdef USE_LIBDPP static int cntlr_dpp_uri_eth(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) @@ -882,6 +885,7 @@ static int cntlr_dpp_uri_eth(struct ubus_context *ctx, struct ubus_object *obj, return UBUS_STATUS_OK; } +#endif static int cntlr_dpp_uri(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -3587,8 +3591,10 @@ int cntlr_publish_object(struct controller *c, const char *objname) #if (EASYMESH_VERSION > 2) UBUS_METHOD("dpp_enrollee_uri", cntlr_dpp_uri, dpp_uri_params), +#ifdef USE_LIBDPP UBUS_METHOD("dpp_enrollee_uri_eth", cntlr_dpp_uri_eth, dpp_uri_params), +#endif #endif /* DPP */ UBUS_METHOD("steer_summary", cntlr_steer_summary, steer_summary_params), diff --git a/src/config.c b/src/config.c index 01a7a539a2cd8eae40161b0f98d13a0716cf111a..cd02597447865b21854387e47ca1171e41c42f38 100644 --- a/src/config.c +++ b/src/config.c @@ -36,7 +36,9 @@ #include "config.h" #include "timer.h" #if (EASYMESH_VERSION > 2) +#ifdef USE_LIBDPP #include <dpp_api.h> +#endif #include "dpp.h" #endif @@ -1234,6 +1236,7 @@ static int cntlr_config_get_credentials(struct controller_config *c, list_add_tail(&cred->list, &c->aplist); #if (EASYMESH_VERSION > 2) +#ifdef USE_LIBDPP if (cred->multi_ap & 0x01) { struct controller *cntlr = container_of(c, struct controller, cfg); const char *sec; @@ -1249,6 +1252,7 @@ static int cntlr_config_get_credentials(struct controller_config *c, (char *) cred->key, cred->band); } +#endif #endif return 0; } diff --git a/src/dpp.c b/src/dpp.c index 927845364b19a5690be278f3963ca49670af1324..b4d524e7c41ea51c24f0a10a8f4fb2616cd51313 100644 --- a/src/dpp.c +++ b/src/dpp.c @@ -49,7 +49,9 @@ #include "utils/debug.h" #include "utils/dpp_sock.h" #if (EASYMESH_VERSION > 2) +#ifdef USE_LIBDPP #include <dpp_api.h> +#endif #include "dpp.h" #include <math.h> @@ -64,6 +66,79 @@ static void dpp_fd_timeout(atimer_t *t); +#ifndef USE_LIBDPP +uint8_t *dpp_get_attr(uint8_t *msg, uint16_t msglen, uint16_t attr, uint16_t *olen) +{ + uint8_t *p; + uint8_t *msg_end; + + + if (!msg || msglen == 0) + return NULL; + + p = msg; + msg_end = msg + msglen; + + while (labs(p - msg) < msglen - 4) { + uint16_t attr_type; + uint16_t attr_len; + + attr_type = buf_get_le16(p); + p += 2; + attr_len = buf_get_le16(p); + p += 2; + + if (p + attr_len > msg_end) { + pr_debug("%s: Invalid attr = 0x%04x len = %hu, p = %p msg_end = %p diff = %d msg_len:%d\n", + __func__, attr_type, attr_len, p, msg_end, abs(msg_end - p), msglen); + return NULL; + } + + if (attr_type == attr) { + pr_debug("MATCHED attr = 0x%04x\n", attr); + if (olen) + *olen = attr_len; + + return p; + } + + p += attr_len; + } + + pr_debug("%s: VALID msg, but attr 0x%04x not found!\n", __func__, attr); + return NULL; +} + +uint8_t dpp_get_pub_af_type(const uint8_t *frame, uint16_t framelen) +{ + if (framelen < 7) + return 255; + + return *(frame + 6); +} + +uint8_t dpp_get_gas_frame_type(const uint8_t *frame, uint16_t framelen) +{ + if (framelen < 1) + return 255; + + return *frame; +} + +uint8_t dpp_get_frame_type(const uint8_t *frame, uint16_t framelen) +{ + if (framelen < 7) + return 255; + + if (FRAME_IS_DPP_PUB_AF(frame)) + return dpp_get_pub_af_type(frame, framelen); + else if (FRAME_IS_DPP_GAS_FRAME(frame)) + return dpp_get_gas_frame_type(frame, framelen); + + return 255; +} + +#endif const char *dpp_type2str(enum dpp_bootstrap_type type) { @@ -724,6 +799,8 @@ out: blob_buf_free(&uris); return rc; } + +#ifdef USE_LIBDPP int dpp_frame_handler(void *dpp, uint8_t *smac, enum dpp_event ev, uint8_t *frame, size_t framelen) { @@ -810,7 +887,7 @@ int dpp_frame_handler(void *dpp, uint8_t *smac, enum dpp_event ev, } return 0; } - +#endif static void dpp_fd_timeout(atimer_t *t) { diff --git a/src/dpp.h b/src/dpp.h index 0ab2eacd40276d7f80c17d7aa588a2cae6daf678..e824898e71df541b161c8ee692403b766b915b99 100644 --- a/src/dpp.h +++ b/src/dpp.h @@ -1,7 +1,9 @@ #ifndef DPP_H #define DPP_H +#ifdef USE_LIBDPP #include <dpputils.h> +#endif #define FRAME_DST_ENROLLEE(type) \ ((type == DPP_PA_AUTHENTICATION_REQ) || \ @@ -9,6 +11,92 @@ #define DPP_URI_FILE "/etc/multiap/dpp_uris.json" +#ifndef USE_LIBDPP + +#define DPP_PUB_AF_ACTION 0x09 +#define DPP_PUB_AF_ACTION_OUI_TYPE 0x1A +#define DPP_PUB_AF_GAS_INITIAL_REQ 0x0A +#define DPP_PUB_AF_GAS_INITIAL_RESP 0x0B + + +#define FRAME_IS_DPP_PUB_AF(frame) \ + ((*(frame) == DPP_PUB_AF_ACTION) && \ + (memcmp((frame + 1), "\x50\x6F\x9A", 3) == 0) && \ + ((*(frame + 4)) == DPP_PUB_AF_ACTION_OUI_TYPE)) + +#define FRAME_IS_DPP_GAS_FRAME(frame) \ + ((*(frame) == DPP_PUB_AF_GAS_INITIAL_REQ) || \ + (*(frame) == DPP_PUB_AF_GAS_INITIAL_RESP)) + +enum dpp_attribute_id { + DPP_ATTR_STATUS = 0x1000, + DPP_ATTR_I_BOOTSTRAP_KEY_HASH = 0x1001, + DPP_ATTR_R_BOOTSTRAP_KEY_HASH = 0x1002, + DPP_ATTR_I_PROTOCOL_KEY = 0x1003, + DPP_ATTR_WRAPPED_DATA = 0x1004, + DPP_ATTR_I_NONCE = 0x1005, + DPP_ATTR_I_CAPABILITIES = 0x1006, + DPP_ATTR_R_NONCE = 0x1007, + DPP_ATTR_R_CAPABILITIES = 0x1008, + DPP_ATTR_R_PROTOCOL_KEY = 0x1009, + DPP_ATTR_I_AUTH_TAG = 0x100A, + DPP_ATTR_R_AUTH_TAG = 0x100B, + DPP_ATTR_CONFIG_OBJ = 0x100C, + DPP_ATTR_CONNECTOR = 0x100D, + DPP_ATTR_CONFIG_ATTR_OBJ = 0x100E, + DPP_ATTR_BOOTSTRAP_KEY = 0x100F, + DPP_ATTR_OWN_NET_NK_HASH = 0x1011, + DPP_ATTR_FINITE_CYCLIC_GROUP = 0x1012, + DPP_ATTR_ENCRYPTED_KEY = 0x1013, + DPP_ATTR_ENROLLEE_NONCE = 0x1014, + DPP_ATTR_CODE_IDENTIFIER = 0x1015, + DPP_ATTR_TRANSACTION_ID = 0x1016, + DPP_ATTR_BOOTSTRAP_INFO = 0x1017, + DPP_ATTR_CHANNEL = 0x1018, + DPP_ATTR_PROTOCOL_VERSION = 0x1019, + DPP_ATTR_ENVELOPED_DATA = 0x101A, + DPP_ATTR_SEND_CONN_STATUS = 0x101B, + DPP_ATTR_CONN_STATUS = 0x101C, + DPP_ATTR_RECONFIG_FLAGS = 0x101D, + DPP_ATTR_C_SIGN_KEY_HASH = 0x101E, + DPP_ATTR_CSR_ATTR_REQ = 0x101F, + DPP_ATTR_A_NONCE = 0x1020, + DPP_ATTR_E_PRIME_ID = 0x1021, + DPP_ATTR_CONFIGURATOR_NONCE = 0x1022, +}; + +enum dpp_public_action_frame_type { + DPP_PA_AUTHENTICATION_REQ = 0, + DPP_PA_AUTHENTICATION_RESP = 1, + DPP_PA_AUTHENTICATION_CONF = 2, + DPP_PA_PEER_DISCOVERY_REQ = 5, + DPP_PA_PEER_DISCOVERY_RESP = 6, + DPP_PA_PKEX_V1_EXCHANGE_REQ = 7, + DPP_PA_PKEX_EXCHANGE_RESP = 8, + DPP_PA_PKEX_COMMIT_REVEAL_REQ = 9, + DPP_PA_PKEX_COMMIT_REVEAL_RESP = 10, + DPP_PA_CONFIGURATION_RESULT = 11, + DPP_PA_CONNECTION_STATUS_RESULT = 12, + DPP_PA_PRESENCE_ANNOUNCEMENT = 13, + DPP_PA_RECONFIG_ANNOUNCEMENT = 14, + DPP_PA_RECONFIG_AUTH_REQ = 15, + DPP_PA_RECONFIG_AUTH_RESP = 16, + DPP_PA_RECONFIG_AUTH_CONF = 17, + DPP_PA_PKEX_EXCHANGE_REQ = 18, + DPP_PA_PB_PRESENCE_ANNOUNCEMENT = 19, + DPP_PA_PB_PRESENCE_ANNOUNCEMENT_RESP = 20, + DPP_PA_PRIV_PEER_INTRO_QUERY = 21, + DPP_PA_PRIV_PEER_INTRO_NOTIFY = 22, + DPP_PA_PRIV_PEER_INTRO_UPDATE = 23, +}; +uint8_t *dpp_get_attr(uint8_t *msg, uint16_t msglen, uint16_t attr, uint16_t *olen); + +uint8_t dpp_get_pub_af_type(const uint8_t *frame, uint16_t framelen); +uint8_t dpp_get_gas_frame_type(const uint8_t *frame, uint16_t framelen); +uint8_t dpp_get_frame_type(const uint8_t *frame, uint16_t framelen); + +#endif + enum dpp_responder_state { DPP_BOOSTRAPPING, DPP_AUTHENTICATING,