#include "protocol.h" #include "cfg.h" #include "user_main.h" const char* SysGetErrName(int err) { if (err < 0) { err = -err; } if (err == ERR_OK) { return "ERR_OK"; } else if (err >= 1001) { switch (err) { default: return "ERR_UNSUPPORT"; case ERR_INPUT_PARAMS: return "ERR_INPUT_PARAMS"; case ERR_NO_ITEMS: return "ERR_NO_ITEMS"; case ERR_MALLOC_MEMORY: return "ERR_MALLOC_MEMORY"; case ERR_ITEM_UNINIT: return "ERR_ITEM_UNINIT"; case ERR_JSON_STR_FORMAT: return "ERR_JSON_STR_FORMAT"; case ERR_UNKNOWN_CMD_ID: return "ERR_UNKNOWN_CMD_ID"; case ERR_PRO_DECODE: return "ERR_PRO_DECODE"; case ERR_SEND_MESSAGE: return "ERR_SEND_MESSAGE"; case ERR_MSG_FULL: return "ERR_MSG_FULL"; case ERR_ERASE_FLASH: return "ERR_ERASE_FLASH"; case ERR_WRITE_FLASH: return "ERR_WRITE_FLASH"; case ERR_READ_FLASH: return "ERR_READ_FLASH"; case ERR_GPIO_NOT_SUPPORT: return "ERR_GPIO_NOT_SUPPORT"; case ERR_GPIO_NOT_CONFIG: return "ERR_GPIO_NOT_CONFIG"; case ERR_GPIO_MUX_UNSUPPORT: return "ERR_GPIO_MUX_UNSUPPORT"; case ERR_GPIO_MODE_UNSUPPORT: return "ERR_GPIO_MODE_UNSUPPORT"; case ERR_GPIO_INTR_UNSUPPORT: return "ERR_GPIO_INTR_UNSUPPORT"; case ERR_GPIO_UNKNOWN_CMD: return "ERR_GPIO_UNKNOWN_CMD"; } } else if (err < 1000 && err >= 100) { return SysGetWIFIError(err); } else if(err < 100) { switch (err) { case ERR_FAIL: return "ERR_FAIL"; case ERR_NOT_SUPPORT: return "ERR_NOT_SUPPORT"; default: return "ERR_UNSUPPORT"; } } else { return "ERR_UNSUPPORT"; } } const char* SysGetWIFIError(int wifiErr) { switch(wifiErr) { case APP_WIFI_CFG_SYS_ERR: return "APP_WIFI_CFG_SYS_ERR"; case APP_WIFI_CFG_FMT_INVALID: return "APP_WIFI_CFG_FMT_INVALID"; case APP_WIFI_CFG_JSON_INVALID: return "APP_WIFI_CFG_JSON_INVALID"; case APP_WIFI_CFG_PARAMS_ERR: return "APP_WIFI_CFG_PARAMS_ERR"; case APP_WIFI_CFG_SSID_NO_EXIT: return "APP_WIFI_CFG_SSID_NO_EXIT"; case APP_WIFI_CFG_PWD_INVALID: return "APP_WIFI_CFG_PWD_INVALID"; case APP_WIFI_CFG_BUSY: return "APP_WIFI_CFG_BUSY"; case APP_WIFI_CFG_TIMEOUT: return "APP_WIFI_CFG_TIMEOUT"; case APP_WIFI_CFG_WIFI_MD_ERR: return "APP_WIFI_CFG_WIFI_MD_ERR"; case APP_WIFI_CFG_CODEC_ERR: return "APP_WIFI_CFG_CODEC_ERR"; case APP_WIFI_CFG_OTHER: return "APP_WIFI_CFG_OTHER"; case APP_WIFI_CFG_SYS_CFG_BUSY: return "APP_WIFI_CFG_SYS_CFG_BUSY"; case APP_WIFI_CFG_SERVER_ERR: return "APP_WIFI_CFG_SERVER_ERR"; case APP_WIFI_CFG_PROTO_ERR: return "APP_WIFI_CFG_PROTO_ERR"; case APP_WIFI_CFG_CMPT_ERR: return "APP_WIFI_CFG_CMPT_ERR"; case APP_WIFI_CFG_AP_FULL_ERR: return "APP_WIFI_CFG_AP_FULL_ERR"; case APP_WIFI_CFG_STATE_INVALID: return "APP_WIFI_CFG_STATE_INVALID"; default: return "UNKNOWN_CODE"; } } int HalWifiCodeToUser(int wifiErr) { switch(wifiErr) { case REASON_UNSPECIFIED: return APP_WIFI_CFG_OTHER; case REASON_AUTH_EXPIRE: case REASON_AUTH_LEAVE: case REASON_NOT_AUTHED: case REASON_NOT_ASSOCED: case REASON_ASSOC_LEAVE: case REASON_ASSOC_NOT_AUTHED: case REASON_IE_INVALID: case REASON_MIC_FAILURE: case REASON_IE_IN_4WAY_DIFFERS: case REASON_GROUP_CIPHER_INVALID: case REASON_PAIRWISE_CIPHER_INVALID: case REASON_AKMP_INVALID: case REASON_CIPHER_SUITE_REJECTED: case REASON_ASSOC_FAIL: return APP_WIFI_CFG_PROTO_ERR; case REASON_ASSOC_TOOMANY: return APP_WIFI_CFG_AP_FULL_ERR; case REASON_DISASSOC_PWRCAP_BAD: case REASON_DISASSOC_SUPCHAN_BAD: case REASON_UNSUPP_RSN_IE_VERSION: case REASON_INVALID_RSN_IE_CAP: return APP_WIFI_CFG_CMPT_ERR; case REASON_4WAY_HANDSHAKE_TIMEOUT: case REASON_GROUP_KEY_UPDATE_TIMEOUT: return APP_WIFI_CFG_TIMEOUT; case REASON_802_1X_AUTH_FAILED: case REASON_AUTH_FAIL: return APP_WIFI_CFG_PWD_INVALID; case REASON_BEACON_TIMEOUT: case REASON_HANDSHAKE_TIMEOUT: case REASON_ASSOC_EXPIRE: return APP_WIFI_CFG_TIMEOUT; case REASON_NO_AP_FOUND: return APP_WIFI_CFG_SSID_NO_EXIT; default: return ERR_OK; } } const char* SysGetHALWIFIError(int wifiErr) { switch(wifiErr) { case REASON_UNSPECIFIED: return "REASON_UNSPECIFIED"; case REASON_AUTH_EXPIRE: return "REASON_AUTH_EXPIRE"; case REASON_AUTH_LEAVE: return "REASON_AUTH_LEAVE"; case REASON_ASSOC_EXPIRE: return "REASON_ASSOC_EXPIRE"; case REASON_ASSOC_TOOMANY: return "REASON_ASSOC_TOOMANY"; case REASON_NOT_AUTHED: return "REASON_NOT_AUTHED"; case REASON_NOT_ASSOCED: return "REASON_NOT_ASSOCED"; case REASON_ASSOC_LEAVE: return "REASON_ASSOC_LEAVE"; case REASON_ASSOC_NOT_AUTHED: return "REASON_ASSOC_NOT_AUTHED"; case REASON_DISASSOC_PWRCAP_BAD: return "REASON_DISASSOC_PWRCAP_BAD"; case REASON_DISASSOC_SUPCHAN_BAD: return "REASON_DISASSOC_SUPCHAN_BAD"; case REASON_IE_INVALID: return "REASON_IE_INVALID"; case REASON_MIC_FAILURE: return "REASON_MIC_FAILURE"; case REASON_4WAY_HANDSHAKE_TIMEOUT: return "REASON_4WAY_HANDSHAKE_TIMEOUT"; case REASON_GROUP_KEY_UPDATE_TIMEOUT: return "REASON_GROUP_KEY_UPDATE_TIMEOUT"; case REASON_IE_IN_4WAY_DIFFERS: return "REASON_IE_IN_4WAY_DIFFERS"; case REASON_GROUP_CIPHER_INVALID: return "REASON_GROUP_CIPHER_INVALID"; case REASON_PAIRWISE_CIPHER_INVALID: return "REASON_PAIRWISE_CIPHER_INVALID"; case REASON_AKMP_INVALID: return "REASON_AKMP_INVALID"; case REASON_UNSUPP_RSN_IE_VERSION: return "REASON_UNSUPP_RSN_IE_VERSION"; case REASON_INVALID_RSN_IE_CAP: return "REASON_INVALID_RSN_IE_CAP"; case REASON_802_1X_AUTH_FAILED: return "REASON_802_1X_AUTH_FAILED"; case REASON_CIPHER_SUITE_REJECTED: return "REASON_CIPHER_SUITE_REJECTED"; case REASON_BEACON_TIMEOUT: return "REASON_BEACON_TIMEOUT"; case REASON_NO_AP_FOUND: return "REASON_NO_AP_FOUND"; case REASON_AUTH_FAIL: return "REASON_AUTH_FAIL"; case REASON_ASSOC_FAIL: return "REASON_ASSOC_FAIL"; case REASON_HANDSHAKE_TIMEOUT: return "REASON_HANDSHAKE_TIMEOUT"; default: return "UNKNOWN_CODE"; } } const char* ProName2Str(int cmdId) { switch(cmdId) { case GET_DEV_ID: return "GET_DEV_ID"; case CONFIG_AP: return "CONFIG_AP"; case EXIT_SOFTAP_MODE: return "EXIT_SOFTAP_MODE"; case MSG_BYPASS: return "MSG_BYPASS"; case GPIO_FUNC: return "GPIO_FUNC"; } return "UNKNOWN_PROTOCOL"; } const char* ProCryptoName2Str(int cryptoType) { switch(cryptoType) { case CRYPTO_NONE: return "CRYPTO_NONE"; case CRYPTO_MD5: return "CRYPTO_MD5"; case CRYPTO_AES: return "CRYPTO_AES"; } return "UNKNOWN_PROTOCOL"; }