summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/p1905_managerd/src/p1905_ap_autoconfig.c
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/devkit/p1905_managerd/src/p1905_ap_autoconfig.c')
-rw-r--r--cleopatre/devkit/p1905_managerd/src/p1905_ap_autoconfig.c201
1 files changed, 201 insertions, 0 deletions
diff --git a/cleopatre/devkit/p1905_managerd/src/p1905_ap_autoconfig.c b/cleopatre/devkit/p1905_managerd/src/p1905_ap_autoconfig.c
new file mode 100644
index 0000000000..884131df5f
--- /dev/null
+++ b/cleopatre/devkit/p1905_managerd/src/p1905_ap_autoconfig.c
@@ -0,0 +1,201 @@
+/*
+ * cleopatre/application/p1905_managerd/src/p1905_ap_autoconfig.c
+ *
+ * (C) Copyright 2013 MSsar Semiconductor, Inc.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <errno.h>
+#include "p1905_managerd.h"
+#include "p1905_ap_autoconfig.h"
+#include "cmdu_message.h"
+#include "libspid.h"
+
+//#define P1905_AP_AUTOCONFIG_DEBUG
+#ifdef P1905_AP_AUTOCONFIG_DEBUG
+#define debug(...) printf(__VA_ARGS__)
+#define debug_syslog(...) printf(__VA_ARGS__)
+#else
+#define debug(...)
+#define debug_syslog(format, ...) syslog(LOG_WARNING, format, ##__VA_ARGS__)
+#endif
+
+#define AUTO_CONFIG_TIMEOUT_CNT 3//15 seconds(5 seconds per count)
+
+extern const unsigned char p1905_multicast_address[6];
+
+void ap_autoconfig_init(struct p1905_managerd_ctx *ctx)
+{
+#if defined(SUPPORT_AP_ENROLLE)
+ unsigned char conf_status;
+ debug_syslog("AP is an enrollee\n");
+
+ ctx->enrolle_state = no_ap_autoconfig;
+ ctx->ap_config_data = NULL;
+ ctx->last_tx_data = NULL;
+ ctx->current_rx_data = NULL;
+ ctx->is_authenticator_exist_in_M2 = 0;
+ ctx->is_in_encrypt_settings = 0;
+ ctx->get_config_attr_kind = 0;
+
+ /* check wsc configured status.
+ * if this enrollee is not configured, send ap auto config search
+ */
+ ctx->need_ap_config = 0;
+ if(wifi_utils_success == get_wsc_conf_status(&conf_status))
+ {
+ if(conf_status == AP_NOT_CONFIGURED)
+ ctx->need_ap_config = 1;
+ }
+#elif defined(SUPPORT_AP_REGISTRAR)
+ /* if it is ap registrar, check the WIFI_CFG_CHANGE in /etc/web_reset.info
+ * if get value=yes, need to send ap auto config renew
+ */
+ unsigned char status[5] = {0};
+ libspid_error_t ret;
+ debug_syslog("AP is an registrar\n");
+
+ if(LIBSPID_SUCCESS == libspid_config_read_item(LIBSPID_WEB_RESET_INFO_PATH,
+ LIBSPID_WEB_RESET_INFO_LABEL_WIFI_CFG_CHANGE, status, 5))
+ {
+ if(!strcmp(status, LIBSPID_WEB_RESET_INFO_RESET_BY_WEB_YES))
+ {
+ ctx->need_ap_config = 1;
+ ret = libspid_config_write_item (LIBSPID_WEB_RESET_INFO_PATH,
+ LIBSPID_WEB_RESET_INFO_LABEL_WIFI_CFG_CHANGE,
+ LIBSPID_WEB_RESET_INFO_RESET_BY_WEB_NO);
+ if (LIBSPID_SUCCESS == ret)
+ libspid_system_save_file (LIBSPID_WEB_RESET_INFO_PATH);
+ }
+ }
+
+ ctx->last_rx_data = NULL;
+#endif
+ ctx->ap_config = NULL;
+ get_uuid(ctx->uuid);
+}
+
+void ap_autoconfig_free_memory(struct p1905_managerd_ctx *ctx)
+{
+
+
+}
+
+#ifdef SUPPORT_AP_ENROLLE
+void ap_autoconfig_enrolle_sm(struct p1905_managerd_ctx *ctx)
+{
+ WSC_CONFIG config_data;
+
+ switch(ctx->enrolle_state)
+ {
+ case wait_4_send_ap_autoconfig_search:
+ /* if PLC is not authenticated, break!
+ * this function will be called periodically by timer handler
+ * so system will check PLC status periodically
+ */
+ if(!is_connection_status_authenticated())
+ {
+ debug("cannot send auto config search message\n");
+ break;
+ }
+ //debug_syslog("enrollee send ap config search\n");
+ ctx->mid++;
+ ctx->autoconfig_search_mid = ctx->mid;
+ insert_cmdu_txq(p1905_multicast_address,ctx->plc0_mac_addr,\
+ e_ap_autoconfiguration_search, ctx->mid);
+ insert_cmdu_txq(p1905_multicast_address,ctx->eth0_mac_addr,\
+ e_ap_autoconfiguration_search, ctx->mid);
+ ctx->enrolle_state = wait_4_recv_ap_autoconfig_resp;
+ ctx->ap_config_timeout_cnt = 0;
+ break;
+
+ case wait_4_recv_ap_autoconfig_resp:
+ /*check timeout*/
+ if(ctx->ap_config_timeout_cnt > AUTO_CONFIG_TIMEOUT_CNT)
+ {
+ /* ap auto config timeout. Set state to no_ap_autoconfig
+ re-trigger ap autoconfig search process.
+ */
+ ctx->enrolle_state = no_ap_autoconfig;
+ debug_syslog("enrollee wait_4_recv_ap_autoconfig_resp timeout\n");
+ }
+ break;
+
+ case wait_4_recv_m2:
+ /*allocate memory for wifi config use*/
+ if(!ctx->ap_config_data)
+ ctx->ap_config_data = (WSC_CONFIG *)malloc(sizeof(WSC_CONFIG));
+ /*check timeout*/
+ /*if timeout happen, need to free ctx->ap_config_data*/
+ if(ctx->ap_config_timeout_cnt > AUTO_CONFIG_TIMEOUT_CNT)
+ {
+ debug_syslog("enrollee wait_4_recv_m2 timeout\n");
+
+ /* ap auto config timeout. Set state to no_ap_autoconfig
+ re-trigger ap autoconfig search process.
+ */
+ ctx->enrolle_state = no_ap_autoconfig;
+ if(ctx->ap_config_data != NULL)
+ {
+ free(ctx->ap_config_data);
+ ctx->ap_config_data = NULL;
+ }
+ if(ctx->ap_config != NULL)
+ {
+ free(ctx->ap_config);
+ ctx->ap_config = NULL;
+ }
+ if(ctx->last_tx_data != NULL)
+ {
+ free(ctx->last_tx_data);
+ ctx->last_tx_data = NULL;
+ }
+ }
+ break;
+
+ case wait_4_set_config:
+ if(ctx->ap_config_data != NULL)
+ {
+ if(wifi_utils_success != set_wsc_config(ctx->ap_config_data))
+ {
+ debug_syslog("set wsc config error\n");
+ }
+
+ /*test setting*/
+ get_wsc_config(&config_data);
+ debug_syslog("after key = %s\n",config_data.WPAKey);
+ debug_syslog("after SSID = %s\n",config_data.Ssid);
+ debug_syslog("after Auth = 0x%.4x\n",config_data.AuthMode);
+ debug_syslog("after Encry = 0x%.4x\n",config_data.EncrypType);
+
+ if(wifi_utils_success != update_wifi_config_file(ctx->ap_config_data))
+ {
+ debug_syslog("ap auto-config write config file error\n");
+ }
+ /*no need to do ap autoconfig anymore*/
+ ctx->need_ap_config = 0;
+ /*set the configured statue of local wifi device*/
+ set_wsc_conf_status(AP_ALREADY_CONFIGURED);
+
+ free(ctx->ap_config_data);
+ ctx->ap_config_data = NULL;
+ }
+ ctx->enrolle_state = no_ap_autoconfig;
+ break;
+ }
+}
+#endif
+
+#ifdef SUPPORT_AP_REGISTRAR
+void ap_auto_config_renew_start(struct p1905_managerd_ctx *ctx)
+{
+ ctx->mid++;
+ insert_cmdu_txq(p1905_multicast_address,ctx->plc0_mac_addr,\
+ e_ap_autoconfiguration_renew, ctx->mid);
+ insert_cmdu_txq(p1905_multicast_address,ctx->eth0_mac_addr,\
+ e_ap_autoconfiguration_renew, ctx->mid);
+}
+#endif
+