From 395d161f4034436fba7ca956415f2fb10d26de29 Mon Sep 17 00:00:00 2001 From: luckfox-eng33 <144299491+luckfox-eng33@users.noreply.github.com> Date: Fri, 27 Oct 2023 17:12:27 +0800 Subject: [PATCH] fix:wifi_app mistake (#13) --- project/app/wifi_app/.gitignore | 10 +- .../wifi_app/hisi_tools/app/client/cJSON.c | 4761 ++--- .../wifi_app/hisi_tools/app/client/cJSON.h | 330 +- .../hisi_tools/app/client/sample_cli.c | 286 +- .../wifi_app/hisi_tools/app/include/hi_base.h | 21 +- .../hisi_tools/app/include/hi_errno.h | 732 +- .../hisi_tools/app/include/hi_stdlib.h | 209 +- .../hisi_tools/app/include/hi_types.h | 41 +- .../hisi_tools/app/include/hi_types_base.h | 658 +- .../hisi_tools/app/link/hichannel_host.c | 314 +- .../hisi_tools/app/link/hichannel_host.h | 12 +- .../hisi_tools/app/link/hichannel_host_comm.c | 225 +- .../hisi_tools/app/link/hichannel_host_comm.h | 28 +- .../hisi_tools/app/link/hichannel_main.c | 892 +- .../wifi_app/hisi_tools/app/vlinktest/cJSON.c | 4761 ++--- .../wifi_app/hisi_tools/app/vlinktest/cJSON.h | 330 +- .../hisi_tools/app/vlinktest/hichannel_host.c | 314 +- .../hisi_tools/app/vlinktest/hichannel_host.h | 12 +- .../app/vlinktest/hichannel_host_comm.c | 225 +- .../app/vlinktest/hichannel_host_comm.h | 70 +- .../app/vlinktest/vlink_hichannel_cmd.c | 824 +- .../app/vlinktest/vlink_hichannel_main.c | 1569 +- .../app/vlinktest/vlink_tcp_socket_main.c | 130 +- .../app/vlinktest/vlink_wifi_ota_main.c | 297 +- .../wifi_app/hisi_tools/securec/fscanf_s.c | 41 +- .../wifi_app/hisi_tools/securec/fwscanf_s.c | 43 +- .../app/wifi_app/hisi_tools/securec/gets_s.c | 62 +- .../wifi_app/hisi_tools/securec/memcpy_s.c | 971 +- .../wifi_app/hisi_tools/securec/memmove_s.c | 131 +- .../wifi_app/hisi_tools/securec/memset_s.c | 921 +- .../app/wifi_app/hisi_tools/securec/scanf_s.c | 35 +- .../wifi_app/hisi_tools/securec/secinput.h | 141 +- .../app/wifi_app/hisi_tools/securec/securec.h | 856 +- .../wifi_app/hisi_tools/securec/securectype.h | 414 +- .../wifi_app/hisi_tools/securec/securecutil.c | 28 +- .../wifi_app/hisi_tools/securec/securecutil.h | 457 +- .../hisi_tools/securec/secureinput_a.c | 23 +- .../hisi_tools/securec/secureinput_w.c | 35 +- .../hisi_tools/securec/secureprintoutput.h | 127 +- .../hisi_tools/securec/secureprintoutput_a.c | 225 +- .../hisi_tools/securec/secureprintoutput_w.c | 173 +- .../wifi_app/hisi_tools/securec/snprintf_s.c | 92 +- .../wifi_app/hisi_tools/securec/sprintf_s.c | 42 +- .../wifi_app/hisi_tools/securec/sscanf_s.c | 43 +- .../wifi_app/hisi_tools/securec/strcat_s.c | 109 +- .../wifi_app/hisi_tools/securec/strcpy_s.c | 589 +- .../wifi_app/hisi_tools/securec/strncat_s.c | 141 +- .../wifi_app/hisi_tools/securec/strncpy_s.c | 178 +- .../wifi_app/hisi_tools/securec/strtok_s.c | 139 +- .../wifi_app/hisi_tools/securec/swprintf_s.c | 30 +- .../wifi_app/hisi_tools/securec/swscanf_s.c | 43 +- .../wifi_app/hisi_tools/securec/vfscanf_s.c | 61 +- .../wifi_app/hisi_tools/securec/vfwscanf_s.c | 61 +- .../wifi_app/hisi_tools/securec/vscanf_s.c | 58 +- .../wifi_app/hisi_tools/securec/vsnprintf_s.c | 146 +- .../wifi_app/hisi_tools/securec/vsprintf_s.c | 54 +- .../wifi_app/hisi_tools/securec/vsscanf_s.c | 88 +- .../wifi_app/hisi_tools/securec/vswprintf_s.c | 52 +- .../wifi_app/hisi_tools/securec/vswscanf_s.c | 83 +- .../wifi_app/hisi_tools/securec/vwscanf_s.c | 49 +- .../wifi_app/hisi_tools/securec/wcscat_s.c | 123 +- .../wifi_app/hisi_tools/securec/wcscpy_s.c | 96 +- .../wifi_app/hisi_tools/securec/wcsncat_s.c | 128 +- .../wifi_app/hisi_tools/securec/wcsncpy_s.c | 126 +- .../wifi_app/hisi_tools/securec/wcstok_s.c | 128 +- .../wifi_app/hisi_tools/securec/wmemcpy_s.c | 58 +- .../wifi_app/hisi_tools/securec/wmemmove_s.c | 64 +- .../wifi_app/hisi_tools/securec/wscanf_s.c | 34 +- .../hostapd-2.6/hostapd/config_file.c | 6082 +++--- .../hostapd-2.6/hostapd/config_file.h | 6 +- .../wifi_app/hostapd-2.6/hostapd/ctrl_iface.c | 5637 +++--- .../wifi_app/hostapd-2.6/hostapd/ctrl_iface.h | 20 +- .../hostapd-2.6/hostapd/eap_register.c | 106 +- .../hostapd-2.6/hostapd/hapd_module_tests.c | 7 +- .../wifi_app/hostapd-2.6/hostapd/hlr_auc_gw.c | 1590 +- .../hostapd-2.6/hostapd/hostapd_cli.c | 2610 +-- .../app/wifi_app/hostapd-2.6/hostapd/main.c | 1303 +- .../hostapd-2.6/hostapd/nt_password_hash.c | 58 +- .../wifi_app/hostapd-2.6/src/ap/accounting.c | 775 +- .../wifi_app/hostapd-2.6/src/ap/accounting.h | 24 +- project/app/wifi_app/hostapd-2.6/src/ap/acs.c | 1155 +- project/app/wifi_app/hostapd-2.6/src/ap/acs.h | 8 +- .../wifi_app/hostapd-2.6/src/ap/ap_config.c | 1536 +- .../wifi_app/hostapd-2.6/src/ap/ap_config.h | 987 +- .../wifi_app/hostapd-2.6/src/ap/ap_drv_ops.c | 1207 +- .../wifi_app/hostapd-2.6/src/ap/ap_drv_ops.h | 408 +- .../app/wifi_app/hostapd-2.6/src/ap/ap_list.c | 429 +- .../app/wifi_app/hostapd-2.6/src/ap/ap_list.h | 45 +- .../app/wifi_app/hostapd-2.6/src/ap/ap_mlme.c | 135 +- .../app/wifi_app/hostapd-2.6/src/ap/ap_mlme.h | 13 +- .../app/wifi_app/hostapd-2.6/src/ap/authsrv.c | 308 +- .../app/wifi_app/hostapd-2.6/src/ap/beacon.c | 1982 +- .../app/wifi_app/hostapd-2.6/src/ap/beacon.h | 13 +- .../wifi_app/hostapd-2.6/src/ap/bss_load.c | 74 +- .../wifi_app/hostapd-2.6/src/ap/bss_load.h | 2 + .../hostapd-2.6/src/ap/ctrl_iface_ap.c | 937 +- .../hostapd-2.6/src/ap/ctrl_iface_ap.h | 27 +- project/app/wifi_app/hostapd-2.6/src/ap/dfs.c | 1580 +- project/app/wifi_app/hostapd-2.6/src/ap/dfs.h | 18 +- .../wifi_app/hostapd-2.6/src/ap/dhcp_snoop.c | 260 +- .../wifi_app/hostapd-2.6/src/ap/dhcp_snoop.h | 9 +- .../hostapd-2.6/src/ap/drv_callbacks.c | 2093 +- .../wifi_app/hostapd-2.6/src/ap/eap_user_db.c | 422 +- .../wifi_app/hostapd-2.6/src/ap/gas_serv.c | 2383 +-- .../wifi_app/hostapd-2.6/src/ap/gas_serv.h | 97 +- .../app/wifi_app/hostapd-2.6/src/ap/hostapd.c | 4789 ++--- .../app/wifi_app/hostapd-2.6/src/ap/hostapd.h | 624 +- .../app/wifi_app/hostapd-2.6/src/ap/hs20.c | 246 +- .../app/wifi_app/hostapd-2.6/src/ap/hs20.h | 10 +- .../wifi_app/hostapd-2.6/src/ap/hw_features.c | 1483 +- .../wifi_app/hostapd-2.6/src/ap/hw_features.h | 53 +- .../app/wifi_app/hostapd-2.6/src/ap/iapp.c | 740 +- .../app/wifi_app/hostapd-2.6/src/ap/iapp.h | 19 +- .../wifi_app/hostapd-2.6/src/ap/ieee802_11.c | 4932 ++--- .../wifi_app/hostapd-2.6/src/ap/ieee802_11.h | 121 +- .../hostapd-2.6/src/ap/ieee802_11_auth.c | 960 +- .../hostapd-2.6/src/ap/ieee802_11_auth.h | 20 +- .../hostapd-2.6/src/ap/ieee802_11_ht.c | 752 +- .../hostapd-2.6/src/ap/ieee802_11_shared.c | 866 +- .../hostapd-2.6/src/ap/ieee802_11_vht.c | 749 +- .../wifi_app/hostapd-2.6/src/ap/ieee802_1x.c | 4136 ++-- .../wifi_app/hostapd-2.6/src/ap/ieee802_1x.h | 31 +- .../app/wifi_app/hostapd-2.6/src/ap/mbo_ap.c | 362 +- .../app/wifi_app/hostapd-2.6/src/ap/mbo_ap.h | 25 +- .../wifi_app/hostapd-2.6/src/ap/ndisc_snoop.c | 256 +- .../wifi_app/hostapd-2.6/src/ap/ndisc_snoop.h | 13 +- .../wifi_app/hostapd-2.6/src/ap/neighbor_db.c | 157 +- .../wifi_app/hostapd-2.6/src/ap/neighbor_db.h | 10 +- .../wifi_app/hostapd-2.6/src/ap/p2p_hostapd.c | 133 +- .../wifi_app/hostapd-2.6/src/ap/p2p_hostapd.h | 14 +- .../hostapd-2.6/src/ap/peerkey_auth.c | 555 +- .../hostapd-2.6/src/ap/pmksa_cache_auth.c | 798 +- .../hostapd-2.6/src/ap/pmksa_cache_auth.h | 67 +- .../hostapd-2.6/src/ap/preauth_auth.c | 394 +- .../hostapd-2.6/src/ap/preauth_auth.h | 28 +- project/app/wifi_app/hostapd-2.6/src/ap/rrm.c | 784 +- project/app/wifi_app/hostapd-2.6/src/ap/rrm.h | 8 +- .../wifi_app/hostapd-2.6/src/ap/sta_info.c | 1945 +- .../wifi_app/hostapd-2.6/src/ap/sta_info.h | 300 +- .../wifi_app/hostapd-2.6/src/ap/taxonomy.c | 425 +- .../wifi_app/hostapd-2.6/src/ap/taxonomy.h | 16 +- .../hostapd-2.6/src/ap/tkip_countermeasures.c | 144 +- .../app/wifi_app/hostapd-2.6/src/ap/utils.c | 102 +- .../app/wifi_app/hostapd-2.6/src/ap/vlan.c | 33 +- .../app/wifi_app/hostapd-2.6/src/ap/vlan.h | 15 +- .../wifi_app/hostapd-2.6/src/ap/vlan_full.c | 1104 +- .../hostapd-2.6/src/ap/vlan_ifconfig.c | 80 +- .../wifi_app/hostapd-2.6/src/ap/vlan_init.c | 314 +- .../wifi_app/hostapd-2.6/src/ap/vlan_init.h | 28 +- .../wifi_app/hostapd-2.6/src/ap/vlan_ioctl.c | 207 +- .../wifi_app/hostapd-2.6/src/ap/vlan_util.c | 240 +- .../wifi_app/hostapd-2.6/src/ap/vlan_util.h | 3 +- project/app/wifi_app/hostapd-2.6/src/ap/wmm.c | 445 +- project/app/wifi_app/hostapd-2.6/src/ap/wmm.h | 7 +- .../app/wifi_app/hostapd-2.6/src/ap/wnm_ap.c | 974 +- .../app/wifi_app/hostapd-2.6/src/ap/wnm_ap.h | 18 +- .../wifi_app/hostapd-2.6/src/ap/wpa_auth.c | 5614 +++--- .../wifi_app/hostapd-2.6/src/ap/wpa_auth.h | 391 +- .../wifi_app/hostapd-2.6/src/ap/wpa_auth_ft.c | 2819 +-- .../hostapd-2.6/src/ap/wpa_auth_glue.c | 1033 +- .../wifi_app/hostapd-2.6/src/ap/wpa_auth_i.h | 346 +- .../wifi_app/hostapd-2.6/src/ap/wpa_auth_ie.c | 1432 +- .../wifi_app/hostapd-2.6/src/ap/wpa_auth_ie.h | 61 +- .../wifi_app/hostapd-2.6/src/ap/wps_hostapd.c | 3024 +-- .../wifi_app/hostapd-2.6/src/ap/wps_hostapd.h | 71 +- .../app/wifi_app/hostapd-2.6/src/ap/x_snoop.c | 173 +- .../app/wifi_app/hostapd-2.6/src/ap/x_snoop.h | 44 +- .../app/wifi_app/hostapd-2.6/src/common/cli.c | 380 +- .../app/wifi_app/hostapd-2.6/src/common/cli.h | 16 +- .../src/common/common_module_tests.c | 316 +- .../src/common/ctrl_iface_common.c | 215 +- .../src/common/ctrl_iface_common.h | 18 +- .../wifi_app/hostapd-2.6/src/common/defs.h | 367 +- .../hostapd-2.6/src/common/eapol_common.h | 75 +- .../app/wifi_app/hostapd-2.6/src/common/gas.c | 296 +- .../app/wifi_app/hostapd-2.6/src/common/gas.h | 38 +- .../src/common/hw_features_common.c | 701 +- .../src/common/hw_features_common.h | 28 +- .../src/common/ieee802_11_common.c | 2154 +-- .../src/common/ieee802_11_common.h | 204 +- .../hostapd-2.6/src/common/ieee802_11_defs.h | 1667 +- .../hostapd-2.6/src/common/ieee802_1x_defs.h | 89 +- .../hostapd-2.6/src/common/linux_vlan.h | 22 +- .../hostapd-2.6/src/common/privsep_commands.h | 147 +- .../hostapd-2.6/src/common/qca-vendor-attr.h | 12 +- .../hostapd-2.6/src/common/qca-vendor.h | 1465 +- .../app/wifi_app/hostapd-2.6/src/common/sae.c | 2002 +- .../app/wifi_app/hostapd-2.6/src/common/sae.h | 59 +- .../app/wifi_app/hostapd-2.6/src/common/tnc.h | 89 +- .../hostapd-2.6/src/common/wpa_common.c | 2520 +-- .../hostapd-2.6/src/common/wpa_common.h | 284 +- .../hostapd-2.6/src/common/wpa_ctrl.c | 1017 +- .../hostapd-2.6/src/common/wpa_ctrl.h | 102 +- .../hostapd-2.6/src/common/wpa_helpers.c | 417 +- .../hostapd-2.6/src/common/wpa_helpers.h | 23 +- .../wifi_app/hostapd-2.6/src/crypto/aes-cbc.c | 93 +- .../wifi_app/hostapd-2.6/src/crypto/aes-ccm.c | 289 +- .../wifi_app/hostapd-2.6/src/crypto/aes-ctr.c | 55 +- .../wifi_app/hostapd-2.6/src/crypto/aes-eax.c | 163 +- .../hostapd-2.6/src/crypto/aes-encblock.c | 19 +- .../wifi_app/hostapd-2.6/src/crypto/aes-gcm.c | 439 +- .../hostapd-2.6/src/crypto/aes-internal-dec.c | 216 +- .../hostapd-2.6/src/crypto/aes-internal-enc.c | 160 +- .../hostapd-2.6/src/crypto/aes-internal.c | 1349 +- .../hostapd-2.6/src/crypto/aes-omac1.c | 168 +- .../wifi_app/hostapd-2.6/src/crypto/aes-siv.c | 259 +- .../hostapd-2.6/src/crypto/aes-unwrap.c | 95 +- .../hostapd-2.6/src/crypto/aes-wrap.c | 90 +- .../app/wifi_app/hostapd-2.6/src/crypto/aes.h | 4 +- .../wifi_app/hostapd-2.6/src/crypto/aes_i.h | 63 +- .../wifi_app/hostapd-2.6/src/crypto/aes_siv.h | 9 +- .../hostapd-2.6/src/crypto/aes_wrap.h | 73 +- .../wifi_app/hostapd-2.6/src/crypto/crypto.h | 179 +- .../hostapd-2.6/src/crypto/crypto_gnutls.c | 429 +- .../src/crypto/crypto_internal-cipher.c | 410 +- .../src/crypto/crypto_internal-modexp.c | 53 +- .../src/crypto/crypto_internal-rsa.c | 123 +- .../hostapd-2.6/src/crypto/crypto_internal.c | 488 +- .../src/crypto/crypto_libtomcrypt.c | 1085 +- .../src/crypto/crypto_module_tests.c | 2665 +-- .../hostapd-2.6/src/crypto/crypto_none.c | 11 +- .../hostapd-2.6/src/crypto/crypto_openssl.c | 2188 ++- .../hostapd-2.6/src/crypto/des-internal.c | 703 +- .../wifi_app/hostapd-2.6/src/crypto/des_i.h | 4 +- .../hostapd-2.6/src/crypto/dh_group5.c | 35 +- .../hostapd-2.6/src/crypto/dh_group5.h | 8 +- .../hostapd-2.6/src/crypto/dh_groups.c | 1910 +- .../hostapd-2.6/src/crypto/dh_groups.h | 26 +- .../src/crypto/fips_prf_internal.c | 90 +- .../hostapd-2.6/src/crypto/fips_prf_openssl.c | 138 +- .../hostapd-2.6/src/crypto/md4-internal.c | 321 +- .../hostapd-2.6/src/crypto/md5-internal.c | 340 +- .../app/wifi_app/hostapd-2.6/src/crypto/md5.c | 124 +- .../app/wifi_app/hostapd-2.6/src/crypto/md5.h | 4 +- .../wifi_app/hostapd-2.6/src/crypto/md5_i.h | 8 +- .../hostapd-2.6/src/crypto/milenage.c | 368 +- .../hostapd-2.6/src/crypto/milenage.h | 23 +- .../hostapd-2.6/src/crypto/ms_funcs.c | 559 +- .../hostapd-2.6/src/crypto/ms_funcs.h | 63 +- .../wifi_app/hostapd-2.6/src/crypto/random.c | 586 +- .../wifi_app/hostapd-2.6/src/crypto/random.h | 18 +- .../app/wifi_app/hostapd-2.6/src/crypto/rc4.c | 74 +- .../hostapd-2.6/src/crypto/sha1-internal.c | 356 +- .../hostapd-2.6/src/crypto/sha1-pbkdf2.c | 100 +- .../hostapd-2.6/src/crypto/sha1-prf.c | 68 +- .../hostapd-2.6/src/crypto/sha1-tlsprf.c | 125 +- .../hostapd-2.6/src/crypto/sha1-tprf.c | 79 +- .../wifi_app/hostapd-2.6/src/crypto/sha1.c | 122 +- .../wifi_app/hostapd-2.6/src/crypto/sha1.h | 18 +- .../wifi_app/hostapd-2.6/src/crypto/sha1_i.h | 6 +- .../hostapd-2.6/src/crypto/sha256-internal.c | 290 +- .../hostapd-2.6/src/crypto/sha256-kdf.c | 84 +- .../hostapd-2.6/src/crypto/sha256-prf.c | 105 +- .../hostapd-2.6/src/crypto/sha256-tlsprf.c | 62 +- .../wifi_app/hostapd-2.6/src/crypto/sha256.c | 118 +- .../wifi_app/hostapd-2.6/src/crypto/sha256.h | 24 +- .../hostapd-2.6/src/crypto/sha256_i.h | 8 +- .../hostapd-2.6/src/crypto/sha384-internal.c | 72 +- .../hostapd-2.6/src/crypto/sha384-prf.c | 95 +- .../wifi_app/hostapd-2.6/src/crypto/sha384.h | 12 +- .../hostapd-2.6/src/crypto/sha384_i.h | 2 +- .../hostapd-2.6/src/crypto/sha512-internal.c | 344 +- .../hostapd-2.6/src/crypto/sha512_i.h | 8 +- .../app/wifi_app/hostapd-2.6/src/crypto/tls.h | 294 +- .../hostapd-2.6/src/crypto/tls_gnutls.c | 2406 +-- .../hostapd-2.6/src/crypto/tls_internal.c | 992 +- .../hostapd-2.6/src/crypto/tls_none.c | 226 +- .../hostapd-2.6/src/crypto/tls_openssl.c | 6494 ++++--- .../hostapd-2.6/src/crypto/tls_openssl.h | 6 +- .../hostapd-2.6/src/crypto/tls_openssl_ocsp.c | 1160 +- .../hostapd-2.6/src/drivers/android_drv.h | 61 +- .../wifi_app/hostapd-2.6/src/drivers/driver.h | 8283 ++++---- .../hostapd-2.6/src/drivers/driver_atheros.c | 3366 ++-- .../hostapd-2.6/src/drivers/driver_bsd.c | 2708 +-- .../hostapd-2.6/src/drivers/driver_common.c | 435 +- .../hostapd-2.6/src/drivers/driver_hostap.c | 1758 +- .../hostapd-2.6/src/drivers/driver_hostap.h | 265 +- .../src/drivers/driver_macsec_qca.c | 1196 +- .../hostapd-2.6/src/drivers/driver_ndis.c | 4835 ++--- .../hostapd-2.6/src/drivers/driver_ndis.h | 59 +- .../hostapd-2.6/src/drivers/driver_ndis_.c | 116 +- .../hostapd-2.6/src/drivers/driver_nl80211.c | 14634 +++++++------- .../hostapd-2.6/src/drivers/driver_nl80211.h | 384 +- .../src/drivers/driver_nl80211_android.c | 233 +- .../src/drivers/driver_nl80211_capa.c | 2642 +-- .../src/drivers/driver_nl80211_event.c | 3787 ++-- .../src/drivers/driver_nl80211_monitor.c | 774 +- .../src/drivers/driver_nl80211_scan.c | 1674 +- .../hostapd-2.6/src/drivers/driver_none.c | 88 +- .../hostapd-2.6/src/drivers/driver_openbsd.c | 154 +- .../hostapd-2.6/src/drivers/driver_privsep.c | 1285 +- .../src/drivers/driver_roboswitch.c | 709 +- .../hostapd-2.6/src/drivers/driver_wext.c | 3748 ++-- .../hostapd-2.6/src/drivers/driver_wext.h | 70 +- .../hostapd-2.6/src/drivers/driver_wired.c | 985 +- .../hostapd-2.6/src/drivers/drivers.c | 33 +- .../hostapd-2.6/src/drivers/linux_defines.h | 24 +- .../hostapd-2.6/src/drivers/linux_ioctl.c | 321 +- .../hostapd-2.6/src/drivers/linux_wext.h | 2 +- .../hostapd-2.6/src/drivers/ndis_events.c | 1245 +- .../hostapd-2.6/src/drivers/netlink.c | 337 +- .../hostapd-2.6/src/drivers/netlink.h | 12 +- .../hostapd-2.6/src/drivers/nl80211_copy.h | 2102 +-- .../hostapd-2.6/src/drivers/priv_netlink.h | 86 +- .../wifi_app/hostapd-2.6/src/drivers/rfkill.c | 323 +- .../wifi_app/hostapd-2.6/src/drivers/rfkill.h | 10 +- .../hostapd-2.6/src/eap_common/chap.c | 23 +- .../hostapd-2.6/src/eap_common/chap.h | 2 +- .../hostapd-2.6/src/eap_common/eap_common.c | 341 +- .../hostapd-2.6/src/eap_common/eap_common.h | 18 +- .../hostapd-2.6/src/eap_common/eap_defs.h | 118 +- .../src/eap_common/eap_eke_common.c | 1133 +- .../src/eap_common/eap_eke_common.h | 75 +- .../src/eap_common/eap_fast_common.c | 417 +- .../src/eap_common/eap_fast_common.h | 49 +- .../src/eap_common/eap_gpsk_common.c | 723 +- .../src/eap_common/eap_gpsk_common.h | 38 +- .../src/eap_common/eap_ikev2_common.c | 152 +- .../src/eap_common/eap_ikev2_common.h | 13 +- .../src/eap_common/eap_pax_common.c | 147 +- .../src/eap_common/eap_pax_common.h | 82 +- .../src/eap_common/eap_peap_common.c | 122 +- .../src/eap_common/eap_peap_common.h | 5 +- .../src/eap_common/eap_psk_common.c | 79 +- .../src/eap_common/eap_psk_common.h | 38 +- .../src/eap_common/eap_pwd_common.c | 584 +- .../src/eap_common/eap_pwd_common.h | 69 +- .../src/eap_common/eap_sake_common.c | 572 +- .../src/eap_common/eap_sake_common.h | 69 +- .../src/eap_common/eap_sim_common.c | 2040 +- .../src/eap_common/eap_sim_common.h | 171 +- .../src/eap_common/eap_tlv_common.h | 64 +- .../hostapd-2.6/src/eap_common/eap_ttls.h | 35 +- .../src/eap_common/eap_wsc_common.c | 29 +- .../src/eap_common/eap_wsc_common.h | 3 +- .../hostapd-2.6/src/eap_common/ikev2_common.c | 1118 +- .../hostapd-2.6/src/eap_common/ikev2_common.h | 387 +- .../wifi_app/hostapd-2.6/src/eap_peer/eap.c | 3936 ++-- .../wifi_app/hostapd-2.6/src/eap_peer/eap.h | 457 +- .../hostapd-2.6/src/eap_peer/eap_aka.c | 2353 +-- .../hostapd-2.6/src/eap_peer/eap_config.h | 1383 +- .../hostapd-2.6/src/eap_peer/eap_eke.c | 1193 +- .../hostapd-2.6/src/eap_peer/eap_fast.c | 2789 +-- .../hostapd-2.6/src/eap_peer/eap_fast_pac.c | 1328 +- .../hostapd-2.6/src/eap_peer/eap_fast_pac.h | 47 +- .../hostapd-2.6/src/eap_peer/eap_gpsk.c | 1201 +- .../hostapd-2.6/src/eap_peer/eap_gtc.c | 198 +- .../wifi_app/hostapd-2.6/src/eap_peer/eap_i.h | 609 +- .../hostapd-2.6/src/eap_peer/eap_ikev2.c | 837 +- .../hostapd-2.6/src/eap_peer/eap_leap.c | 673 +- .../hostapd-2.6/src/eap_peer/eap_md5.c | 178 +- .../hostapd-2.6/src/eap_peer/eap_methods.c | 380 +- .../hostapd-2.6/src/eap_peer/eap_methods.h | 55 +- .../hostapd-2.6/src/eap_peer/eap_mschapv2.c | 1299 +- .../hostapd-2.6/src/eap_peer/eap_otp.c | 140 +- .../hostapd-2.6/src/eap_peer/eap_pax.c | 850 +- .../hostapd-2.6/src/eap_peer/eap_peap.c | 2087 +- .../hostapd-2.6/src/eap_peer/eap_proxy.h | 27 +- .../src/eap_peer/eap_proxy_dummy.c | 68 +- .../hostapd-2.6/src/eap_peer/eap_psk.c | 787 +- .../hostapd-2.6/src/eap_peer/eap_pwd.c | 1782 +- .../hostapd-2.6/src/eap_peer/eap_sake.c | 780 +- .../hostapd-2.6/src/eap_peer/eap_sim.c | 1970 +- .../hostapd-2.6/src/eap_peer/eap_tls.c | 640 +- .../hostapd-2.6/src/eap_peer/eap_tls_common.c | 1418 +- .../hostapd-2.6/src/eap_peer/eap_tls_common.h | 156 +- .../hostapd-2.6/src/eap_peer/eap_tnc.c | 647 +- .../hostapd-2.6/src/eap_peer/eap_ttls.c | 2803 +-- .../src/eap_peer/eap_vendor_test.c | 244 +- .../hostapd-2.6/src/eap_peer/eap_wsc.c | 975 +- .../wifi_app/hostapd-2.6/src/eap_peer/ikev2.c | 1945 +- .../wifi_app/hostapd-2.6/src/eap_peer/ikev2.h | 69 +- .../hostapd-2.6/src/eap_peer/mschapv2.c | 178 +- .../hostapd-2.6/src/eap_peer/mschapv2.h | 16 +- .../wifi_app/hostapd-2.6/src/eap_peer/tncc.c | 1934 +- .../wifi_app/hostapd-2.6/src/eap_peer/tncc.h | 24 +- .../wifi_app/hostapd-2.6/src/eap_server/eap.h | 202 +- .../hostapd-2.6/src/eap_server/eap_i.h | 351 +- .../hostapd-2.6/src/eap_server/eap_methods.h | 9 +- .../hostapd-2.6/src/eap_server/eap_server.c | 3023 +-- .../src/eap_server/eap_server_aka.c | 2078 +- .../src/eap_server/eap_server_eke.c | 1217 +- .../src/eap_server/eap_server_fast.c | 2582 +-- .../src/eap_server/eap_server_gpsk.c | 1032 +- .../src/eap_server/eap_server_gtc.c | 304 +- .../src/eap_server/eap_server_identity.c | 235 +- .../src/eap_server/eap_server_ikev2.c | 886 +- .../src/eap_server/eap_server_md5.c | 220 +- .../src/eap_server/eap_server_methods.c | 154 +- .../src/eap_server/eap_server_mschapv2.c | 878 +- .../src/eap_server/eap_server_pax.c | 880 +- .../src/eap_server/eap_server_peap.c | 2239 +-- .../src/eap_server/eap_server_psk.c | 794 +- .../src/eap_server/eap_server_pwd.c | 1840 +- .../src/eap_server/eap_server_sake.c | 769 +- .../src/eap_server/eap_server_sim.c | 1362 +- .../src/eap_server/eap_server_tls.c | 610 +- .../src/eap_server/eap_server_tls_common.c | 686 +- .../src/eap_server/eap_server_tnc.c | 881 +- .../src/eap_server/eap_server_ttls.c | 2160 ++- .../src/eap_server/eap_server_vendor_test.c | 232 +- .../src/eap_server/eap_server_wsc.c | 796 +- .../hostapd-2.6/src/eap_server/eap_sim_db.c | 2079 +- .../hostapd-2.6/src/eap_server/eap_sim_db.h | 71 +- .../src/eap_server/eap_tls_common.h | 102 +- .../hostapd-2.6/src/eap_server/ikev2.c | 1869 +- .../hostapd-2.6/src/eap_server/ikev2.h | 72 +- .../hostapd-2.6/src/eap_server/tncs.c | 1764 +- .../hostapd-2.6/src/eap_server/tncs.h | 32 +- .../src/eapol_auth/eapol_auth_dump.c | 488 +- .../src/eapol_auth/eapol_auth_sm.c | 1920 +- .../src/eapol_auth/eapol_auth_sm.h | 124 +- .../src/eapol_auth/eapol_auth_sm_i.h | 257 +- .../src/eapol_supp/eapol_supp_sm.c | 3014 +-- .../src/eapol_supp/eapol_supp_sm.h | 587 +- .../app/wifi_app/hostapd-2.6/src/fst/fst.c | 294 +- .../app/wifi_app/hostapd-2.6/src/fst/fst.h | 293 +- .../hostapd-2.6/src/fst/fst_ctrl_aux.c | 74 +- .../hostapd-2.6/src/fst/fst_ctrl_aux.h | 116 +- .../hostapd-2.6/src/fst/fst_ctrl_defs.h | 108 +- .../hostapd-2.6/src/fst/fst_ctrl_iface.c | 1362 +- .../hostapd-2.6/src/fst/fst_ctrl_iface.h | 11 +- .../wifi_app/hostapd-2.6/src/fst/fst_defs.h | 91 +- .../wifi_app/hostapd-2.6/src/fst/fst_group.c | 676 +- .../wifi_app/hostapd-2.6/src/fst/fst_group.h | 58 +- .../wifi_app/hostapd-2.6/src/fst/fst_iface.c | 95 +- .../wifi_app/hostapd-2.6/src/fst/fst_iface.h | 135 +- .../hostapd-2.6/src/fst/fst_internal.h | 42 +- .../hostapd-2.6/src/fst/fst_session.c | 2365 +-- .../hostapd-2.6/src/fst/fst_session.h | 35 +- .../hostapd-2.6/src/l2_packet/l2_packet.h | 37 +- .../src/l2_packet/l2_packet_freebsd.c | 462 +- .../src/l2_packet/l2_packet_linux.c | 716 +- .../src/l2_packet/l2_packet_ndis.c | 757 +- .../src/l2_packet/l2_packet_none.c | 159 +- .../src/l2_packet/l2_packet_pcap.c | 543 +- .../src/l2_packet/l2_packet_privsep.c | 408 +- .../src/l2_packet/l2_packet_winpcap.c | 456 +- .../app/wifi_app/hostapd-2.6/src/p2p/p2p.c | 8431 +++++---- .../app/wifi_app/hostapd-2.6/src/p2p/p2p.h | 2246 +-- .../wifi_app/hostapd-2.6/src/p2p/p2p_build.c | 1232 +- .../hostapd-2.6/src/p2p/p2p_dev_disc.c | 490 +- .../wifi_app/hostapd-2.6/src/p2p/p2p_go_neg.c | 2552 +-- .../wifi_app/hostapd-2.6/src/p2p/p2p_group.c | 1535 +- .../app/wifi_app/hostapd-2.6/src/p2p/p2p_i.h | 1165 +- .../hostapd-2.6/src/p2p/p2p_invitation.c | 1162 +- .../wifi_app/hostapd-2.6/src/p2p/p2p_parse.c | 1461 +- .../app/wifi_app/hostapd-2.6/src/p2p/p2p_pd.c | 2788 +-- .../app/wifi_app/hostapd-2.6/src/p2p/p2p_sd.c | 1478 +- .../wifi_app/hostapd-2.6/src/p2p/p2p_utils.c | 605 +- .../hostapd-2.6/src/pae/ieee802_1x_cp.c | 909 +- .../hostapd-2.6/src/pae/ieee802_1x_cp.h | 4 +- .../hostapd-2.6/src/pae/ieee802_1x_kay.c | 4770 ++--- .../hostapd-2.6/src/pae/ieee802_1x_kay.h | 229 +- .../hostapd-2.6/src/pae/ieee802_1x_kay_i.h | 524 +- .../hostapd-2.6/src/pae/ieee802_1x_key.c | 185 +- .../hostapd-2.6/src/pae/ieee802_1x_key.h | 14 +- .../hostapd-2.6/src/pae/ieee802_1x_secy_ops.c | 656 +- .../hostapd-2.6/src/pae/ieee802_1x_secy_ops.h | 24 +- .../wifi_app/hostapd-2.6/src/radius/radius.c | 2586 +-- .../wifi_app/hostapd-2.6/src/radius/radius.h | 321 +- .../hostapd-2.6/src/radius/radius_client.c | 2366 +-- .../hostapd-2.6/src/radius/radius_client.h | 342 +- .../hostapd-2.6/src/radius/radius_das.c | 654 +- .../hostapd-2.6/src/radius/radius_das.h | 60 +- .../hostapd-2.6/src/radius/radius_server.c | 3274 ++-- .../hostapd-2.6/src/radius/radius_server.h | 376 +- .../hostapd-2.6/src/rsn_supp/peerkey.c | 1724 +- .../hostapd-2.6/src/rsn_supp/peerkey.h | 87 +- .../hostapd-2.6/src/rsn_supp/pmksa_cache.c | 688 +- .../hostapd-2.6/src/rsn_supp/pmksa_cache.h | 126 +- .../hostapd-2.6/src/rsn_supp/preauth.c | 692 +- .../hostapd-2.6/src/rsn_supp/preauth.h | 61 +- .../wifi_app/hostapd-2.6/src/rsn_supp/tdls.c | 4456 ++--- .../wifi_app/hostapd-2.6/src/rsn_supp/wpa.c | 4408 +++-- .../wifi_app/hostapd-2.6/src/rsn_supp/wpa.h | 397 +- .../hostapd-2.6/src/rsn_supp/wpa_ft.c | 1260 +- .../wifi_app/hostapd-2.6/src/rsn_supp/wpa_i.h | 469 +- .../hostapd-2.6/src/rsn_supp/wpa_ie.c | 886 +- .../hostapd-2.6/src/rsn_supp/wpa_ie.h | 92 +- .../app/wifi_app/hostapd-2.6/src/tls/asn1.c | 341 +- .../app/wifi_app/hostapd-2.6/src/tls/asn1.h | 80 +- .../app/wifi_app/hostapd-2.6/src/tls/bignum.c | 168 +- .../app/wifi_app/hostapd-2.6/src/tls/bignum.h | 12 +- .../wifi_app/hostapd-2.6/src/tls/libtommath.c | 2047 +- .../app/wifi_app/hostapd-2.6/src/tls/pkcs1.c | 509 +- .../app/wifi_app/hostapd-2.6/src/tls/pkcs1.h | 22 +- .../app/wifi_app/hostapd-2.6/src/tls/pkcs5.c | 1022 +- .../app/wifi_app/hostapd-2.6/src/tls/pkcs5.h | 5 +- .../app/wifi_app/hostapd-2.6/src/tls/pkcs8.c | 291 +- .../app/wifi_app/hostapd-2.6/src/tls/pkcs8.h | 6 +- .../app/wifi_app/hostapd-2.6/src/tls/rsa.c | 517 +- .../app/wifi_app/hostapd-2.6/src/tls/rsa.h | 15 +- .../hostapd-2.6/src/tls/tlsv1_client.c | 1125 +- .../hostapd-2.6/src/tls/tlsv1_client.h | 49 +- .../hostapd-2.6/src/tls/tlsv1_client_i.h | 125 +- .../hostapd-2.6/src/tls/tlsv1_client_ocsp.c | 1350 +- .../hostapd-2.6/src/tls/tlsv1_client_read.c | 2510 +-- .../hostapd-2.6/src/tls/tlsv1_client_write.c | 1586 +- .../hostapd-2.6/src/tls/tlsv1_common.c | 765 +- .../hostapd-2.6/src/tls/tlsv1_common.h | 362 +- .../wifi_app/hostapd-2.6/src/tls/tlsv1_cred.c | 1900 +- .../wifi_app/hostapd-2.6/src/tls/tlsv1_cred.h | 47 +- .../hostapd-2.6/src/tls/tlsv1_record.c | 703 +- .../hostapd-2.6/src/tls/tlsv1_record.h | 63 +- .../hostapd-2.6/src/tls/tlsv1_server.c | 1050 +- .../hostapd-2.6/src/tls/tlsv1_server.h | 34 +- .../hostapd-2.6/src/tls/tlsv1_server_i.h | 102 +- .../hostapd-2.6/src/tls/tlsv1_server_read.c | 2041 +- .../hostapd-2.6/src/tls/tlsv1_server_write.c | 1713 +- .../app/wifi_app/hostapd-2.6/src/tls/x509v3.c | 3452 ++-- .../app/wifi_app/hostapd-2.6/src/tls/x509v3.h | 194 +- .../wifi_app/hostapd-2.6/src/utils/base64.c | 206 +- .../wifi_app/hostapd-2.6/src/utils/base64.h | 8 +- .../wifi_app/hostapd-2.6/src/utils/bitfield.c | 105 +- .../wifi_app/hostapd-2.6/src/utils/bitfield.h | 2 +- .../hostapd-2.6/src/utils/browser-android.c | 171 +- .../hostapd-2.6/src/utils/browser-system.c | 157 +- .../hostapd-2.6/src/utils/browser-wpadebug.c | 196 +- .../wifi_app/hostapd-2.6/src/utils/browser.c | 296 +- .../wifi_app/hostapd-2.6/src/utils/browser.h | 7 +- .../wifi_app/hostapd-2.6/src/utils/common.c | 1620 +- .../wifi_app/hostapd-2.6/src/utils/common.h | 306 +- .../app/wifi_app/hostapd-2.6/src/utils/edit.c | 1806 +- .../app/wifi_app/hostapd-2.6/src/utils/edit.h | 9 +- .../hostapd-2.6/src/utils/edit_readline.c | 261 +- .../hostapd-2.6/src/utils/edit_simple.c | 109 +- .../wifi_app/hostapd-2.6/src/utils/eloop.c | 1826 +- .../wifi_app/hostapd-2.6/src/utils/eloop.h | 49 +- .../hostapd-2.6/src/utils/eloop_win.c | 980 +- .../hostapd-2.6/src/utils/ext_password.c | 124 +- .../hostapd-2.6/src/utils/ext_password.h | 18 +- .../hostapd-2.6/src/utils/ext_password_i.h | 10 +- .../hostapd-2.6/src/utils/ext_password_test.c | 103 +- .../hostapd-2.6/src/utils/http-utils.h | 57 +- .../hostapd-2.6/src/utils/http_curl.c | 2538 +-- .../wifi_app/hostapd-2.6/src/utils/includes.h | 12 +- .../wifi_app/hostapd-2.6/src/utils/ip_addr.c | 51 +- .../wifi_app/hostapd-2.6/src/utils/ip_addr.h | 16 +- .../app/wifi_app/hostapd-2.6/src/utils/list.h | 105 +- .../app/wifi_app/hostapd-2.6/src/utils/os.h | 167 +- .../hostapd-2.6/src/utils/os_internal.c | 805 +- .../wifi_app/hostapd-2.6/src/utils/os_none.c | 265 +- .../wifi_app/hostapd-2.6/src/utils/os_unix.c | 1147 +- .../wifi_app/hostapd-2.6/src/utils/os_win32.c | 381 +- .../hostapd-2.6/src/utils/pcsc_funcs.c | 2095 ++- .../hostapd-2.6/src/utils/pcsc_funcs.h | 14 +- .../wifi_app/hostapd-2.6/src/utils/platform.h | 26 +- .../wifi_app/hostapd-2.6/src/utils/radiotap.c | 583 +- .../wifi_app/hostapd-2.6/src/utils/radiotap.h | 217 +- .../hostapd-2.6/src/utils/radiotap_iter.h | 60 +- .../hostapd-2.6/src/utils/state_machine.h | 61 +- .../wifi_app/hostapd-2.6/src/utils/trace.c | 533 +- .../wifi_app/hostapd-2.6/src/utils/trace.h | 61 +- .../src/utils/utils_module_tests.c | 1282 +- .../app/wifi_app/hostapd-2.6/src/utils/uuid.c | 87 +- .../hostapd-2.6/src/utils/wpa_debug.c | 1178 +- .../hostapd-2.6/src/utils/wpa_debug.h | 219 +- .../wifi_app/hostapd-2.6/src/utils/wpabuf.c | 410 +- .../wifi_app/hostapd-2.6/src/utils/wpabuf.h | 134 +- .../hostapd-2.6/src/utils/xml-utils.c | 681 +- .../hostapd-2.6/src/utils/xml-utils.h | 113 +- .../hostapd-2.6/src/utils/xml_libxml2.c | 623 +- .../app/wifi_app/hostapd-2.6/src/wps/http.h | 24 +- .../hostapd-2.6/src/wps/http_client.c | 546 +- .../hostapd-2.6/src/wps/http_client.h | 39 +- .../hostapd-2.6/src/wps/http_server.c | 422 +- .../hostapd-2.6/src/wps/http_server.h | 19 +- .../wifi_app/hostapd-2.6/src/wps/httpread.c | 1302 +- .../wifi_app/hostapd-2.6/src/wps/httpread.h | 63 +- .../app/wifi_app/hostapd-2.6/src/wps/ndef.c | 273 +- .../wifi_app/hostapd-2.6/src/wps/upnp_xml.c | 227 +- .../wifi_app/hostapd-2.6/src/wps/upnp_xml.h | 13 +- .../app/wifi_app/hostapd-2.6/src/wps/wps.c | 823 +- .../app/wifi_app/hostapd-2.6/src/wps/wps.h | 1420 +- .../hostapd-2.6/src/wps/wps_attr_build.c | 724 +- .../hostapd-2.6/src/wps/wps_attr_parse.c | 1274 +- .../hostapd-2.6/src/wps/wps_attr_parse.h | 156 +- .../hostapd-2.6/src/wps/wps_attr_process.c | 381 +- .../wifi_app/hostapd-2.6/src/wps/wps_common.c | 1284 +- .../wifi_app/hostapd-2.6/src/wps/wps_defs.h | 470 +- .../hostapd-2.6/src/wps/wps_dev_attr.c | 573 +- .../hostapd-2.6/src/wps/wps_dev_attr.h | 13 +- .../hostapd-2.6/src/wps/wps_enrollee.c | 2370 +-- .../app/wifi_app/hostapd-2.6/src/wps/wps_er.c | 3248 ++-- .../app/wifi_app/hostapd-2.6/src/wps/wps_er.h | 141 +- .../hostapd-2.6/src/wps/wps_er_ssdp.c | 315 +- .../app/wifi_app/hostapd-2.6/src/wps/wps_i.h | 249 +- .../hostapd-2.6/src/wps/wps_module_tests.c | 639 +- .../hostapd-2.6/src/wps/wps_registrar.c | 5482 +++--- .../wifi_app/hostapd-2.6/src/wps/wps_upnp.c | 1419 +- .../wifi_app/hostapd-2.6/src/wps/wps_upnp.h | 30 +- .../hostapd-2.6/src/wps/wps_upnp_ap.c | 102 +- .../hostapd-2.6/src/wps/wps_upnp_event.c | 534 +- .../wifi_app/hostapd-2.6/src/wps/wps_upnp_i.h | 161 +- .../hostapd-2.6/src/wps/wps_upnp_ssdp.c | 1250 +- .../hostapd-2.6/src/wps/wps_upnp_web.c | 2195 +-- .../hostapd-2.6/src/wps/wps_validate.c | 3203 ++-- project/app/wifi_app/wifi/include/RK_encode.h | 6 +- .../app/wifi_app/wifi/include/Rk_socket_app.h | 18 +- project/app/wifi_app/wifi/include/Rk_softap.h | 21 +- project/app/wifi_app/wifi/include/Rk_wifi.h | 276 +- .../app/wifi_app/wifi/include/rk_wifi_hal.h | 110 +- project/app/wifi_app/wifi/include/slog.h | 35 +- project/app/wifi_app/wifi/src/Rk_wifi.c | 3987 ++-- .../wifi_app/wifi/src/atbm6441/atbm_tool.h | 573 +- .../app/wifi_app/wifi/src/atbm6441/tools.c | 1091 +- .../app/wifi_app/wifi/src/atbm6441/tools.h | 15 +- .../wifi/src/hisi_tools/include/hi_base.h | 16 +- .../wifi/src/hisi_tools/include/hi_errno.h | 732 +- .../wifi/src/hisi_tools/include/hi_stdlib.h | 209 +- .../wifi/src/hisi_tools/include/hi_types.h | 41 +- .../src/hisi_tools/include/hi_types_base.h | 658 +- .../wifi/src/hisi_tools/securec/fscanf_s.c | 41 +- .../wifi/src/hisi_tools/securec/fwscanf_s.c | 43 +- .../wifi/src/hisi_tools/securec/gets_s.c | 62 +- .../wifi/src/hisi_tools/securec/memcpy_s.c | 971 +- .../wifi/src/hisi_tools/securec/memmove_s.c | 131 +- .../wifi/src/hisi_tools/securec/memset_s.c | 921 +- .../wifi/src/hisi_tools/securec/scanf_s.c | 35 +- .../wifi/src/hisi_tools/securec/secinput.h | 141 +- .../wifi/src/hisi_tools/securec/securec.h | 856 +- .../wifi/src/hisi_tools/securec/securectype.h | 414 +- .../wifi/src/hisi_tools/securec/securecutil.c | 28 +- .../wifi/src/hisi_tools/securec/securecutil.h | 457 +- .../src/hisi_tools/securec/secureinput_a.c | 23 +- .../src/hisi_tools/securec/secureinput_w.c | 35 +- .../hisi_tools/securec/secureprintoutput.h | 127 +- .../hisi_tools/securec/secureprintoutput_a.c | 225 +- .../hisi_tools/securec/secureprintoutput_w.c | 173 +- .../wifi/src/hisi_tools/securec/snprintf_s.c | 92 +- .../wifi/src/hisi_tools/securec/sprintf_s.c | 42 +- .../wifi/src/hisi_tools/securec/sscanf_s.c | 43 +- .../wifi/src/hisi_tools/securec/strcat_s.c | 109 +- .../wifi/src/hisi_tools/securec/strcpy_s.c | 589 +- .../wifi/src/hisi_tools/securec/strncat_s.c | 141 +- .../wifi/src/hisi_tools/securec/strncpy_s.c | 178 +- .../wifi/src/hisi_tools/securec/strtok_s.c | 139 +- .../wifi/src/hisi_tools/securec/swprintf_s.c | 30 +- .../wifi/src/hisi_tools/securec/swscanf_s.c | 43 +- .../wifi/src/hisi_tools/securec/vfscanf_s.c | 61 +- .../wifi/src/hisi_tools/securec/vfwscanf_s.c | 61 +- .../wifi/src/hisi_tools/securec/vscanf_s.c | 58 +- .../wifi/src/hisi_tools/securec/vsnprintf_s.c | 146 +- .../wifi/src/hisi_tools/securec/vsprintf_s.c | 54 +- .../wifi/src/hisi_tools/securec/vsscanf_s.c | 88 +- .../wifi/src/hisi_tools/securec/vswprintf_s.c | 52 +- .../wifi/src/hisi_tools/securec/vswscanf_s.c | 83 +- .../wifi/src/hisi_tools/securec/vwscanf_s.c | 49 +- .../wifi/src/hisi_tools/securec/wcscat_s.c | 123 +- .../wifi/src/hisi_tools/securec/wcscpy_s.c | 96 +- .../wifi/src/hisi_tools/securec/wcsncat_s.c | 128 +- .../wifi/src/hisi_tools/securec/wcsncpy_s.c | 126 +- .../wifi/src/hisi_tools/securec/wcstok_s.c | 128 +- .../wifi/src/hisi_tools/securec/wmemcpy_s.c | 58 +- .../wifi/src/hisi_tools/securec/wmemmove_s.c | 64 +- .../wifi/src/hisi_tools/securec/wscanf_s.c | 34 +- .../wifi/src/hisi_tools/vlinktest/cJSON.c | 4761 ++--- .../wifi/src/hisi_tools/vlinktest/cJSON.h | 330 +- .../src/hisi_tools/vlinktest/hichannel_host.c | 314 +- .../src/hisi_tools/vlinktest/hichannel_host.h | 12 +- .../vlinktest/hichannel_host_comm.c | 225 +- .../vlinktest/hichannel_host_comm.h | 74 +- .../vlinktest/vlink_hichannel_cmd.c | 1246 +- .../vlinktest/vlink_hichannel_main.c | 1750 +- .../vlinktest/vlink_tcp_socket_main.c | 130 +- .../vlinktest/vlink_wifi_ota_main.c | 297 +- project/app/wifi_app/wifi/src/rk_atbm_wifi.c | 444 +- project/app/wifi_app/wifi/src/rk_hisi_wifi.c | 257 +- project/app/wifi_app/wifi/src/rk_wifi_hal.c | 300 +- project/app/wifi_app/wifi/src/wpa_ctrl.h | 37 +- project/app/wifi_app/wifi/test/rk_wifi_test.c | 740 +- project/app/wifi_app/wifi/test/rkwifi_cli.c | 84 +- .../app/wifi_app/wifi/test/softap/softap.c | 765 +- .../app/wifi_app/wifi/utility/Rk_socket_app.c | 229 +- .../wifi_app/wifi/utility/encode/RK_encode.c | 82 +- .../wifi/utility/encode/gbk_to_utf8.c | 4304 ++--- .../wifi/utility/encode/gbk_to_utf8.h | 2 +- .../wifi/utility/encode/utf8_to_gbk.c | 3693 ++-- .../wifi/utility/encode/utf8_to_gbk.h | 2 +- project/app/wifi_app/wifi/utility/utility.c | 308 +- project/app/wifi_app/wifi/utility/utility.h | 7 +- .../wpa_supplicant-2.6/hs20/client/est.c | 1162 +- .../hs20/client/oma_dm_client.c | 2066 +- .../hs20/client/osu_client.c | 5179 ++--- .../hs20/client/osu_client.h | 102 +- .../hs20/client/spp_client.c | 1542 +- .../wpa_supplicant-2.6/src/ap/accounting.c | 775 +- .../wpa_supplicant-2.6/src/ap/accounting.h | 24 +- .../wifi_app/wpa_supplicant-2.6/src/ap/acs.c | 1155 +- .../wifi_app/wpa_supplicant-2.6/src/ap/acs.h | 8 +- .../wpa_supplicant-2.6/src/ap/ap_config.c | 1536 +- .../wpa_supplicant-2.6/src/ap/ap_config.h | 987 +- .../wpa_supplicant-2.6/src/ap/ap_drv_ops.c | 1207 +- .../wpa_supplicant-2.6/src/ap/ap_drv_ops.h | 408 +- .../wpa_supplicant-2.6/src/ap/ap_list.c | 429 +- .../wpa_supplicant-2.6/src/ap/ap_list.h | 45 +- .../wpa_supplicant-2.6/src/ap/ap_mlme.c | 135 +- .../wpa_supplicant-2.6/src/ap/ap_mlme.h | 13 +- .../wpa_supplicant-2.6/src/ap/authsrv.c | 308 +- .../wpa_supplicant-2.6/src/ap/beacon.c | 1982 +- .../wpa_supplicant-2.6/src/ap/beacon.h | 13 +- .../wpa_supplicant-2.6/src/ap/bss_load.c | 74 +- .../wpa_supplicant-2.6/src/ap/bss_load.h | 2 + .../wpa_supplicant-2.6/src/ap/ctrl_iface_ap.c | 937 +- .../wpa_supplicant-2.6/src/ap/ctrl_iface_ap.h | 27 +- .../wifi_app/wpa_supplicant-2.6/src/ap/dfs.c | 1580 +- .../wifi_app/wpa_supplicant-2.6/src/ap/dfs.h | 18 +- .../wpa_supplicant-2.6/src/ap/dhcp_snoop.c | 260 +- .../wpa_supplicant-2.6/src/ap/dhcp_snoop.h | 9 +- .../wpa_supplicant-2.6/src/ap/drv_callbacks.c | 2093 +- .../wpa_supplicant-2.6/src/ap/eap_user_db.c | 422 +- .../wpa_supplicant-2.6/src/ap/gas_serv.c | 2383 +-- .../wpa_supplicant-2.6/src/ap/gas_serv.h | 97 +- .../wpa_supplicant-2.6/src/ap/hostapd.c | 4789 ++--- .../wpa_supplicant-2.6/src/ap/hostapd.h | 624 +- .../wifi_app/wpa_supplicant-2.6/src/ap/hs20.c | 246 +- .../wifi_app/wpa_supplicant-2.6/src/ap/hs20.h | 10 +- .../wpa_supplicant-2.6/src/ap/hw_features.c | 1483 +- .../wpa_supplicant-2.6/src/ap/hw_features.h | 53 +- .../wifi_app/wpa_supplicant-2.6/src/ap/iapp.c | 740 +- .../wifi_app/wpa_supplicant-2.6/src/ap/iapp.h | 19 +- .../wpa_supplicant-2.6/src/ap/ieee802_11.c | 4932 ++--- .../wpa_supplicant-2.6/src/ap/ieee802_11.h | 121 +- .../src/ap/ieee802_11_auth.c | 960 +- .../src/ap/ieee802_11_auth.h | 20 +- .../wpa_supplicant-2.6/src/ap/ieee802_11_ht.c | 752 +- .../src/ap/ieee802_11_shared.c | 866 +- .../src/ap/ieee802_11_vht.c | 749 +- .../wpa_supplicant-2.6/src/ap/ieee802_1x.c | 4136 ++-- .../wpa_supplicant-2.6/src/ap/ieee802_1x.h | 31 +- .../wpa_supplicant-2.6/src/ap/mbo_ap.c | 362 +- .../wpa_supplicant-2.6/src/ap/mbo_ap.h | 25 +- .../wpa_supplicant-2.6/src/ap/ndisc_snoop.c | 256 +- .../wpa_supplicant-2.6/src/ap/ndisc_snoop.h | 13 +- .../wpa_supplicant-2.6/src/ap/neighbor_db.c | 157 +- .../wpa_supplicant-2.6/src/ap/neighbor_db.h | 10 +- .../wpa_supplicant-2.6/src/ap/p2p_hostapd.c | 133 +- .../wpa_supplicant-2.6/src/ap/p2p_hostapd.h | 14 +- .../wpa_supplicant-2.6/src/ap/peerkey_auth.c | 555 +- .../src/ap/pmksa_cache_auth.c | 798 +- .../src/ap/pmksa_cache_auth.h | 67 +- .../wpa_supplicant-2.6/src/ap/preauth_auth.c | 394 +- .../wpa_supplicant-2.6/src/ap/preauth_auth.h | 28 +- .../wifi_app/wpa_supplicant-2.6/src/ap/rrm.c | 784 +- .../wifi_app/wpa_supplicant-2.6/src/ap/rrm.h | 8 +- .../wpa_supplicant-2.6/src/ap/sta_info.c | 1945 +- .../wpa_supplicant-2.6/src/ap/sta_info.h | 300 +- .../wpa_supplicant-2.6/src/ap/taxonomy.c | 425 +- .../wpa_supplicant-2.6/src/ap/taxonomy.h | 16 +- .../src/ap/tkip_countermeasures.c | 144 +- .../wpa_supplicant-2.6/src/ap/utils.c | 102 +- .../wifi_app/wpa_supplicant-2.6/src/ap/vlan.c | 33 +- .../wifi_app/wpa_supplicant-2.6/src/ap/vlan.h | 15 +- .../wpa_supplicant-2.6/src/ap/vlan_full.c | 1104 +- .../wpa_supplicant-2.6/src/ap/vlan_ifconfig.c | 80 +- .../wpa_supplicant-2.6/src/ap/vlan_init.c | 314 +- .../wpa_supplicant-2.6/src/ap/vlan_init.h | 28 +- .../wpa_supplicant-2.6/src/ap/vlan_ioctl.c | 207 +- .../wpa_supplicant-2.6/src/ap/vlan_util.c | 240 +- .../wpa_supplicant-2.6/src/ap/vlan_util.h | 3 +- .../wifi_app/wpa_supplicant-2.6/src/ap/wmm.c | 445 +- .../wifi_app/wpa_supplicant-2.6/src/ap/wmm.h | 7 +- .../wpa_supplicant-2.6/src/ap/wnm_ap.c | 974 +- .../wpa_supplicant-2.6/src/ap/wnm_ap.h | 18 +- .../wpa_supplicant-2.6/src/ap/wpa_auth.c | 5586 +++--- .../wpa_supplicant-2.6/src/ap/wpa_auth.h | 391 +- .../wpa_supplicant-2.6/src/ap/wpa_auth_ft.c | 2819 +-- .../wpa_supplicant-2.6/src/ap/wpa_auth_glue.c | 1033 +- .../wpa_supplicant-2.6/src/ap/wpa_auth_i.h | 346 +- .../wpa_supplicant-2.6/src/ap/wpa_auth_ie.c | 1432 +- .../wpa_supplicant-2.6/src/ap/wpa_auth_ie.h | 61 +- .../wpa_supplicant-2.6/src/ap/wps_hostapd.c | 3024 +-- .../wpa_supplicant-2.6/src/ap/wps_hostapd.h | 71 +- .../wpa_supplicant-2.6/src/ap/x_snoop.c | 173 +- .../wpa_supplicant-2.6/src/ap/x_snoop.h | 44 +- .../wpa_supplicant-2.6/src/common/cli.c | 380 +- .../wpa_supplicant-2.6/src/common/cli.h | 16 +- .../src/common/common_module_tests.c | 316 +- .../src/common/ctrl_iface_common.c | 215 +- .../src/common/ctrl_iface_common.h | 18 +- .../wpa_supplicant-2.6/src/common/defs.h | 367 +- .../src/common/eapol_common.h | 75 +- .../wpa_supplicant-2.6/src/common/gas.c | 296 +- .../wpa_supplicant-2.6/src/common/gas.h | 38 +- .../src/common/hw_features_common.c | 701 +- .../src/common/hw_features_common.h | 28 +- .../src/common/ieee802_11_common.c | 2154 +-- .../src/common/ieee802_11_common.h | 204 +- .../src/common/ieee802_11_defs.h | 1667 +- .../src/common/ieee802_1x_defs.h | 89 +- .../src/common/linux_vlan.h | 22 +- .../src/common/privsep_commands.h | 147 +- .../src/common/qca-vendor-attr.h | 12 +- .../src/common/qca-vendor.h | 1465 +- .../wpa_supplicant-2.6/src/common/sae.c | 2002 +- .../wpa_supplicant-2.6/src/common/sae.h | 59 +- .../wpa_supplicant-2.6/src/common/tnc.h | 89 +- .../src/common/wpa_common.c | 2520 +-- .../src/common/wpa_common.h | 293 +- .../wpa_supplicant-2.6/src/common/wpa_ctrl.c | 1017 +- .../wpa_supplicant-2.6/src/common/wpa_ctrl.h | 102 +- .../src/common/wpa_helpers.c | 417 +- .../src/common/wpa_helpers.h | 23 +- .../wpa_supplicant-2.6/src/crypto/aes-cbc.c | 93 +- .../wpa_supplicant-2.6/src/crypto/aes-ccm.c | 289 +- .../wpa_supplicant-2.6/src/crypto/aes-ctr.c | 55 +- .../wpa_supplicant-2.6/src/crypto/aes-eax.c | 163 +- .../src/crypto/aes-encblock.c | 19 +- .../wpa_supplicant-2.6/src/crypto/aes-gcm.c | 439 +- .../src/crypto/aes-internal-dec.c | 216 +- .../src/crypto/aes-internal-enc.c | 160 +- .../src/crypto/aes-internal.c | 1349 +- .../wpa_supplicant-2.6/src/crypto/aes-omac1.c | 168 +- .../wpa_supplicant-2.6/src/crypto/aes-siv.c | 259 +- .../src/crypto/aes-unwrap.c | 95 +- .../wpa_supplicant-2.6/src/crypto/aes-wrap.c | 90 +- .../wpa_supplicant-2.6/src/crypto/aes.h | 4 +- .../wpa_supplicant-2.6/src/crypto/aes_i.h | 63 +- .../wpa_supplicant-2.6/src/crypto/aes_siv.h | 9 +- .../wpa_supplicant-2.6/src/crypto/aes_wrap.h | 73 +- .../wpa_supplicant-2.6/src/crypto/crypto.h | 179 +- .../src/crypto/crypto_gnutls.c | 429 +- .../src/crypto/crypto_internal-cipher.c | 410 +- .../src/crypto/crypto_internal-modexp.c | 53 +- .../src/crypto/crypto_internal-rsa.c | 123 +- .../src/crypto/crypto_internal.c | 488 +- .../src/crypto/crypto_libtomcrypt.c | 1085 +- .../src/crypto/crypto_module_tests.c | 2665 +-- .../src/crypto/crypto_none.c | 11 +- .../src/crypto/crypto_openssl.c | 2188 ++- .../src/crypto/des-internal.c | 703 +- .../wpa_supplicant-2.6/src/crypto/des_i.h | 4 +- .../wpa_supplicant-2.6/src/crypto/dh_group5.c | 35 +- .../wpa_supplicant-2.6/src/crypto/dh_group5.h | 8 +- .../wpa_supplicant-2.6/src/crypto/dh_groups.c | 1910 +- .../wpa_supplicant-2.6/src/crypto/dh_groups.h | 26 +- .../src/crypto/fips_prf_internal.c | 90 +- .../src/crypto/fips_prf_openssl.c | 138 +- .../src/crypto/md4-internal.c | 321 +- .../src/crypto/md5-internal.c | 340 +- .../wpa_supplicant-2.6/src/crypto/md5.c | 124 +- .../wpa_supplicant-2.6/src/crypto/md5.h | 4 +- .../wpa_supplicant-2.6/src/crypto/md5_i.h | 8 +- .../wpa_supplicant-2.6/src/crypto/milenage.c | 368 +- .../wpa_supplicant-2.6/src/crypto/milenage.h | 23 +- .../wpa_supplicant-2.6/src/crypto/ms_funcs.c | 559 +- .../wpa_supplicant-2.6/src/crypto/ms_funcs.h | 63 +- .../wpa_supplicant-2.6/src/crypto/random.c | 586 +- .../wpa_supplicant-2.6/src/crypto/random.h | 18 +- .../wpa_supplicant-2.6/src/crypto/rc4.c | 74 +- .../src/crypto/sha1-internal.c | 356 +- .../src/crypto/sha1-pbkdf2.c | 100 +- .../wpa_supplicant-2.6/src/crypto/sha1-prf.c | 68 +- .../src/crypto/sha1-tlsprf.c | 125 +- .../wpa_supplicant-2.6/src/crypto/sha1-tprf.c | 79 +- .../wpa_supplicant-2.6/src/crypto/sha1.c | 122 +- .../wpa_supplicant-2.6/src/crypto/sha1.h | 18 +- .../wpa_supplicant-2.6/src/crypto/sha1_i.h | 6 +- .../src/crypto/sha256-internal.c | 290 +- .../src/crypto/sha256-kdf.c | 84 +- .../src/crypto/sha256-prf.c | 105 +- .../src/crypto/sha256-tlsprf.c | 62 +- .../wpa_supplicant-2.6/src/crypto/sha256.c | 118 +- .../wpa_supplicant-2.6/src/crypto/sha256.h | 24 +- .../wpa_supplicant-2.6/src/crypto/sha256_i.h | 8 +- .../src/crypto/sha384-internal.c | 72 +- .../src/crypto/sha384-prf.c | 95 +- .../wpa_supplicant-2.6/src/crypto/sha384.h | 12 +- .../wpa_supplicant-2.6/src/crypto/sha384_i.h | 2 +- .../src/crypto/sha512-internal.c | 344 +- .../wpa_supplicant-2.6/src/crypto/sha512_i.h | 8 +- .../wpa_supplicant-2.6/src/crypto/tls.h | 294 +- .../src/crypto/tls_gnutls.c | 2406 +-- .../src/crypto/tls_internal.c | 992 +- .../wpa_supplicant-2.6/src/crypto/tls_none.c | 226 +- .../src/crypto/tls_openssl.c | 6494 ++++--- .../src/crypto/tls_openssl.h | 6 +- .../src/crypto/tls_openssl_ocsp.c | 1160 +- .../src/drivers/android_drv.h | 61 +- .../wpa_supplicant-2.6/src/drivers/driver.h | 8283 ++++---- .../src/drivers/driver_atheros.c | 3366 ++-- .../src/drivers/driver_bsd.c | 2708 +-- .../src/drivers/driver_common.c | 435 +- .../src/drivers/driver_hostap.c | 1758 +- .../src/drivers/driver_hostap.h | 265 +- .../src/drivers/driver_macsec_qca.c | 1196 +- .../src/drivers/driver_ndis.c | 4835 ++--- .../src/drivers/driver_ndis.h | 59 +- .../src/drivers/driver_ndis_.c | 116 +- .../src/drivers/driver_nl80211.c | 14634 +++++++------- .../src/drivers/driver_nl80211.h | 384 +- .../src/drivers/driver_nl80211_android.c | 233 +- .../src/drivers/driver_nl80211_capa.c | 2642 +-- .../src/drivers/driver_nl80211_event.c | 3787 ++-- .../src/drivers/driver_nl80211_monitor.c | 774 +- .../src/drivers/driver_nl80211_scan.c | 1674 +- .../src/drivers/driver_none.c | 88 +- .../src/drivers/driver_openbsd.c | 154 +- .../src/drivers/driver_privsep.c | 1285 +- .../src/drivers/driver_roboswitch.c | 709 +- .../src/drivers/driver_wext.c | 3748 ++-- .../src/drivers/driver_wext.h | 70 +- .../src/drivers/driver_wired.c | 985 +- .../wpa_supplicant-2.6/src/drivers/drivers.c | 33 +- .../src/drivers/linux_defines.h | 24 +- .../src/drivers/linux_ioctl.c | 321 +- .../src/drivers/linux_wext.h | 2 +- .../src/drivers/ndis_events.c | 1245 +- .../wpa_supplicant-2.6/src/drivers/netlink.c | 337 +- .../wpa_supplicant-2.6/src/drivers/netlink.h | 12 +- .../src/drivers/nl80211_copy.h | 2102 +-- .../src/drivers/priv_netlink.h | 86 +- .../wpa_supplicant-2.6/src/drivers/rfkill.c | 323 +- .../wpa_supplicant-2.6/src/drivers/rfkill.h | 10 +- .../wpa_supplicant-2.6/src/eap_common/chap.c | 23 +- .../wpa_supplicant-2.6/src/eap_common/chap.h | 2 +- .../src/eap_common/eap_common.c | 341 +- .../src/eap_common/eap_common.h | 18 +- .../src/eap_common/eap_defs.h | 118 +- .../src/eap_common/eap_eke_common.c | 1133 +- .../src/eap_common/eap_eke_common.h | 75 +- .../src/eap_common/eap_fast_common.c | 417 +- .../src/eap_common/eap_fast_common.h | 49 +- .../src/eap_common/eap_gpsk_common.c | 723 +- .../src/eap_common/eap_gpsk_common.h | 38 +- .../src/eap_common/eap_ikev2_common.c | 152 +- .../src/eap_common/eap_ikev2_common.h | 13 +- .../src/eap_common/eap_pax_common.c | 147 +- .../src/eap_common/eap_pax_common.h | 82 +- .../src/eap_common/eap_peap_common.c | 122 +- .../src/eap_common/eap_peap_common.h | 5 +- .../src/eap_common/eap_psk_common.c | 79 +- .../src/eap_common/eap_psk_common.h | 38 +- .../src/eap_common/eap_pwd_common.c | 584 +- .../src/eap_common/eap_pwd_common.h | 69 +- .../src/eap_common/eap_sake_common.c | 572 +- .../src/eap_common/eap_sake_common.h | 69 +- .../src/eap_common/eap_sim_common.c | 2040 +- .../src/eap_common/eap_sim_common.h | 171 +- .../src/eap_common/eap_tlv_common.h | 64 +- .../src/eap_common/eap_ttls.h | 35 +- .../src/eap_common/eap_wsc_common.c | 29 +- .../src/eap_common/eap_wsc_common.h | 3 +- .../src/eap_common/ikev2_common.c | 1118 +- .../src/eap_common/ikev2_common.h | 387 +- .../wpa_supplicant-2.6/src/eap_peer/eap.c | 3936 ++-- .../wpa_supplicant-2.6/src/eap_peer/eap.h | 457 +- .../wpa_supplicant-2.6/src/eap_peer/eap_aka.c | 2353 +-- .../src/eap_peer/eap_config.h | 1383 +- .../wpa_supplicant-2.6/src/eap_peer/eap_eke.c | 1193 +- .../src/eap_peer/eap_fast.c | 2789 +-- .../src/eap_peer/eap_fast_pac.c | 1328 +- .../src/eap_peer/eap_fast_pac.h | 47 +- .../src/eap_peer/eap_gpsk.c | 1201 +- .../wpa_supplicant-2.6/src/eap_peer/eap_gtc.c | 198 +- .../wpa_supplicant-2.6/src/eap_peer/eap_i.h | 609 +- .../src/eap_peer/eap_ikev2.c | 837 +- .../src/eap_peer/eap_leap.c | 673 +- .../wpa_supplicant-2.6/src/eap_peer/eap_md5.c | 178 +- .../src/eap_peer/eap_methods.c | 380 +- .../src/eap_peer/eap_methods.h | 55 +- .../src/eap_peer/eap_mschapv2.c | 1299 +- .../wpa_supplicant-2.6/src/eap_peer/eap_otp.c | 140 +- .../wpa_supplicant-2.6/src/eap_peer/eap_pax.c | 850 +- .../src/eap_peer/eap_peap.c | 2087 +- .../src/eap_peer/eap_proxy.h | 27 +- .../src/eap_peer/eap_proxy_dummy.c | 68 +- .../wpa_supplicant-2.6/src/eap_peer/eap_psk.c | 787 +- .../wpa_supplicant-2.6/src/eap_peer/eap_pwd.c | 1782 +- .../src/eap_peer/eap_sake.c | 780 +- .../wpa_supplicant-2.6/src/eap_peer/eap_sim.c | 1970 +- .../wpa_supplicant-2.6/src/eap_peer/eap_tls.c | 640 +- .../src/eap_peer/eap_tls_common.c | 1418 +- .../src/eap_peer/eap_tls_common.h | 156 +- .../wpa_supplicant-2.6/src/eap_peer/eap_tnc.c | 647 +- .../src/eap_peer/eap_ttls.c | 2803 +-- .../src/eap_peer/eap_vendor_test.c | 244 +- .../wpa_supplicant-2.6/src/eap_peer/eap_wsc.c | 975 +- .../wpa_supplicant-2.6/src/eap_peer/ikev2.c | 1945 +- .../wpa_supplicant-2.6/src/eap_peer/ikev2.h | 69 +- .../src/eap_peer/mschapv2.c | 178 +- .../src/eap_peer/mschapv2.h | 16 +- .../wpa_supplicant-2.6/src/eap_peer/tncc.c | 1934 +- .../wpa_supplicant-2.6/src/eap_peer/tncc.h | 24 +- .../wpa_supplicant-2.6/src/eap_server/eap.h | 202 +- .../wpa_supplicant-2.6/src/eap_server/eap_i.h | 351 +- .../src/eap_server/eap_methods.h | 9 +- .../src/eap_server/eap_server.c | 3023 +-- .../src/eap_server/eap_server_aka.c | 2078 +- .../src/eap_server/eap_server_eke.c | 1217 +- .../src/eap_server/eap_server_fast.c | 2582 +-- .../src/eap_server/eap_server_gpsk.c | 1032 +- .../src/eap_server/eap_server_gtc.c | 304 +- .../src/eap_server/eap_server_identity.c | 235 +- .../src/eap_server/eap_server_ikev2.c | 886 +- .../src/eap_server/eap_server_md5.c | 220 +- .../src/eap_server/eap_server_methods.c | 154 +- .../src/eap_server/eap_server_mschapv2.c | 878 +- .../src/eap_server/eap_server_pax.c | 880 +- .../src/eap_server/eap_server_peap.c | 2239 +-- .../src/eap_server/eap_server_psk.c | 794 +- .../src/eap_server/eap_server_pwd.c | 1840 +- .../src/eap_server/eap_server_sake.c | 769 +- .../src/eap_server/eap_server_sim.c | 1362 +- .../src/eap_server/eap_server_tls.c | 610 +- .../src/eap_server/eap_server_tls_common.c | 686 +- .../src/eap_server/eap_server_tnc.c | 881 +- .../src/eap_server/eap_server_ttls.c | 2160 ++- .../src/eap_server/eap_server_vendor_test.c | 232 +- .../src/eap_server/eap_server_wsc.c | 796 +- .../src/eap_server/eap_sim_db.c | 2079 +- .../src/eap_server/eap_sim_db.h | 71 +- .../src/eap_server/eap_tls_common.h | 102 +- .../wpa_supplicant-2.6/src/eap_server/ikev2.c | 1869 +- .../wpa_supplicant-2.6/src/eap_server/ikev2.h | 72 +- .../wpa_supplicant-2.6/src/eap_server/tncs.c | 1764 +- .../wpa_supplicant-2.6/src/eap_server/tncs.h | 32 +- .../src/eapol_auth/eapol_auth_dump.c | 488 +- .../src/eapol_auth/eapol_auth_sm.c | 1920 +- .../src/eapol_auth/eapol_auth_sm.h | 124 +- .../src/eapol_auth/eapol_auth_sm_i.h | 257 +- .../src/eapol_supp/eapol_supp_sm.c | 3014 +-- .../src/eapol_supp/eapol_supp_sm.h | 587 +- .../wifi_app/wpa_supplicant-2.6/src/fst/fst.c | 294 +- .../wifi_app/wpa_supplicant-2.6/src/fst/fst.h | 293 +- .../wpa_supplicant-2.6/src/fst/fst_ctrl_aux.c | 74 +- .../wpa_supplicant-2.6/src/fst/fst_ctrl_aux.h | 116 +- .../src/fst/fst_ctrl_defs.h | 108 +- .../src/fst/fst_ctrl_iface.c | 1362 +- .../src/fst/fst_ctrl_iface.h | 11 +- .../wpa_supplicant-2.6/src/fst/fst_defs.h | 91 +- .../wpa_supplicant-2.6/src/fst/fst_group.c | 676 +- .../wpa_supplicant-2.6/src/fst/fst_group.h | 58 +- .../wpa_supplicant-2.6/src/fst/fst_iface.c | 95 +- .../wpa_supplicant-2.6/src/fst/fst_iface.h | 135 +- .../wpa_supplicant-2.6/src/fst/fst_internal.h | 42 +- .../wpa_supplicant-2.6/src/fst/fst_session.c | 2365 +-- .../wpa_supplicant-2.6/src/fst/fst_session.h | 35 +- .../src/l2_packet/l2_packet.h | 37 +- .../src/l2_packet/l2_packet_freebsd.c | 462 +- .../src/l2_packet/l2_packet_linux.c | 716 +- .../src/l2_packet/l2_packet_ndis.c | 757 +- .../src/l2_packet/l2_packet_none.c | 159 +- .../src/l2_packet/l2_packet_pcap.c | 543 +- .../src/l2_packet/l2_packet_privsep.c | 408 +- .../src/l2_packet/l2_packet_winpcap.c | 456 +- .../wifi_app/wpa_supplicant-2.6/src/p2p/p2p.c | 8431 +++++---- .../wifi_app/wpa_supplicant-2.6/src/p2p/p2p.h | 2246 +-- .../wpa_supplicant-2.6/src/p2p/p2p_build.c | 1232 +- .../wpa_supplicant-2.6/src/p2p/p2p_dev_disc.c | 490 +- .../wpa_supplicant-2.6/src/p2p/p2p_go_neg.c | 2552 +-- .../wpa_supplicant-2.6/src/p2p/p2p_group.c | 1535 +- .../wpa_supplicant-2.6/src/p2p/p2p_i.h | 1165 +- .../src/p2p/p2p_invitation.c | 1162 +- .../wpa_supplicant-2.6/src/p2p/p2p_parse.c | 1461 +- .../wpa_supplicant-2.6/src/p2p/p2p_pd.c | 2788 +-- .../wpa_supplicant-2.6/src/p2p/p2p_sd.c | 1478 +- .../wpa_supplicant-2.6/src/p2p/p2p_utils.c | 605 +- .../src/pae/ieee802_1x_cp.c | 909 +- .../src/pae/ieee802_1x_cp.h | 4 +- .../src/pae/ieee802_1x_kay.c | 4770 ++--- .../src/pae/ieee802_1x_kay.h | 229 +- .../src/pae/ieee802_1x_kay_i.h | 524 +- .../src/pae/ieee802_1x_key.c | 185 +- .../src/pae/ieee802_1x_key.h | 14 +- .../src/pae/ieee802_1x_secy_ops.c | 656 +- .../src/pae/ieee802_1x_secy_ops.h | 24 +- .../wpa_supplicant-2.6/src/radius/radius.c | 2586 +-- .../wpa_supplicant-2.6/src/radius/radius.h | 321 +- .../src/radius/radius_client.c | 2366 +-- .../src/radius/radius_client.h | 342 +- .../src/radius/radius_das.c | 654 +- .../src/radius/radius_das.h | 60 +- .../src/radius/radius_server.c | 3274 ++-- .../src/radius/radius_server.h | 376 +- .../wpa_supplicant-2.6/src/rsn_supp/peerkey.c | 1724 +- .../wpa_supplicant-2.6/src/rsn_supp/peerkey.h | 87 +- .../src/rsn_supp/pmksa_cache.c | 688 +- .../src/rsn_supp/pmksa_cache.h | 126 +- .../wpa_supplicant-2.6/src/rsn_supp/preauth.c | 692 +- .../wpa_supplicant-2.6/src/rsn_supp/preauth.h | 61 +- .../wpa_supplicant-2.6/src/rsn_supp/tdls.c | 4514 ++--- .../wpa_supplicant-2.6/src/rsn_supp/wpa.c | 4480 ++--- .../wpa_supplicant-2.6/src/rsn_supp/wpa.h | 397 +- .../wpa_supplicant-2.6/src/rsn_supp/wpa_ft.c | 1274 +- .../wpa_supplicant-2.6/src/rsn_supp/wpa_i.h | 477 +- .../wpa_supplicant-2.6/src/rsn_supp/wpa_ie.c | 886 +- .../wpa_supplicant-2.6/src/rsn_supp/wpa_ie.h | 92 +- .../wpa_supplicant-2.6/src/tls/asn1.c | 341 +- .../wpa_supplicant-2.6/src/tls/asn1.h | 80 +- .../wpa_supplicant-2.6/src/tls/bignum.c | 168 +- .../wpa_supplicant-2.6/src/tls/bignum.h | 12 +- .../wpa_supplicant-2.6/src/tls/libtommath.c | 2047 +- .../wpa_supplicant-2.6/src/tls/pkcs1.c | 509 +- .../wpa_supplicant-2.6/src/tls/pkcs1.h | 22 +- .../wpa_supplicant-2.6/src/tls/pkcs5.c | 1022 +- .../wpa_supplicant-2.6/src/tls/pkcs5.h | 5 +- .../wpa_supplicant-2.6/src/tls/pkcs8.c | 291 +- .../wpa_supplicant-2.6/src/tls/pkcs8.h | 6 +- .../wifi_app/wpa_supplicant-2.6/src/tls/rsa.c | 517 +- .../wifi_app/wpa_supplicant-2.6/src/tls/rsa.h | 15 +- .../wpa_supplicant-2.6/src/tls/tlsv1_client.c | 1125 +- .../wpa_supplicant-2.6/src/tls/tlsv1_client.h | 49 +- .../src/tls/tlsv1_client_i.h | 125 +- .../src/tls/tlsv1_client_ocsp.c | 1350 +- .../src/tls/tlsv1_client_read.c | 2510 +-- .../src/tls/tlsv1_client_write.c | 1586 +- .../wpa_supplicant-2.6/src/tls/tlsv1_common.c | 765 +- .../wpa_supplicant-2.6/src/tls/tlsv1_common.h | 362 +- .../wpa_supplicant-2.6/src/tls/tlsv1_cred.c | 1900 +- .../wpa_supplicant-2.6/src/tls/tlsv1_cred.h | 47 +- .../wpa_supplicant-2.6/src/tls/tlsv1_record.c | 703 +- .../wpa_supplicant-2.6/src/tls/tlsv1_record.h | 63 +- .../wpa_supplicant-2.6/src/tls/tlsv1_server.c | 1050 +- .../wpa_supplicant-2.6/src/tls/tlsv1_server.h | 34 +- .../src/tls/tlsv1_server_i.h | 102 +- .../src/tls/tlsv1_server_read.c | 2041 +- .../src/tls/tlsv1_server_write.c | 1713 +- .../wpa_supplicant-2.6/src/tls/x509v3.c | 3452 ++-- .../wpa_supplicant-2.6/src/tls/x509v3.h | 194 +- .../wpa_supplicant-2.6/src/utils/base64.c | 206 +- .../wpa_supplicant-2.6/src/utils/base64.h | 8 +- .../wpa_supplicant-2.6/src/utils/bitfield.c | 105 +- .../wpa_supplicant-2.6/src/utils/bitfield.h | 2 +- .../src/utils/browser-android.c | 171 +- .../src/utils/browser-system.c | 157 +- .../src/utils/browser-wpadebug.c | 196 +- .../wpa_supplicant-2.6/src/utils/browser.c | 296 +- .../wpa_supplicant-2.6/src/utils/browser.h | 7 +- .../wpa_supplicant-2.6/src/utils/common.c | 1620 +- .../wpa_supplicant-2.6/src/utils/common.h | 306 +- .../wpa_supplicant-2.6/src/utils/edit.c | 1806 +- .../wpa_supplicant-2.6/src/utils/edit.h | 9 +- .../src/utils/edit_readline.c | 261 +- .../src/utils/edit_simple.c | 109 +- .../wpa_supplicant-2.6/src/utils/eloop.c | 1826 +- .../wpa_supplicant-2.6/src/utils/eloop.h | 49 +- .../wpa_supplicant-2.6/src/utils/eloop_win.c | 980 +- .../src/utils/ext_password.c | 124 +- .../src/utils/ext_password.h | 18 +- .../src/utils/ext_password_i.h | 10 +- .../src/utils/ext_password_test.c | 103 +- .../wpa_supplicant-2.6/src/utils/http-utils.h | 57 +- .../wpa_supplicant-2.6/src/utils/http_curl.c | 2538 +-- .../wpa_supplicant-2.6/src/utils/includes.h | 12 +- .../wpa_supplicant-2.6/src/utils/ip_addr.c | 51 +- .../wpa_supplicant-2.6/src/utils/ip_addr.h | 16 +- .../wpa_supplicant-2.6/src/utils/list.h | 105 +- .../wpa_supplicant-2.6/src/utils/os.h | 167 +- .../src/utils/os_internal.c | 805 +- .../wpa_supplicant-2.6/src/utils/os_none.c | 265 +- .../wpa_supplicant-2.6/src/utils/os_unix.c | 1147 +- .../wpa_supplicant-2.6/src/utils/os_win32.c | 381 +- .../wpa_supplicant-2.6/src/utils/pcsc_funcs.c | 2095 ++- .../wpa_supplicant-2.6/src/utils/pcsc_funcs.h | 14 +- .../wpa_supplicant-2.6/src/utils/platform.h | 26 +- .../wpa_supplicant-2.6/src/utils/radiotap.c | 583 +- .../wpa_supplicant-2.6/src/utils/radiotap.h | 217 +- .../src/utils/radiotap_iter.h | 60 +- .../src/utils/state_machine.h | 61 +- .../wpa_supplicant-2.6/src/utils/trace.c | 533 +- .../wpa_supplicant-2.6/src/utils/trace.h | 61 +- .../src/utils/utils_module_tests.c | 1282 +- .../wpa_supplicant-2.6/src/utils/uuid.c | 87 +- .../wpa_supplicant-2.6/src/utils/wpa_debug.c | 1178 +- .../wpa_supplicant-2.6/src/utils/wpa_debug.h | 219 +- .../wpa_supplicant-2.6/src/utils/wpabuf.c | 410 +- .../wpa_supplicant-2.6/src/utils/wpabuf.h | 134 +- .../wpa_supplicant-2.6/src/utils/xml-utils.c | 681 +- .../wpa_supplicant-2.6/src/utils/xml-utils.h | 113 +- .../src/utils/xml_libxml2.c | 623 +- .../wpa_supplicant-2.6/src/wps/http.h | 24 +- .../wpa_supplicant-2.6/src/wps/http_client.c | 546 +- .../wpa_supplicant-2.6/src/wps/http_client.h | 39 +- .../wpa_supplicant-2.6/src/wps/http_server.c | 422 +- .../wpa_supplicant-2.6/src/wps/http_server.h | 19 +- .../wpa_supplicant-2.6/src/wps/httpread.c | 1302 +- .../wpa_supplicant-2.6/src/wps/httpread.h | 63 +- .../wpa_supplicant-2.6/src/wps/ndef.c | 273 +- .../wpa_supplicant-2.6/src/wps/upnp_xml.c | 227 +- .../wpa_supplicant-2.6/src/wps/upnp_xml.h | 13 +- .../wifi_app/wpa_supplicant-2.6/src/wps/wps.c | 823 +- .../wifi_app/wpa_supplicant-2.6/src/wps/wps.h | 1420 +- .../src/wps/wps_attr_build.c | 724 +- .../src/wps/wps_attr_parse.c | 1274 +- .../src/wps/wps_attr_parse.h | 156 +- .../src/wps/wps_attr_process.c | 381 +- .../wpa_supplicant-2.6/src/wps/wps_common.c | 1284 +- .../wpa_supplicant-2.6/src/wps/wps_defs.h | 470 +- .../wpa_supplicant-2.6/src/wps/wps_dev_attr.c | 573 +- .../wpa_supplicant-2.6/src/wps/wps_dev_attr.h | 13 +- .../wpa_supplicant-2.6/src/wps/wps_enrollee.c | 2370 +-- .../wpa_supplicant-2.6/src/wps/wps_er.c | 3248 ++-- .../wpa_supplicant-2.6/src/wps/wps_er.h | 141 +- .../wpa_supplicant-2.6/src/wps/wps_er_ssdp.c | 315 +- .../wpa_supplicant-2.6/src/wps/wps_i.h | 249 +- .../src/wps/wps_module_tests.c | 639 +- .../src/wps/wps_registrar.c | 5482 +++--- .../wpa_supplicant-2.6/src/wps/wps_upnp.c | 1419 +- .../wpa_supplicant-2.6/src/wps/wps_upnp.h | 30 +- .../wpa_supplicant-2.6/src/wps/wps_upnp_ap.c | 102 +- .../src/wps/wps_upnp_event.c | 534 +- .../wpa_supplicant-2.6/src/wps/wps_upnp_i.h | 161 +- .../src/wps/wps_upnp_ssdp.c | 1250 +- .../wpa_supplicant-2.6/src/wps/wps_upnp_web.c | 2195 +-- .../wpa_supplicant-2.6/src/wps/wps_validate.c | 3203 ++-- .../wpa_supplicant-2.6/wpa_supplicant/ap.c | 2120 ++- .../wpa_supplicant-2.6/wpa_supplicant/ap.h | 82 +- .../wpa_supplicant/autoscan.c | 207 +- .../wpa_supplicant/autoscan.h | 24 +- .../wpa_supplicant/autoscan_exponential.c | 113 +- .../wpa_supplicant/autoscan_periodic.c | 80 +- .../wpa_supplicant/bgscan.c | 140 +- .../wpa_supplicant/bgscan.h | 52 +- .../wpa_supplicant/bgscan_learn.c | 928 +- .../wpa_supplicant/bgscan_simple.c | 437 +- .../wpa_supplicant/binder/binder.h | 26 +- .../wpa_supplicant/binder/binder_i.h | 15 +- .../wpa_supplicant/binder/iface.h | 3 +- .../wpa_supplicant/binder/supplicant.h | 3 +- .../wpa_supplicant/blacklist.c | 154 +- .../wpa_supplicant/blacklist.h | 10 +- .../wpa_supplicant-2.6/wpa_supplicant/bss.c | 1618 +- .../wpa_supplicant-2.6/wpa_supplicant/bss.h | 219 +- .../wpa_supplicant/config.c | 6392 ++++--- .../wpa_supplicant/config.h | 2265 +-- .../wpa_supplicant/config_file.c | 2223 +-- .../wpa_supplicant/config_none.c | 55 +- .../wpa_supplicant/config_ssid.h | 1215 +- .../wpa_supplicant/config_winreg.c | 1478 +- .../wpa_supplicant/ctrl_iface.c | 15705 ++++++++-------- .../wpa_supplicant/ctrl_iface.h | 47 +- .../wpa_supplicant/ctrl_iface_named_pipe.c | 1166 +- .../wpa_supplicant/ctrl_iface_udp.c | 1118 +- .../wpa_supplicant/ctrl_iface_unix.c | 2163 ++- .../wpa_supplicant/dbus/dbus_common.c | 420 +- .../wpa_supplicant/dbus/dbus_common.h | 2 +- .../wpa_supplicant/dbus/dbus_common_i.h | 16 +- .../wpa_supplicant/dbus/dbus_dict_helpers.c | 1227 +- .../wpa_supplicant/dbus/dbus_dict_helpers.h | 145 +- .../wpa_supplicant/dbus/dbus_new.c | 5457 +++--- .../wpa_supplicant/dbus/dbus_new.h | 628 +- .../wpa_supplicant/dbus/dbus_new_handlers.c | 5497 +++--- .../wpa_supplicant/dbus/dbus_new_handlers.h | 189 +- .../dbus/dbus_new_handlers_p2p.c | 4310 +++-- .../dbus/dbus_new_handlers_p2p.h | 112 +- .../dbus/dbus_new_handlers_wps.c | 564 +- .../wpa_supplicant/dbus/dbus_new_helpers.c | 1293 +- .../wpa_supplicant/dbus/dbus_new_helpers.h | 145 +- .../wpa_supplicant/dbus/dbus_new_introspect.c | 359 +- .../wpa_supplicant/dbus/dbus_old.c | 927 +- .../wpa_supplicant/dbus/dbus_old.h | 127 +- .../wpa_supplicant/dbus/dbus_old_handlers.c | 1804 +- .../wpa_supplicant/dbus/dbus_old_handlers.h | 120 +- .../dbus/dbus_old_handlers_wps.c | 164 +- .../wpa_supplicant/driver_i.h | 1231 +- .../wpa_supplicant/eap_register.c | 192 +- .../wpa_supplicant/eapol_test.c | 2467 +-- .../wpa_supplicant/events.c | 6358 ++++--- .../wpa_supplicant/gas_query.c | 1123 +- .../wpa_supplicant/gas_query.h | 40 +- .../wpa_supplicant/hs20_supplicant.c | 1949 +- .../wpa_supplicant/hs20_supplicant.h | 20 +- .../wpa_supplicant/ibss_rsn.c | 1345 +- .../wpa_supplicant/ibss_rsn.h | 51 +- .../wpa_supplicant/interworking.c | 4949 ++--- .../wpa_supplicant/interworking.h | 26 +- .../wpa_supplicant/libwpa_test.c | 31 +- .../wpa_supplicant-2.6/wpa_supplicant/main.c | 604 +- .../wpa_supplicant/main_none.c | 37 +- .../wpa_supplicant/main_winmain.c | 89 +- .../wpa_supplicant/main_winsvc.c | 620 +- .../wpa_supplicant-2.6/wpa_supplicant/mbo.c | 1174 +- .../wpa_supplicant-2.6/wpa_supplicant/mesh.c | 990 +- .../wpa_supplicant-2.6/wpa_supplicant/mesh.h | 24 +- .../wpa_supplicant/mesh_mpm.c | 1959 +- .../wpa_supplicant/mesh_mpm.h | 20 +- .../wpa_supplicant/mesh_rsn.c | 1136 +- .../wpa_supplicant/mesh_rsn.h | 41 +- .../wpa_supplicant/nfc_pw_token.c | 100 +- .../wpa_supplicant/notify.c | 960 +- .../wpa_supplicant/notify.h | 125 +- .../wpa_supplicant/offchannel.c | 647 +- .../wpa_supplicant/offchannel.h | 28 +- .../wpa_supplicant/p2p_supplicant.c | 14360 +++++++------- .../wpa_supplicant/p2p_supplicant.h | 341 +- .../wpa_supplicant/p2p_supplicant_sd.c | 1834 +- .../wpa_supplicant/preauth_test.c | 467 +- .../wpa_supplicant-2.6/wpa_supplicant/scan.c | 4007 ++-- .../wpa_supplicant-2.6/wpa_supplicant/scan.h | 40 +- .../wpa_supplicant-2.6/wpa_supplicant/sme.c | 2582 +-- .../wpa_supplicant-2.6/wpa_supplicant/sme.h | 97 +- .../wpa_supplicant/wifi_display.c | 624 +- .../wpa_supplicant/wifi_display.h | 8 +- .../wpa_supplicant/win_if_list.c | 206 +- .../wpa_supplicant/wmm_ac.c | 1396 +- .../wpa_supplicant/wmm_ac.h | 161 +- .../wpa_supplicant/wnm_sta.c | 2490 +-- .../wpa_supplicant/wnm_sta.h | 75 +- .../wpa_supplicant/wpa_cli.c | 6160 +++--- .../wpa_supplicant/wpa_gui-qt4/addinterface.h | 19 +- .../wpa_supplicant/wpa_gui-qt4/eventhistory.h | 47 +- .../wpa_gui-qt4/networkconfig.h | 53 +- .../wpa_supplicant/wpa_gui-qt4/peers.h | 121 +- .../wpa_supplicant/wpa_gui-qt4/scanresults.h | 27 +- .../wpa_gui-qt4/scanresultsitem.h | 7 +- .../wpa_supplicant/wpa_gui-qt4/signalbar.h | 14 +- .../wpa_supplicant/wpa_gui-qt4/stringquery.h | 13 +- .../wpa_gui-qt4/userdatarequest.h | 25 +- .../wpa_supplicant/wpa_gui-qt4/wpagui.h | 254 +- .../wpa_supplicant/wpa_gui-qt4/wpamsg.h | 21 +- .../wpa_supplicant/wpa_passphrase.c | 90 +- .../wpa_supplicant/wpa_priv.c | 1809 +- .../wpa_supplicant/wpa_supplicant.c | 9880 +++++----- .../wpa_supplicant/wpa_supplicant_i.h | 1726 +- .../wpa_supplicant/wpas_glue.c | 1574 +- .../wpa_supplicant/wpas_glue.h | 10 +- .../wpa_supplicant/wpas_kay.c | 485 +- .../wpa_supplicant/wpas_kay.h | 23 +- .../wpa_supplicant/wpas_module_tests.c | 118 +- .../wpa_supplicant/wps_supplicant.c | 4503 ++--- .../wpa_supplicant/wps_supplicant.h | 131 +- 1323 files changed, 537512 insertions(+), 492255 deletions(-) mode change 100644 => 100755 project/app/wifi_app/hisi_tools/app/include/hi_base.h mode change 100644 => 100755 project/app/wifi_app/hisi_tools/app/vlinktest/cJSON.c mode change 100644 => 100755 project/app/wifi_app/hisi_tools/app/vlinktest/cJSON.h mode change 100644 => 100755 project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host.c mode change 100644 => 100755 project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host.h mode change 100644 => 100755 project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host_comm.c mode change 100644 => 100755 project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host_comm.h mode change 100644 => 100755 project/app/wifi_app/hisi_tools/app/vlinktest/vlink_hichannel_cmd.c mode change 100644 => 100755 project/app/wifi_app/hisi_tools/app/vlinktest/vlink_wifi_ota_main.c mode change 100644 => 100755 project/app/wifi_app/wifi/include/Rk_wifi.h mode change 100644 => 100755 project/app/wifi_app/wifi/include/rk_wifi_hal.h mode change 100644 => 100755 project/app/wifi_app/wifi/src/hisi_tools/vlinktest/vlink_hichannel_cmd.c mode change 100644 => 100755 project/app/wifi_app/wifi/src/hisi_tools/vlinktest/vlink_hichannel_main.c mode change 100644 => 100755 project/app/wifi_app/wifi/src/rk_hisi_wifi.c mode change 100644 => 100755 project/app/wifi_app/wifi/src/rk_wifi_hal.c mode change 100644 => 100755 project/app/wifi_app/wifi/test/rk_wifi_test.c diff --git a/project/app/wifi_app/.gitignore b/project/app/wifi_app/.gitignore index 5af35bb2f..43868f898 100644 --- a/project/app/wifi_app/.gitignore +++ b/project/app/wifi_app/.gitignore @@ -1,12 +1,4 @@ -# *.o -# !hostapd-2.6/hostapd/*.o -# !hostapd-2.6/src/common/*.o -# !hostapd-2.6/src/crypto/*.o -# !hostapd-2.6/src/drivers/*.o -# !hostapd-2.6/src/drivers/*.o -# !hostapd-2.6/src/drivers/*.o -# !hostapd-2.6/src/drivers/*.o - +*.o hostapd-2.6/hostapd/hostapd hostapd-2.6/hostapd/hostapd_cli install_out diff --git a/project/app/wifi_app/hisi_tools/app/client/cJSON.c b/project/app/wifi_app/hisi_tools/app/client/cJSON.c index 8c282309c..030311ce5 100644 --- a/project/app/wifi_app/hisi_tools/app/client/cJSON.c +++ b/project/app/wifi_app/hisi_tools/app/client/cJSON.c @@ -32,25 +32,25 @@ #pragma GCC visibility push(default) #endif #if defined(_MSC_VER) -#pragma warning(push) +#pragma warning (push) /* disable warning about single line comments in system headers */ -#pragma warning(disable : 4001) +#pragma warning (disable : 4001) #endif +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include #ifdef ENABLE_LOCALES #include #endif #if defined(_MSC_VER) -#pragma warning(pop) +#pragma warning (pop) #endif #ifdef __GNUC__ #pragma GCC visibility pop @@ -69,8 +69,7 @@ #endif #define false ((cJSON_bool)0) -/* define isnan and isinf for ANSI C, if in C99 or above, isnan and isinf has - * been defined in math.h */ +/* define isnan and isinf for ANSI C, if in C99 or above, isnan and isinf has been defined in math.h */ #ifndef isinf #define isinf(d) (isnan((d - d)) && !isnan(d)) #endif @@ -82,85 +81,98 @@ #ifdef _WIN32 #define NAN sqrt(-1.0) #else -#define NAN 0.0 / 0.0 +#define NAN 0.0/0.0 #endif #endif typedef struct { - const unsigned char *json; - size_t position; + const unsigned char *json; + size_t position; } error; -static error global_error = {NULL, 0}; +static error global_error = { NULL, 0 }; -CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) { - return (const char *)(global_error.json + global_error.position); +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) +{ + return (const char*) (global_error.json + global_error.position); } -CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item) { - if (!cJSON_IsString(item)) { - return NULL; - } +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item) +{ + if (!cJSON_IsString(item)) + { + return NULL; + } - return item->valuestring; + return item->valuestring; } -CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item) { - if (!cJSON_IsNumber(item)) { - return (double)NAN; - } +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item) +{ + if (!cJSON_IsNumber(item)) + { + return (double) NAN; + } - return item->valuedouble; + return item->valuedouble; } -/* This is a safeguard to prevent copy-pasters from using incompatible C and - * header files */ -#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || \ - (CJSON_VERSION_PATCH != 14) -#error cJSON.h and cJSON.c have different versions. Make sure that both have the same. +/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ +#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 14) + #error cJSON.h and cJSON.c have different versions. Make sure that both have the same. #endif -CJSON_PUBLIC(const char *) cJSON_Version(void) { - static char version[15]; - sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, - CJSON_VERSION_PATCH); +CJSON_PUBLIC(const char*) cJSON_Version(void) +{ + static char version[15]; + sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); - return version; + return version; } -/* Case insensitive string comparison, doesn't consider two NULL pointers equal - * though */ -static int case_insensitive_strcmp(const unsigned char *string1, - const unsigned char *string2) { - if ((string1 == NULL) || (string2 == NULL)) { - return 1; - } - - if (string1 == string2) { - return 0; - } - - for (; tolower(*string1) == tolower(*string2); (void)string1++, string2++) { - if (*string1 == '\0') { - return 0; +/* Case insensitive string comparison, doesn't consider two NULL pointers equal though */ +static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) +{ + if ((string1 == NULL) || (string2 == NULL)) + { + return 1; } - } - return tolower(*string1) - tolower(*string2); + if (string1 == string2) + { + return 0; + } + + for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++) + { + if (*string1 == '\0') + { + return 0; + } + } + + return tolower(*string1) - tolower(*string2); } -typedef struct internal_hooks { - void *(CJSON_CDECL *allocate)(size_t size); - void(CJSON_CDECL *deallocate)(void *pointer); - void *(CJSON_CDECL *reallocate)(void *pointer, size_t size); +typedef struct internal_hooks +{ + void *(CJSON_CDECL *allocate)(size_t size); + void (CJSON_CDECL *deallocate)(void *pointer); + void *(CJSON_CDECL *reallocate)(void *pointer, size_t size); } internal_hooks; #if defined(_MSC_VER) -/* work around MSVC error C2322: '...' address of dllimport '...' is not static - */ -static void *CJSON_CDECL internal_malloc(size_t size) { return malloc(size); } -static void CJSON_CDECL internal_free(void *pointer) { free(pointer); } -static void *CJSON_CDECL internal_realloc(void *pointer, size_t size) { - return realloc(pointer, size); +/* work around MSVC error C2322: '...' address of dllimport '...' is not static */ +static void * CJSON_CDECL internal_malloc(size_t size) +{ + return malloc(size); +} +static void CJSON_CDECL internal_free(void *pointer) +{ + free(pointer); +} +static void * CJSON_CDECL internal_realloc(void *pointer, size_t size) +{ + return realloc(pointer, size); } #else #define internal_malloc malloc @@ -171,2617 +183,2928 @@ static void *CJSON_CDECL internal_realloc(void *pointer, size_t size) { /* strlen of character literals resolved at compile time */ #define static_strlen(string_literal) (sizeof(string_literal) - sizeof("")) -static internal_hooks global_hooks = {internal_malloc, internal_free, - internal_realloc}; +static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc }; -static unsigned char *cJSON_strdup(const unsigned char *string, - const internal_hooks *const hooks) { - size_t length = 0; - unsigned char *copy = NULL; +static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) +{ + size_t length = 0; + unsigned char *copy = NULL; - if (string == NULL) { - return NULL; - } + if (string == NULL) + { + return NULL; + } - length = strlen((const char *)string) + sizeof(""); - copy = (unsigned char *)hooks->allocate(length); - if (copy == NULL) { - return NULL; - } - memcpy(copy, string, length); + length = strlen((const char*)string) + sizeof(""); + copy = (unsigned char*)hooks->allocate(length); + if (copy == NULL) + { + return NULL; + } + memcpy(copy, string, length); - return copy; + return copy; } -CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks) { - if (hooks == NULL) { - /* Reset hooks */ +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) +{ + if (hooks == NULL) + { + /* Reset hooks */ + global_hooks.allocate = malloc; + global_hooks.deallocate = free; + global_hooks.reallocate = realloc; + return; + } + global_hooks.allocate = malloc; + if (hooks->malloc_fn != NULL) + { + global_hooks.allocate = hooks->malloc_fn; + } + global_hooks.deallocate = free; - global_hooks.reallocate = realloc; - return; - } + if (hooks->free_fn != NULL) + { + global_hooks.deallocate = hooks->free_fn; + } - global_hooks.allocate = malloc; - if (hooks->malloc_fn != NULL) { - global_hooks.allocate = hooks->malloc_fn; - } - - global_hooks.deallocate = free; - if (hooks->free_fn != NULL) { - global_hooks.deallocate = hooks->free_fn; - } - - /* use realloc only if both free and malloc are used */ - global_hooks.reallocate = NULL; - if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) { - global_hooks.reallocate = realloc; - } + /* use realloc only if both free and malloc are used */ + global_hooks.reallocate = NULL; + if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) + { + global_hooks.reallocate = realloc; + } } /* Internal constructor. */ -static cJSON *cJSON_New_Item(const internal_hooks *const hooks) { - cJSON *node = (cJSON *)hooks->allocate(sizeof(cJSON)); - if (node) { - memset(node, '\0', sizeof(cJSON)); - } +static cJSON *cJSON_New_Item(const internal_hooks * const hooks) +{ + cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); + if (node) + { + memset(node, '\0', sizeof(cJSON)); + } - return node; + return node; } /* Delete a cJSON structure. */ -CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) { - cJSON *next = NULL; - while (item != NULL) { - next = item->next; - if (!(item->type & cJSON_IsReference) && (item->child != NULL)) { - cJSON_Delete(item->child); +CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) +{ + cJSON *next = NULL; + while (item != NULL) + { + next = item->next; + if (!(item->type & cJSON_IsReference) && (item->child != NULL)) + { + cJSON_Delete(item->child); + } + if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) + { + global_hooks.deallocate(item->valuestring); + } + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + global_hooks.deallocate(item->string); + } + global_hooks.deallocate(item); + item = next; } - if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) { - global_hooks.deallocate(item->valuestring); - } - if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) { - global_hooks.deallocate(item->string); - } - global_hooks.deallocate(item); - item = next; - } } /* get the decimal point character of the current locale */ -static unsigned char get_decimal_point(void) { +static unsigned char get_decimal_point(void) +{ #ifdef ENABLE_LOCALES - struct lconv *lconv = localeconv(); - return (unsigned char)lconv->decimal_point[0]; + struct lconv *lconv = localeconv(); + return (unsigned char) lconv->decimal_point[0]; #else - return '.'; + return '.'; #endif } -typedef struct { - const unsigned char *content; - size_t length; - size_t offset; - size_t depth; /* How deeply nested (in arrays/objects) is the input at the - current offset. */ - internal_hooks hooks; +typedef struct +{ + const unsigned char *content; + size_t length; + size_t offset; + size_t depth; /* How deeply nested (in arrays/objects) is the input at the current offset. */ + internal_hooks hooks; } parse_buffer; -/* check if the given size is left to read in a given parse buffer (starting - * with 1) */ -#define can_read(buffer, size) \ - ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) +/* check if the given size is left to read in a given parse buffer (starting with 1) */ +#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) /* check if the buffer can be accessed at the given index (starting with 0) */ -#define can_access_at_index(buffer, index) \ - ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) -#define cannot_access_at_index(buffer, index) \ - (!can_access_at_index(buffer, index)) +#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) +#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index)) /* get a pointer to the buffer at the position */ #define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) -/* Parse the input text to generate a number, and populate the result into item. - */ -static cJSON_bool parse_number(cJSON *const item, - parse_buffer *const input_buffer) { - double number = 0; - unsigned char *after_end = NULL; - unsigned char number_c_string[64]; - unsigned char decimal_point = get_decimal_point(); - size_t i = 0; +/* Parse the input text to generate a number, and populate the result into item. */ +static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) +{ + double number = 0; + unsigned char *after_end = NULL; + unsigned char number_c_string[64]; + unsigned char decimal_point = get_decimal_point(); + size_t i = 0; - if ((input_buffer == NULL) || (input_buffer->content == NULL)) { - return false; - } - - /* copy the number into a temporary buffer and replace '.' with the decimal - * point of the current locale (for strtod) This also takes care of '\0' not - * necessarily being available for marking the end of the input */ - for (i = 0; (i < (sizeof(number_c_string) - 1)) && - can_access_at_index(input_buffer, i); - i++) { - switch (buffer_at_offset(input_buffer)[i]) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '+': - case '-': - case 'e': - case 'E': - number_c_string[i] = buffer_at_offset(input_buffer)[i]; - break; - - case '.': - number_c_string[i] = decimal_point; - break; - - default: - goto loop_end; + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; + } + + /* copy the number into a temporary buffer and replace '.' with the decimal point + * of the current locale (for strtod) + * This also takes care of '\0' not necessarily being available for marking the end of the input */ + for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) + { + switch (buffer_at_offset(input_buffer)[i]) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '+': + case '-': + case 'e': + case 'E': + number_c_string[i] = buffer_at_offset(input_buffer)[i]; + break; + + case '.': + number_c_string[i] = decimal_point; + break; + + default: + goto loop_end; + } } - } loop_end: - number_c_string[i] = '\0'; + number_c_string[i] = '\0'; - number = strtod((const char *)number_c_string, (char **)&after_end); - if (number_c_string == after_end) { - return false; /* parse_error */ - } + number = strtod((const char*)number_c_string, (char**)&after_end); + if (number_c_string == after_end) + { + return false; /* parse_error */ + } - item->valuedouble = number; + item->valuedouble = number; - /* use saturation in case of overflow */ - if (number >= INT_MAX) { - item->valueint = INT_MAX; - } else if (number <= (double)INT_MIN) { - item->valueint = INT_MIN; - } else { - item->valueint = (int)number; - } + /* use saturation in case of overflow */ + if (number >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (number <= (double)INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)number; + } - item->type = cJSON_Number; + item->type = cJSON_Number; - input_buffer->offset += (size_t)(after_end - number_c_string); - return true; + input_buffer->offset += (size_t)(after_end - number_c_string); + return true; } -/* don't ask me, but the original cJSON_SetNumberValue returns an integer or - * double */ -CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) { - if (number >= INT_MAX) { - object->valueint = INT_MAX; - } else if (number <= (double)INT_MIN) { - object->valueint = INT_MIN; - } else { - object->valueint = (int)number; - } +/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) +{ + if (number >= INT_MAX) + { + object->valueint = INT_MAX; + } + else if (number <= (double)INT_MIN) + { + object->valueint = INT_MIN; + } + else + { + object->valueint = (int)number; + } - return object->valuedouble = number; + return object->valuedouble = number; } -CJSON_PUBLIC(char *) -cJSON_SetValuestring(cJSON *object, const char *valuestring) { - char *copy = NULL; - /* if object's type is not cJSON_String or is cJSON_IsReference, it should not - * set valuestring */ - if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) { - return NULL; - } - if (strlen(valuestring) <= strlen(object->valuestring)) { - strcpy(object->valuestring, valuestring); - return object->valuestring; - } - copy = - (char *)cJSON_strdup((const unsigned char *)valuestring, &global_hooks); - if (copy == NULL) { - return NULL; - } - if (object->valuestring != NULL) { - cJSON_free(object->valuestring); - } - object->valuestring = copy; +CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring) +{ + char *copy = NULL; + /* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */ + if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) + { + return NULL; + } + if (strlen(valuestring) <= strlen(object->valuestring)) + { + strcpy(object->valuestring, valuestring); + return object->valuestring; + } + copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks); + if (copy == NULL) + { + return NULL; + } + if (object->valuestring != NULL) + { + cJSON_free(object->valuestring); + } + object->valuestring = copy; - return copy; + return copy; } -typedef struct { - unsigned char *buffer; - size_t length; - size_t offset; - size_t depth; /* current nesting depth (for formatted printing) */ - cJSON_bool noalloc; - cJSON_bool format; /* is this print a formatted print */ - internal_hooks hooks; +typedef struct +{ + unsigned char *buffer; + size_t length; + size_t offset; + size_t depth; /* current nesting depth (for formatted printing) */ + cJSON_bool noalloc; + cJSON_bool format; /* is this print a formatted print */ + internal_hooks hooks; } printbuffer; /* realloc printbuffer if necessary to have at least "needed" bytes more */ -static unsigned char *ensure(printbuffer *const p, size_t needed) { - unsigned char *newbuffer = NULL; - size_t newsize = 0; +static unsigned char* ensure(printbuffer * const p, size_t needed) +{ + unsigned char *newbuffer = NULL; + size_t newsize = 0; - if ((p == NULL) || (p->buffer == NULL)) { - return NULL; - } - - if ((p->length > 0) && (p->offset >= p->length)) { - /* make sure that offset is valid */ - return NULL; - } - - if (needed > INT_MAX) { - /* sizes bigger than INT_MAX are currently not supported */ - return NULL; - } - - needed += p->offset + 1; - if (needed <= p->length) { - return p->buffer + p->offset; - } - - if (p->noalloc) { - return NULL; - } - - /* calculate new buffer size */ - if (needed > (INT_MAX / 2)) { - /* overflow of int, use INT_MAX if possible */ - if (needed <= INT_MAX) { - newsize = INT_MAX; - } else { - return NULL; - } - } else { - newsize = needed * 2; - } - - if (p->hooks.reallocate != NULL) { - /* reallocate with realloc if available */ - newbuffer = (unsigned char *)p->hooks.reallocate(p->buffer, newsize); - if (newbuffer == NULL) { - p->hooks.deallocate(p->buffer); - p->length = 0; - p->buffer = NULL; - - return NULL; - } - } else { - /* otherwise reallocate manually */ - newbuffer = (unsigned char *)p->hooks.allocate(newsize); - if (!newbuffer) { - p->hooks.deallocate(p->buffer); - p->length = 0; - p->buffer = NULL; - - return NULL; + if ((p == NULL) || (p->buffer == NULL)) + { + return NULL; } - memcpy(newbuffer, p->buffer, p->offset + 1); - p->hooks.deallocate(p->buffer); - } - p->length = newsize; - p->buffer = newbuffer; + if ((p->length > 0) && (p->offset >= p->length)) + { + /* make sure that offset is valid */ + return NULL; + } - return newbuffer + p->offset; + if (needed > INT_MAX) + { + /* sizes bigger than INT_MAX are currently not supported */ + return NULL; + } + + needed += p->offset + 1; + if (needed <= p->length) + { + return p->buffer + p->offset; + } + + if (p->noalloc) { + return NULL; + } + + /* calculate new buffer size */ + if (needed > (INT_MAX / 2)) + { + /* overflow of int, use INT_MAX if possible */ + if (needed <= INT_MAX) + { + newsize = INT_MAX; + } + else + { + return NULL; + } + } + else + { + newsize = needed * 2; + } + + if (p->hooks.reallocate != NULL) + { + /* reallocate with realloc if available */ + newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); + if (newbuffer == NULL) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + } + else + { + /* otherwise reallocate manually */ + newbuffer = (unsigned char*)p->hooks.allocate(newsize); + if (!newbuffer) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + + memcpy(newbuffer, p->buffer, p->offset + 1); + p->hooks.deallocate(p->buffer); + } + p->length = newsize; + p->buffer = newbuffer; + + return newbuffer + p->offset; } -/* calculate the new length of the string in a printbuffer and update the offset - */ -static void update_offset(printbuffer *const buffer) { - const unsigned char *buffer_pointer = NULL; - if ((buffer == NULL) || (buffer->buffer == NULL)) { - return; - } - buffer_pointer = buffer->buffer + buffer->offset; +/* calculate the new length of the string in a printbuffer and update the offset */ +static void update_offset(printbuffer * const buffer) +{ + const unsigned char *buffer_pointer = NULL; + if ((buffer == NULL) || (buffer->buffer == NULL)) + { + return; + } + buffer_pointer = buffer->buffer + buffer->offset; - buffer->offset += strlen((const char *)buffer_pointer); + buffer->offset += strlen((const char*)buffer_pointer); } /* securely comparison of floating-point variables */ -static cJSON_bool compare_double(double a, double b) { - double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b); - return (fabs(a - b) <= maxVal * DBL_EPSILON); +static cJSON_bool compare_double(double a, double b) +{ + double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b); + return (fabs(a - b) <= maxVal * DBL_EPSILON); } /* Render the number nicely from the given item into a string. */ -static cJSON_bool print_number(const cJSON *const item, - printbuffer *const output_buffer) { - unsigned char *output_pointer = NULL; - double d = item->valuedouble; - int length = 0; - size_t i = 0; - unsigned char number_buffer[26] = { - 0}; /* temporary buffer to print the number into */ - unsigned char decimal_point = get_decimal_point(); - double test = 0.0; +static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + double d = item->valuedouble; + int length = 0; + size_t i = 0; + unsigned char number_buffer[26] = {0}; /* temporary buffer to print the number into */ + unsigned char decimal_point = get_decimal_point(); + double test = 0.0; - if (output_buffer == NULL) { - return false; - } - - /* This checks for NaN and Infinity */ - if (isnan(d) || isinf(d)) { - length = sprintf((char *)number_buffer, "null"); - } else { - /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits - */ - length = sprintf((char *)number_buffer, "%1.15g", d); - - /* Check whether the original double can be recovered */ - if ((sscanf((char *)number_buffer, "%lg", &test) != 1) || - !compare_double((double)test, d)) { - /* If not, print with 17 decimal places of precision */ - length = sprintf((char *)number_buffer, "%1.17g", d); - } - } - - /* sprintf failed or buffer overrun occurred */ - if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) { - return false; - } - - /* reserve appropriate space in the output */ - output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); - if (output_pointer == NULL) { - return false; - } - - /* copy the printed number to the output and replace locale - * dependent decimal point with '.' */ - for (i = 0; i < ((size_t)length); i++) { - if (number_buffer[i] == decimal_point) { - output_pointer[i] = '.'; - continue; + if (output_buffer == NULL) + { + return false; } - output_pointer[i] = number_buffer[i]; - } - output_pointer[i] = '\0'; + /* This checks for NaN and Infinity */ + if (isnan(d) || isinf(d)) + { + length = sprintf((char*)number_buffer, "null"); + } + else + { + /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */ + length = sprintf((char*)number_buffer, "%1.15g", d); - output_buffer->offset += (size_t)length; + /* Check whether the original double can be recovered */ + if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d)) + { + /* If not, print with 17 decimal places of precision */ + length = sprintf((char*)number_buffer, "%1.17g", d); + } + } - return true; + /* sprintf failed or buffer overrun occurred */ + if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) + { + return false; + } + + /* reserve appropriate space in the output */ + output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); + if (output_pointer == NULL) + { + return false; + } + + /* copy the printed number to the output and replace locale + * dependent decimal point with '.' */ + for (i = 0; i < ((size_t)length); i++) + { + if (number_buffer[i] == decimal_point) + { + output_pointer[i] = '.'; + continue; + } + + output_pointer[i] = number_buffer[i]; + } + output_pointer[i] = '\0'; + + output_buffer->offset += (size_t)length; + + return true; } /* parse 4 digit hexadecimal number */ -static unsigned parse_hex4(const unsigned char *const input) { - unsigned int h = 0; - size_t i = 0; +static unsigned parse_hex4(const unsigned char * const input) +{ + unsigned int h = 0; + size_t i = 0; - for (i = 0; i < 4; i++) { - /* parse digit */ - if ((input[i] >= '0') && (input[i] <= '9')) { - h += (unsigned int)input[i] - '0'; - } else if ((input[i] >= 'A') && (input[i] <= 'F')) { - h += (unsigned int)10 + input[i] - 'A'; - } else if ((input[i] >= 'a') && (input[i] <= 'f')) { - h += (unsigned int)10 + input[i] - 'a'; - } else /* invalid */ + for (i = 0; i < 4; i++) { - return 0; + /* parse digit */ + if ((input[i] >= '0') && (input[i] <= '9')) + { + h += (unsigned int) input[i] - '0'; + } + else if ((input[i] >= 'A') && (input[i] <= 'F')) + { + h += (unsigned int) 10 + input[i] - 'A'; + } + else if ((input[i] >= 'a') && (input[i] <= 'f')) + { + h += (unsigned int) 10 + input[i] - 'a'; + } + else /* invalid */ + { + return 0; + } + + if (i < 3) + { + /* shift left to make place for the next nibble */ + h = h << 4; + } } - if (i < 3) { - /* shift left to make place for the next nibble */ - h = h << 4; - } - } - - return h; + return h; } /* converts a UTF-16 literal to UTF-8 * A literal can be one or two sequences of the form \uXXXX */ -static unsigned char -utf16_literal_to_utf8(const unsigned char *const input_pointer, - const unsigned char *const input_end, - unsigned char **output_pointer) { - long unsigned int codepoint = 0; - unsigned int first_code = 0; - const unsigned char *first_sequence = input_pointer; - unsigned char utf8_length = 0; - unsigned char utf8_position = 0; - unsigned char sequence_length = 0; - unsigned char first_byte_mark = 0; +static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer) +{ + long unsigned int codepoint = 0; + unsigned int first_code = 0; + const unsigned char *first_sequence = input_pointer; + unsigned char utf8_length = 0; + unsigned char utf8_position = 0; + unsigned char sequence_length = 0; + unsigned char first_byte_mark = 0; - if ((input_end - first_sequence) < 6) { - /* input ends unexpectedly */ - goto fail; - } - - /* get the first utf16 sequence */ - first_code = parse_hex4(first_sequence + 2); - - /* check that the code is valid */ - if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) { - goto fail; - } - - /* UTF16 surrogate pair */ - if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) { - const unsigned char *second_sequence = first_sequence + 6; - unsigned int second_code = 0; - sequence_length = 12; /* \uXXXX\uXXXX */ - - if ((input_end - second_sequence) < 6) { - /* input ends unexpectedly */ - goto fail; + if ((input_end - first_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; } - if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) { - /* missing second half of the surrogate pair */ - goto fail; - } + /* get the first utf16 sequence */ + first_code = parse_hex4(first_sequence + 2); - /* get the second utf16 sequence */ - second_code = parse_hex4(second_sequence + 2); /* check that the code is valid */ - if ((second_code < 0xDC00) || (second_code > 0xDFFF)) { - /* invalid second half of the surrogate pair */ - goto fail; + if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) + { + goto fail; } - /* calculate the unicode codepoint from the surrogate pair */ - codepoint = - 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); - } else { - sequence_length = 6; /* \uXXXX */ - codepoint = first_code; - } + /* UTF16 surrogate pair */ + if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) + { + const unsigned char *second_sequence = first_sequence + 6; + unsigned int second_code = 0; + sequence_length = 12; /* \uXXXX\uXXXX */ - /* encode as UTF-8 - * takes at maximum 4 bytes to encode: - * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ - if (codepoint < 0x80) { - /* normal ascii, encoding 0xxxxxxx */ - utf8_length = 1; - } else if (codepoint < 0x800) { - /* two bytes, encoding 110xxxxx 10xxxxxx */ - utf8_length = 2; - first_byte_mark = 0xC0; /* 11000000 */ - } else if (codepoint < 0x10000) { - /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ - utf8_length = 3; - first_byte_mark = 0xE0; /* 11100000 */ - } else if (codepoint <= 0x10FFFF) { - /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ - utf8_length = 4; - first_byte_mark = 0xF0; /* 11110000 */ - } else { - /* invalid unicode codepoint */ - goto fail; - } + if ((input_end - second_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; + } - /* encode as utf8 */ - for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; - utf8_position--) { - /* 10xxxxxx */ - (*output_pointer)[utf8_position] = - (unsigned char)((codepoint | 0x80) & 0xBF); - codepoint >>= 6; - } - /* encode first byte */ - if (utf8_length > 1) { - (*output_pointer)[0] = - (unsigned char)((codepoint | first_byte_mark) & 0xFF); - } else { - (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); - } + if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) + { + /* missing second half of the surrogate pair */ + goto fail; + } - *output_pointer += utf8_length; + /* get the second utf16 sequence */ + second_code = parse_hex4(second_sequence + 2); + /* check that the code is valid */ + if ((second_code < 0xDC00) || (second_code > 0xDFFF)) + { + /* invalid second half of the surrogate pair */ + goto fail; + } - return sequence_length; + + /* calculate the unicode codepoint from the surrogate pair */ + codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); + } + else + { + sequence_length = 6; /* \uXXXX */ + codepoint = first_code; + } + + /* encode as UTF-8 + * takes at maximum 4 bytes to encode: + * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + if (codepoint < 0x80) + { + /* normal ascii, encoding 0xxxxxxx */ + utf8_length = 1; + } + else if (codepoint < 0x800) + { + /* two bytes, encoding 110xxxxx 10xxxxxx */ + utf8_length = 2; + first_byte_mark = 0xC0; /* 11000000 */ + } + else if (codepoint < 0x10000) + { + /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ + utf8_length = 3; + first_byte_mark = 0xE0; /* 11100000 */ + } + else if (codepoint <= 0x10FFFF) + { + /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + utf8_length = 4; + first_byte_mark = 0xF0; /* 11110000 */ + } + else + { + /* invalid unicode codepoint */ + goto fail; + } + + /* encode as utf8 */ + for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) + { + /* 10xxxxxx */ + (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF); + codepoint >>= 6; + } + /* encode first byte */ + if (utf8_length > 1) + { + (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF); + } + else + { + (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); + } + + *output_pointer += utf8_length; + + return sequence_length; fail: - return 0; + return 0; } /* Parse the input text into an unescaped cinput, and populate item. */ -static cJSON_bool parse_string(cJSON *const item, - parse_buffer *const input_buffer) { - const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; - const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; - unsigned char *output_pointer = NULL; - unsigned char *output = NULL; +static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) +{ + const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; + const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; + unsigned char *output_pointer = NULL; + unsigned char *output = NULL; - /* not a string */ - if (buffer_at_offset(input_buffer)[0] != '\"') { - goto fail; - } - - { - /* calculate approximate size of the output (overestimate) */ - size_t allocation_length = 0; - size_t skipped_bytes = 0; - while ( - ((size_t)(input_end - input_buffer->content) < input_buffer->length) && - (*input_end != '\"')) { - /* is escape sequence */ - if (input_end[0] == '\\') { - if ((size_t)(input_end + 1 - input_buffer->content) >= - input_buffer->length) { - /* prevent buffer overflow when last input character is a backslash */ - goto fail; - } - skipped_bytes++; - input_end++; - } - input_end++; - } - if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || - (*input_end != '\"')) { - goto fail; /* string ended unexpectedly */ - } - - /* This is at most how much we need for the output */ - allocation_length = - (size_t)(input_end - buffer_at_offset(input_buffer)) - skipped_bytes; - output = (unsigned char *)input_buffer->hooks.allocate(allocation_length + - sizeof("")); - if (output == NULL) { - goto fail; /* allocation failure */ - } - } - - output_pointer = output; - /* loop through the string literal */ - while (input_pointer < input_end) { - if (*input_pointer != '\\') { - *output_pointer++ = *input_pointer++; - } - /* escape sequence */ - else { - unsigned char sequence_length = 2; - if ((input_end - input_pointer) < 1) { + /* not a string */ + if (buffer_at_offset(input_buffer)[0] != '\"') + { goto fail; - } - - switch (input_pointer[1]) { - case 'b': - *output_pointer++ = '\b'; - break; - case 'f': - *output_pointer++ = '\f'; - break; - case 'n': - *output_pointer++ = '\n'; - break; - case 'r': - *output_pointer++ = '\r'; - break; - case 't': - *output_pointer++ = '\t'; - break; - case '\"': - case '\\': - case '/': - *output_pointer++ = input_pointer[1]; - break; - - /* UTF-16 literal */ - case 'u': - sequence_length = - utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); - if (sequence_length == 0) { - /* failed to convert UTF16-literal to UTF-8 */ - goto fail; - } - break; - - default: - goto fail; - } - input_pointer += sequence_length; } - } - /* zero terminate the output */ - *output_pointer = '\0'; + { + /* calculate approximate size of the output (overestimate) */ + size_t allocation_length = 0; + size_t skipped_bytes = 0; + while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) + { + /* is escape sequence */ + if (input_end[0] == '\\') + { + if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) + { + /* prevent buffer overflow when last input character is a backslash */ + goto fail; + } + skipped_bytes++; + input_end++; + } + input_end++; + } + if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) + { + goto fail; /* string ended unexpectedly */ + } - item->type = cJSON_String; - item->valuestring = (char *)output; + /* This is at most how much we need for the output */ + allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes; + output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof("")); + if (output == NULL) + { + goto fail; /* allocation failure */ + } + } - input_buffer->offset = (size_t)(input_end - input_buffer->content); - input_buffer->offset++; + output_pointer = output; + /* loop through the string literal */ + while (input_pointer < input_end) + { + if (*input_pointer != '\\') + { + *output_pointer++ = *input_pointer++; + } + /* escape sequence */ + else + { + unsigned char sequence_length = 2; + if ((input_end - input_pointer) < 1) + { + goto fail; + } - return true; + switch (input_pointer[1]) + { + case 'b': + *output_pointer++ = '\b'; + break; + case 'f': + *output_pointer++ = '\f'; + break; + case 'n': + *output_pointer++ = '\n'; + break; + case 'r': + *output_pointer++ = '\r'; + break; + case 't': + *output_pointer++ = '\t'; + break; + case '\"': + case '\\': + case '/': + *output_pointer++ = input_pointer[1]; + break; + + /* UTF-16 literal */ + case 'u': + sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); + if (sequence_length == 0) + { + /* failed to convert UTF16-literal to UTF-8 */ + goto fail; + } + break; + + default: + goto fail; + } + input_pointer += sequence_length; + } + } + + /* zero terminate the output */ + *output_pointer = '\0'; + + item->type = cJSON_String; + item->valuestring = (char*)output; + + input_buffer->offset = (size_t) (input_end - input_buffer->content); + input_buffer->offset++; + + return true; fail: - if (output != NULL) { - input_buffer->hooks.deallocate(output); - } + if (output != NULL) + { + input_buffer->hooks.deallocate(output); + } - if (input_pointer != NULL) { - input_buffer->offset = (size_t)(input_pointer - input_buffer->content); - } + if (input_pointer != NULL) + { + input_buffer->offset = (size_t)(input_pointer - input_buffer->content); + } - return false; + return false; } /* Render the cstring provided to an escaped version that can be printed. */ -static cJSON_bool print_string_ptr(const unsigned char *const input, - printbuffer *const output_buffer) { - const unsigned char *input_pointer = NULL; - unsigned char *output = NULL; - unsigned char *output_pointer = NULL; - size_t output_length = 0; - /* numbers of additional characters needed for escaping */ - size_t escape_characters = 0; +static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer) +{ + const unsigned char *input_pointer = NULL; + unsigned char *output = NULL; + unsigned char *output_pointer = NULL; + size_t output_length = 0; + /* numbers of additional characters needed for escaping */ + size_t escape_characters = 0; - if (output_buffer == NULL) { - return false; - } - - /* empty string */ - if (input == NULL) { - output = ensure(output_buffer, sizeof("\"\"")); - if (output == NULL) { - return false; + if (output_buffer == NULL) + { + return false; } - strcpy((char *)output, "\"\""); - return true; - } + /* empty string */ + if (input == NULL) + { + output = ensure(output_buffer, sizeof("\"\"")); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "\"\""); - /* set "flag" to 1 if something needs to be escaped */ - for (input_pointer = input; *input_pointer; input_pointer++) { - switch (*input_pointer) { - case '\"': - case '\\': - case '\b': - case '\f': - case '\n': - case '\r': - case '\t': - /* one character escape sequence */ - escape_characters++; - break; - default: - if (*input_pointer < 32) { - /* UTF-16 escape sequence uXXXX */ - escape_characters += 5; - } - break; + return true; } - } - output_length = (size_t)(input_pointer - input) + escape_characters; - output = ensure(output_buffer, output_length + sizeof("\"\"")); - if (output == NULL) { - return false; - } + /* set "flag" to 1 if something needs to be escaped */ + for (input_pointer = input; *input_pointer; input_pointer++) + { + switch (*input_pointer) + { + case '\"': + case '\\': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + /* one character escape sequence */ + escape_characters++; + break; + default: + if (*input_pointer < 32) + { + /* UTF-16 escape sequence uXXXX */ + escape_characters += 5; + } + break; + } + } + output_length = (size_t)(input_pointer - input) + escape_characters; + + output = ensure(output_buffer, output_length + sizeof("\"\"")); + if (output == NULL) + { + return false; + } + + /* no characters have to be escaped */ + if (escape_characters == 0) + { + output[0] = '\"'; + memcpy(output + 1, input, output_length); + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; + } - /* no characters have to be escaped */ - if (escape_characters == 0) { output[0] = '\"'; - memcpy(output + 1, input, output_length); + output_pointer = output + 1; + /* copy the string */ + for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) + { + if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) + { + /* normal character, copy */ + *output_pointer = *input_pointer; + } + else + { + /* character needs to be escaped */ + *output_pointer++ = '\\'; + switch (*input_pointer) + { + case '\\': + *output_pointer = '\\'; + break; + case '\"': + *output_pointer = '\"'; + break; + case '\b': + *output_pointer = 'b'; + break; + case '\f': + *output_pointer = 'f'; + break; + case '\n': + *output_pointer = 'n'; + break; + case '\r': + *output_pointer = 'r'; + break; + case '\t': + *output_pointer = 't'; + break; + default: + /* escape and print as unicode codepoint */ + sprintf((char*)output_pointer, "u%04x", *input_pointer); + output_pointer += 4; + break; + } + } + } output[output_length + 1] = '\"'; output[output_length + 2] = '\0'; return true; - } - - output[0] = '\"'; - output_pointer = output + 1; - /* copy the string */ - for (input_pointer = input; *input_pointer != '\0'; - (void)input_pointer++, output_pointer++) { - if ((*input_pointer > 31) && (*input_pointer != '\"') && - (*input_pointer != '\\')) { - /* normal character, copy */ - *output_pointer = *input_pointer; - } else { - /* character needs to be escaped */ - *output_pointer++ = '\\'; - switch (*input_pointer) { - case '\\': - *output_pointer = '\\'; - break; - case '\"': - *output_pointer = '\"'; - break; - case '\b': - *output_pointer = 'b'; - break; - case '\f': - *output_pointer = 'f'; - break; - case '\n': - *output_pointer = 'n'; - break; - case '\r': - *output_pointer = 'r'; - break; - case '\t': - *output_pointer = 't'; - break; - default: - /* escape and print as unicode codepoint */ - sprintf((char *)output_pointer, "u%04x", *input_pointer); - output_pointer += 4; - break; - } - } - } - output[output_length + 1] = '\"'; - output[output_length + 2] = '\0'; - - return true; } /* Invoke print_string_ptr (which is useful) on an item. */ -static cJSON_bool print_string(const cJSON *const item, printbuffer *const p) { - return print_string_ptr((unsigned char *)item->valuestring, p); +static cJSON_bool print_string(const cJSON * const item, printbuffer * const p) +{ + return print_string_ptr((unsigned char*)item->valuestring, p); } /* Predeclare these prototypes. */ -static cJSON_bool parse_value(cJSON *const item, - parse_buffer *const input_buffer); -static cJSON_bool print_value(const cJSON *const item, - printbuffer *const output_buffer); -static cJSON_bool parse_array(cJSON *const item, - parse_buffer *const input_buffer); -static cJSON_bool print_array(const cJSON *const item, - printbuffer *const output_buffer); -static cJSON_bool parse_object(cJSON *const item, - parse_buffer *const input_buffer); -static cJSON_bool print_object(const cJSON *const item, - printbuffer *const output_buffer); +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer); /* Utility to jump whitespace and cr/lf */ -static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) { - if ((buffer == NULL) || (buffer->content == NULL)) { - return NULL; - } +static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL)) + { + return NULL; + } + + if (cannot_access_at_index(buffer, 0)) + { + return buffer; + } + + while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) + { + buffer->offset++; + } + + if (buffer->offset == buffer->length) + { + buffer->offset--; + } - if (cannot_access_at_index(buffer, 0)) { return buffer; - } - - while (can_access_at_index(buffer, 0) && - (buffer_at_offset(buffer)[0] <= 32)) { - buffer->offset++; - } - - if (buffer->offset == buffer->length) { - buffer->offset--; - } - - return buffer; } /* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */ -static parse_buffer *skip_utf8_bom(parse_buffer *const buffer) { - if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) { - return NULL; - } +static parse_buffer *skip_utf8_bom(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) + { + return NULL; + } - if (can_access_at_index(buffer, 4) && - (strncmp((const char *)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == - 0)) { - buffer->offset += 3; - } + if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) + { + buffer->offset += 3; + } - return buffer; + return buffer; } -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithOpts(const char *value, const char **return_parse_end, - cJSON_bool require_null_terminated) { - size_t buffer_length; +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) +{ + size_t buffer_length; - if (NULL == value) { - return NULL; - } + if (NULL == value) + { + return NULL; + } - /* Adding null character size due to require_null_terminated. */ - buffer_length = strlen(value) + sizeof(""); + /* Adding null character size due to require_null_terminated. */ + buffer_length = strlen(value) + sizeof(""); - return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, - require_null_terminated); + return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, require_null_terminated); } /* Parse an object - create a new root, and populate. */ -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, - const char **return_parse_end, - cJSON_bool require_null_terminated) { - parse_buffer buffer = {0, 0, 0, 0, {0, 0, 0}}; - cJSON *item = NULL; +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated) +{ + parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; + cJSON *item = NULL; - /* reset error position */ - global_error.json = NULL; - global_error.position = 0; + /* reset error position */ + global_error.json = NULL; + global_error.position = 0; - if (value == NULL || 0 == buffer_length) { - goto fail; - } - - buffer.content = (const unsigned char *)value; - buffer.length = buffer_length; - buffer.offset = 0; - buffer.hooks = global_hooks; - - item = cJSON_New_Item(&global_hooks); - if (item == NULL) /* memory fail */ - { - goto fail; - } - - if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) { - /* parse failure. ep is set. */ - goto fail; - } - - /* if we require null-terminated JSON without appended garbage, skip and then - * check for a null terminator */ - if (require_null_terminated) { - buffer_skip_whitespace(&buffer); - if ((buffer.offset >= buffer.length) || - buffer_at_offset(&buffer)[0] != '\0') { - goto fail; + if (value == NULL || 0 == buffer_length) + { + goto fail; } - } - if (return_parse_end) { - *return_parse_end = (const char *)buffer_at_offset(&buffer); - } - return item; + buffer.content = (const unsigned char*)value; + buffer.length = buffer_length; + buffer.offset = 0; + buffer.hooks = global_hooks; + + item = cJSON_New_Item(&global_hooks); + if (item == NULL) /* memory fail */ + { + goto fail; + } + + if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) + { + /* parse failure. ep is set. */ + goto fail; + } + + /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ + if (require_null_terminated) + { + buffer_skip_whitespace(&buffer); + if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') + { + goto fail; + } + } + if (return_parse_end) + { + *return_parse_end = (const char*)buffer_at_offset(&buffer); + } + + return item; fail: - if (item != NULL) { - cJSON_Delete(item); - } - - if (value != NULL) { - error local_error; - local_error.json = (const unsigned char *)value; - local_error.position = 0; - - if (buffer.offset < buffer.length) { - local_error.position = buffer.offset; - } else if (buffer.length > 0) { - local_error.position = buffer.length - 1; + if (item != NULL) + { + cJSON_Delete(item); } - if (return_parse_end != NULL) { - *return_parse_end = (const char *)local_error.json + local_error.position; + if (value != NULL) + { + error local_error; + local_error.json = (const unsigned char*)value; + local_error.position = 0; + + if (buffer.offset < buffer.length) + { + local_error.position = buffer.offset; + } + else if (buffer.length > 0) + { + local_error.position = buffer.length - 1; + } + + if (return_parse_end != NULL) + { + *return_parse_end = (const char*)local_error.json + local_error.position; + } + + global_error = local_error; } - global_error = local_error; - } - - return NULL; + return NULL; } /* Default options for cJSON_Parse */ -CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) { - return cJSON_ParseWithOpts(value, 0, 0); +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) +{ + return cJSON_ParseWithOpts(value, 0, 0); } -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithLength(const char *value, size_t buffer_length) { - return cJSON_ParseWithLengthOpts(value, buffer_length, 0, 0); +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length) +{ + return cJSON_ParseWithLengthOpts(value, buffer_length, 0, 0); } #define cjson_min(a, b) (((a) < (b)) ? (a) : (b)) -static unsigned char *print(const cJSON *const item, cJSON_bool format, - const internal_hooks *const hooks) { - static const size_t default_buffer_size = 256; - printbuffer buffer[1]; - unsigned char *printed = NULL; +static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) +{ + static const size_t default_buffer_size = 256; + printbuffer buffer[1]; + unsigned char *printed = NULL; - memset(buffer, 0, sizeof(buffer)); + memset(buffer, 0, sizeof(buffer)); - /* create buffer */ - buffer->buffer = (unsigned char *)hooks->allocate(default_buffer_size); - buffer->length = default_buffer_size; - buffer->format = format; - buffer->hooks = *hooks; - if (buffer->buffer == NULL) { - goto fail; - } - - /* print the value */ - if (!print_value(item, buffer)) { - goto fail; - } - update_offset(buffer); - - /* check if reallocate is available */ - if (hooks->reallocate != NULL) { - printed = - (unsigned char *)hooks->reallocate(buffer->buffer, buffer->offset + 1); - if (printed == NULL) { - goto fail; + /* create buffer */ + buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size); + buffer->length = default_buffer_size; + buffer->format = format; + buffer->hooks = *hooks; + if (buffer->buffer == NULL) + { + goto fail; } - buffer->buffer = NULL; - } else /* otherwise copy the JSON over to a new buffer */ - { - printed = (unsigned char *)hooks->allocate(buffer->offset + 1); - if (printed == NULL) { - goto fail; + + /* print the value */ + if (!print_value(item, buffer)) + { + goto fail; } - memcpy(printed, buffer->buffer, - cjson_min(buffer->length, buffer->offset + 1)); - printed[buffer->offset] = '\0'; /* just to be sure */ + update_offset(buffer); - /* free the buffer */ - hooks->deallocate(buffer->buffer); - } + /* check if reallocate is available */ + if (hooks->reallocate != NULL) + { + printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); + if (printed == NULL) { + goto fail; + } + buffer->buffer = NULL; + } + else /* otherwise copy the JSON over to a new buffer */ + { + printed = (unsigned char*) hooks->allocate(buffer->offset + 1); + if (printed == NULL) + { + goto fail; + } + memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); + printed[buffer->offset] = '\0'; /* just to be sure */ - return printed; + /* free the buffer */ + hooks->deallocate(buffer->buffer); + } + + return printed; fail: - if (buffer->buffer != NULL) { - hooks->deallocate(buffer->buffer); - } + if (buffer->buffer != NULL) + { + hooks->deallocate(buffer->buffer); + } - if (printed != NULL) { - hooks->deallocate(printed); - } + if (printed != NULL) + { + hooks->deallocate(printed); + } - return NULL; + return NULL; } /* Render a cJSON item/entity/structure to text. */ -CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) { - return (char *)print(item, true, &global_hooks); +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) +{ + return (char*)print(item, true, &global_hooks); } -CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) { - return (char *)print(item, false, &global_hooks); +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) +{ + return (char*)print(item, false, &global_hooks); } -CJSON_PUBLIC(char *) -cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) { - printbuffer p = {0, 0, 0, 0, 0, 0, {0, 0, 0}}; +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; - if (prebuffer < 0) { - return NULL; - } + if (prebuffer < 0) + { + return NULL; + } - p.buffer = (unsigned char *)global_hooks.allocate((size_t)prebuffer); - if (!p.buffer) { - return NULL; - } + p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); + if (!p.buffer) + { + return NULL; + } - p.length = (size_t)prebuffer; - p.offset = 0; - p.noalloc = false; - p.format = fmt; - p.hooks = global_hooks; + p.length = (size_t)prebuffer; + p.offset = 0; + p.noalloc = false; + p.format = fmt; + p.hooks = global_hooks; - if (!print_value(item, &p)) { - global_hooks.deallocate(p.buffer); - return NULL; - } + if (!print_value(item, &p)) + { + global_hooks.deallocate(p.buffer); + return NULL; + } - return (char *)p.buffer; + return (char*)p.buffer; } -CJSON_PUBLIC(cJSON_bool) -cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, - const cJSON_bool format) { - printbuffer p = {0, 0, 0, 0, 0, 0, {0, 0, 0}}; +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; - if ((length < 0) || (buffer == NULL)) { - return false; - } + if ((length < 0) || (buffer == NULL)) + { + return false; + } - p.buffer = (unsigned char *)buffer; - p.length = (size_t)length; - p.offset = 0; - p.noalloc = true; - p.format = format; - p.hooks = global_hooks; + p.buffer = (unsigned char*)buffer; + p.length = (size_t)length; + p.offset = 0; + p.noalloc = true; + p.format = format; + p.hooks = global_hooks; - return print_value(item, &p); + return print_value(item, &p); } /* Parser core - when encountering text, process appropriately. */ -static cJSON_bool parse_value(cJSON *const item, - parse_buffer *const input_buffer) { - if ((input_buffer == NULL) || (input_buffer->content == NULL)) { - return false; /* no input */ - } +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer) +{ + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; /* no input */ + } - /* parse the different types of values */ - /* null */ - if (can_read(input_buffer, 4) && - (strncmp((const char *)buffer_at_offset(input_buffer), "null", 4) == 0)) { - item->type = cJSON_NULL; - input_buffer->offset += 4; - return true; - } - /* false */ - if (can_read(input_buffer, 5) && - (strncmp((const char *)buffer_at_offset(input_buffer), "false", 5) == - 0)) { - item->type = cJSON_False; - input_buffer->offset += 5; - return true; - } - /* true */ - if (can_read(input_buffer, 4) && - (strncmp((const char *)buffer_at_offset(input_buffer), "true", 4) == 0)) { - item->type = cJSON_True; - item->valueint = 1; - input_buffer->offset += 4; - return true; - } - /* string */ - if (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == '\"')) { - return parse_string(item, input_buffer); - } - /* number */ - if (can_access_at_index(input_buffer, 0) && - ((buffer_at_offset(input_buffer)[0] == '-') || - ((buffer_at_offset(input_buffer)[0] >= '0') && - (buffer_at_offset(input_buffer)[0] <= '9')))) { - return parse_number(item, input_buffer); - } - /* array */ - if (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == '[')) { - return parse_array(item, input_buffer); - } - /* object */ - if (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == '{')) { - return parse_object(item, input_buffer); - } + /* parse the different types of values */ + /* null */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0)) + { + item->type = cJSON_NULL; + input_buffer->offset += 4; + return true; + } + /* false */ + if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0)) + { + item->type = cJSON_False; + input_buffer->offset += 5; + return true; + } + /* true */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "true", 4) == 0)) + { + item->type = cJSON_True; + item->valueint = 1; + input_buffer->offset += 4; + return true; + } + /* string */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) + { + return parse_string(item, input_buffer); + } + /* number */ + if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) + { + return parse_number(item, input_buffer); + } + /* array */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) + { + return parse_array(item, input_buffer); + } + /* object */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) + { + return parse_object(item, input_buffer); + } - return false; + return false; } /* Render a value to text. */ -static cJSON_bool print_value(const cJSON *const item, - printbuffer *const output_buffer) { - unsigned char *output = NULL; +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output = NULL; - if ((item == NULL) || (output_buffer == NULL)) { - return false; - } - - switch ((item->type) & 0xFF) { - case cJSON_NULL: - output = ensure(output_buffer, 5); - if (output == NULL) { - return false; - } - strcpy((char *)output, "null"); - return true; - - case cJSON_False: - output = ensure(output_buffer, 6); - if (output == NULL) { - return false; - } - strcpy((char *)output, "false"); - return true; - - case cJSON_True: - output = ensure(output_buffer, 5); - if (output == NULL) { - return false; - } - strcpy((char *)output, "true"); - return true; - - case cJSON_Number: - return print_number(item, output_buffer); - - case cJSON_Raw: { - size_t raw_length = 0; - if (item->valuestring == NULL) { - return false; + if ((item == NULL) || (output_buffer == NULL)) + { + return false; } - raw_length = strlen(item->valuestring) + sizeof(""); - output = ensure(output_buffer, raw_length); - if (output == NULL) { - return false; + switch ((item->type) & 0xFF) + { + case cJSON_NULL: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "null"); + return true; + + case cJSON_False: + output = ensure(output_buffer, 6); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "false"); + return true; + + case cJSON_True: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "true"); + return true; + + case cJSON_Number: + return print_number(item, output_buffer); + + case cJSON_Raw: + { + size_t raw_length = 0; + if (item->valuestring == NULL) + { + return false; + } + + raw_length = strlen(item->valuestring) + sizeof(""); + output = ensure(output_buffer, raw_length); + if (output == NULL) + { + return false; + } + memcpy(output, item->valuestring, raw_length); + return true; + } + + case cJSON_String: + return print_string(item, output_buffer); + + case cJSON_Array: + return print_array(item, output_buffer); + + case cJSON_Object: + return print_object(item, output_buffer); + + default: + return false; } - memcpy(output, item->valuestring, raw_length); - return true; - } - - case cJSON_String: - return print_string(item, output_buffer); - - case cJSON_Array: - return print_array(item, output_buffer); - - case cJSON_Object: - return print_object(item, output_buffer); - - default: - return false; - } } /* Build an array from input text. */ -static cJSON_bool parse_array(cJSON *const item, - parse_buffer *const input_buffer) { - cJSON *head = NULL; /* head of the linked list */ - cJSON *current_item = NULL; +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) +{ + cJSON *head = NULL; /* head of the linked list */ + cJSON *current_item = NULL; - if (input_buffer->depth >= CJSON_NESTING_LIMIT) { - return false; /* to deeply nested */ - } - input_buffer->depth++; + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; - if (buffer_at_offset(input_buffer)[0] != '[') { - /* not an array */ - goto fail; - } - - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == ']')) { - /* empty array */ - goto success; - } - - /* check if we skipped to the end of the buffer */ - if (cannot_access_at_index(input_buffer, 0)) { - input_buffer->offset--; - goto fail; - } - - /* step back to character in front of the first element */ - input_buffer->offset--; - /* loop through the comma separated array elements */ - do { - /* allocate next item */ - cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); - if (new_item == NULL) { - goto fail; /* allocation failure */ + if (buffer_at_offset(input_buffer)[0] != '[') + { + /* not an array */ + goto fail; } - /* attach next item to list */ - if (head == NULL) { - /* start the linked list */ - current_item = head = new_item; - } else { - /* add to the end and advance */ - current_item->next = new_item; - new_item->prev = current_item; - current_item = new_item; - } - - /* parse next value */ input_buffer->offset++; buffer_skip_whitespace(input_buffer); - if (!parse_value(current_item, input_buffer)) { - goto fail; /* failed to parse value */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) + { + /* empty array */ + goto success; } - buffer_skip_whitespace(input_buffer); - } while (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == ',')); - if (cannot_access_at_index(input_buffer, 0) || - buffer_at_offset(input_buffer)[0] != ']') { - goto fail; /* expected end of array */ - } + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ + input_buffer->offset--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse next value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); + } + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + + if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') + { + goto fail; /* expected end of array */ + } success: - input_buffer->depth--; + input_buffer->depth--; - if (head != NULL) { - head->prev = current_item; - } + if (head != NULL) { + head->prev = current_item; + } - item->type = cJSON_Array; - item->child = head; + item->type = cJSON_Array; + item->child = head; - input_buffer->offset++; + input_buffer->offset++; - return true; + return true; fail: - if (head != NULL) { - cJSON_Delete(head); - } + if (head != NULL) + { + cJSON_Delete(head); + } - return false; + return false; } /* Render an array to text */ -static cJSON_bool print_array(const cJSON *const item, - printbuffer *const output_buffer) { - unsigned char *output_pointer = NULL; - size_t length = 0; - cJSON *current_element = item->child; +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_element = item->child; - if (output_buffer == NULL) { - return false; - } - - /* Compose the output array. */ - /* opening square bracket */ - output_pointer = ensure(output_buffer, 1); - if (output_pointer == NULL) { - return false; - } - - *output_pointer = '['; - output_buffer->offset++; - output_buffer->depth++; - - while (current_element != NULL) { - if (!print_value(current_element, output_buffer)) { - return false; - } - update_offset(output_buffer); - if (current_element->next) { - length = (size_t)(output_buffer->format ? 2 : 1); - output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) { + if (output_buffer == NULL) + { return false; - } - *output_pointer++ = ','; - if (output_buffer->format) { - *output_pointer++ = ' '; - } - *output_pointer = '\0'; - output_buffer->offset += length; } - current_element = current_element->next; - } - output_pointer = ensure(output_buffer, 2); - if (output_pointer == NULL) { - return false; - } - *output_pointer++ = ']'; - *output_pointer = '\0'; - output_buffer->depth--; + /* Compose the output array. */ + /* opening square bracket */ + output_pointer = ensure(output_buffer, 1); + if (output_pointer == NULL) + { + return false; + } - return true; + *output_pointer = '['; + output_buffer->offset++; + output_buffer->depth++; + + while (current_element != NULL) + { + if (!print_value(current_element, output_buffer)) + { + return false; + } + update_offset(output_buffer); + if (current_element->next) + { + length = (size_t) (output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ','; + if(output_buffer->format) + { + *output_pointer++ = ' '; + } + *output_pointer = '\0'; + output_buffer->offset += length; + } + current_element = current_element->next; + } + + output_pointer = ensure(output_buffer, 2); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ']'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; } /* Build an object from the text. */ -static cJSON_bool parse_object(cJSON *const item, - parse_buffer *const input_buffer) { - cJSON *head = NULL; /* linked list head */ - cJSON *current_item = NULL; +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) +{ + cJSON *head = NULL; /* linked list head */ + cJSON *current_item = NULL; - if (input_buffer->depth >= CJSON_NESTING_LIMIT) { - return false; /* to deeply nested */ - } - input_buffer->depth++; + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; - if (cannot_access_at_index(input_buffer, 0) || - (buffer_at_offset(input_buffer)[0] != '{')) { - goto fail; /* not an object */ - } + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) + { + goto fail; /* not an object */ + } - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == '}')) { - goto success; /* empty object */ - } + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) + { + goto success; /* empty object */ + } - /* check if we skipped to the end of the buffer */ - if (cannot_access_at_index(input_buffer, 0)) { + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ input_buffer->offset--; - goto fail; - } + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } - /* step back to character in front of the first element */ - input_buffer->offset--; - /* loop through the comma separated array elements */ - do { - /* allocate next item */ - cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); - if (new_item == NULL) { - goto fail; /* allocation failure */ + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse the name of the child */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_string(current_item, input_buffer)) + { + goto fail; /* failed to parse name */ + } + buffer_skip_whitespace(input_buffer); + + /* swap valuestring and string, because we parsed the name */ + current_item->string = current_item->valuestring; + current_item->valuestring = NULL; + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) + { + goto fail; /* invalid object */ + } + + /* parse the value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); } + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); - /* attach next item to list */ - if (head == NULL) { - /* start the linked list */ - current_item = head = new_item; - } else { - /* add to the end and advance */ - current_item->next = new_item; - new_item->prev = current_item; - current_item = new_item; + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) + { + goto fail; /* expected end of object */ } - /* parse the name of the child */ - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (!parse_string(current_item, input_buffer)) { - goto fail; /* failed to parse name */ - } - buffer_skip_whitespace(input_buffer); - - /* swap valuestring and string, because we parsed the name */ - current_item->string = current_item->valuestring; - current_item->valuestring = NULL; - - if (cannot_access_at_index(input_buffer, 0) || - (buffer_at_offset(input_buffer)[0] != ':')) { - goto fail; /* invalid object */ - } - - /* parse the value */ - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (!parse_value(current_item, input_buffer)) { - goto fail; /* failed to parse value */ - } - buffer_skip_whitespace(input_buffer); - } while (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == ',')); - - if (cannot_access_at_index(input_buffer, 0) || - (buffer_at_offset(input_buffer)[0] != '}')) { - goto fail; /* expected end of object */ - } - success: - input_buffer->depth--; + input_buffer->depth--; - if (head != NULL) { - head->prev = current_item; - } + if (head != NULL) { + head->prev = current_item; + } - item->type = cJSON_Object; - item->child = head; + item->type = cJSON_Object; + item->child = head; - input_buffer->offset++; - return true; + input_buffer->offset++; + return true; fail: - if (head != NULL) { - cJSON_Delete(head); - } + if (head != NULL) + { + cJSON_Delete(head); + } - return false; + return false; } /* Render an object to text. */ -static cJSON_bool print_object(const cJSON *const item, - printbuffer *const output_buffer) { - unsigned char *output_pointer = NULL; - size_t length = 0; - cJSON *current_item = item->child; +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_item = item->child; - if (output_buffer == NULL) { - return false; - } - - /* Compose the output: */ - length = (size_t)(output_buffer->format ? 2 : 1); /* fmt: {\n */ - output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) { - return false; - } - - *output_pointer++ = '{'; - output_buffer->depth++; - if (output_buffer->format) { - *output_pointer++ = '\n'; - } - output_buffer->offset += length; - - while (current_item) { - if (output_buffer->format) { - size_t i; - output_pointer = ensure(output_buffer, output_buffer->depth); - if (output_pointer == NULL) { + if (output_buffer == NULL) + { return false; - } - for (i = 0; i < output_buffer->depth; i++) { - *output_pointer++ = '\t'; - } - output_buffer->offset += output_buffer->depth; } - /* print key */ - if (!print_string_ptr((unsigned char *)current_item->string, - output_buffer)) { - return false; - } - update_offset(output_buffer); - - length = (size_t)(output_buffer->format ? 2 : 1); - output_pointer = ensure(output_buffer, length); - if (output_pointer == NULL) { - return false; - } - *output_pointer++ = ':'; - if (output_buffer->format) { - *output_pointer++ = '\t'; - } - output_buffer->offset += length; - - /* print value */ - if (!print_value(current_item, output_buffer)) { - return false; - } - update_offset(output_buffer); - - /* print comma if not last */ - length = ((size_t)(output_buffer->format ? 1 : 0) + - (size_t)(current_item->next ? 1 : 0)); + /* Compose the output: */ + length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) { - return false; - } - if (current_item->next) { - *output_pointer++ = ','; + if (output_pointer == NULL) + { + return false; } - if (output_buffer->format) { - *output_pointer++ = '\n'; + *output_pointer++ = '{'; + output_buffer->depth++; + if (output_buffer->format) + { + *output_pointer++ = '\n'; } - *output_pointer = '\0'; output_buffer->offset += length; - current_item = current_item->next; - } + while (current_item) + { + if (output_buffer->format) + { + size_t i; + output_pointer = ensure(output_buffer, output_buffer->depth); + if (output_pointer == NULL) + { + return false; + } + for (i = 0; i < output_buffer->depth; i++) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += output_buffer->depth; + } - output_pointer = ensure( - output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); - if (output_pointer == NULL) { - return false; - } - if (output_buffer->format) { - size_t i; - for (i = 0; i < (output_buffer->depth - 1); i++) { - *output_pointer++ = '\t'; + /* print key */ + if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + length = (size_t) (output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ':'; + if (output_buffer->format) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += length; + + /* print value */ + if (!print_value(current_item, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + /* print comma if not last */ + length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)(current_item->next ? 1 : 0)); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + if (current_item->next) + { + *output_pointer++ = ','; + } + + if (output_buffer->format) + { + *output_pointer++ = '\n'; + } + *output_pointer = '\0'; + output_buffer->offset += length; + + current_item = current_item->next; } - } - *output_pointer++ = '}'; - *output_pointer = '\0'; - output_buffer->depth--; - return true; + output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); + if (output_pointer == NULL) + { + return false; + } + if (output_buffer->format) + { + size_t i; + for (i = 0; i < (output_buffer->depth - 1); i++) + { + *output_pointer++ = '\t'; + } + } + *output_pointer++ = '}'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; } /* Get Array size/item / object item. */ -CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) { - cJSON *child = NULL; - size_t size = 0; +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) +{ + cJSON *child = NULL; + size_t size = 0; - if (array == NULL) { - return 0; - } - - child = array->child; - - while (child != NULL) { - size++; - child = child->next; - } - - /* FIXME: Can overflow here. Cannot be fixed without breaking the API */ - - return (int)size; -} - -static cJSON *get_array_item(const cJSON *array, size_t index) { - cJSON *current_child = NULL; - - if (array == NULL) { - return NULL; - } - - current_child = array->child; - while ((current_child != NULL) && (index > 0)) { - index--; - current_child = current_child->next; - } - - return current_child; -} - -CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) { - if (index < 0) { - return NULL; - } - - return get_array_item(array, (size_t)index); -} - -static cJSON *get_object_item(const cJSON *const object, const char *const name, - const cJSON_bool case_sensitive) { - cJSON *current_element = NULL; - - if ((object == NULL) || (name == NULL)) { - return NULL; - } - - current_element = object->child; - if (case_sensitive) { - while ((current_element != NULL) && (current_element->string != NULL) && - (strcmp(name, current_element->string) != 0)) { - current_element = current_element->next; + if (array == NULL) + { + return 0; } - } else { - while ((current_element != NULL) && - (case_insensitive_strcmp( - (const unsigned char *)name, - (const unsigned char *)(current_element->string)) != 0)) { - current_element = current_element->next; + + child = array->child; + + while(child != NULL) + { + size++; + child = child->next; } - } - if ((current_element == NULL) || (current_element->string == NULL)) { - return NULL; - } + /* FIXME: Can overflow here. Cannot be fixed without breaking the API */ - return current_element; + return (int)size; } -CJSON_PUBLIC(cJSON *) -cJSON_GetObjectItem(const cJSON *const object, const char *const string) { - return get_object_item(object, string, false); +static cJSON* get_array_item(const cJSON *array, size_t index) +{ + cJSON *current_child = NULL; + + if (array == NULL) + { + return NULL; + } + + current_child = array->child; + while ((current_child != NULL) && (index > 0)) + { + index--; + current_child = current_child->next; + } + + return current_child; } -CJSON_PUBLIC(cJSON *) -cJSON_GetObjectItemCaseSensitive(const cJSON *const object, - const char *const string) { - return get_object_item(object, string, true); +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) +{ + if (index < 0) + { + return NULL; + } + + return get_array_item(array, (size_t)index); } -CJSON_PUBLIC(cJSON_bool) -cJSON_HasObjectItem(const cJSON *object, const char *string) { - return cJSON_GetObjectItem(object, string) ? 1 : 0; +static cJSON *get_object_item(const cJSON * const object, const char * const name, const cJSON_bool case_sensitive) +{ + cJSON *current_element = NULL; + + if ((object == NULL) || (name == NULL)) + { + return NULL; + } + + current_element = object->child; + if (case_sensitive) + { + while ((current_element != NULL) && (current_element->string != NULL) && (strcmp(name, current_element->string) != 0)) + { + current_element = current_element->next; + } + } + else + { + while ((current_element != NULL) && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) + { + current_element = current_element->next; + } + } + + if ((current_element == NULL) || (current_element->string == NULL)) { + return NULL; + } + + return current_element; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, false); +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, true); +} + +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) +{ + return cJSON_GetObjectItem(object, string) ? 1 : 0; } /* Utility for array list handling. */ -static void suffix_object(cJSON *prev, cJSON *item) { - prev->next = item; - item->prev = prev; +static void suffix_object(cJSON *prev, cJSON *item) +{ + prev->next = item; + item->prev = prev; } /* Utility for handling references. */ -static cJSON *create_reference(const cJSON *item, - const internal_hooks *const hooks) { - cJSON *reference = NULL; - if (item == NULL) { - return NULL; - } +static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) +{ + cJSON *reference = NULL; + if (item == NULL) + { + return NULL; + } - reference = cJSON_New_Item(hooks); - if (reference == NULL) { - return NULL; - } + reference = cJSON_New_Item(hooks); + if (reference == NULL) + { + return NULL; + } - memcpy(reference, item, sizeof(cJSON)); - reference->string = NULL; - reference->type |= cJSON_IsReference; - reference->next = reference->prev = NULL; - return reference; + memcpy(reference, item, sizeof(cJSON)); + reference->string = NULL; + reference->type |= cJSON_IsReference; + reference->next = reference->prev = NULL; + return reference; } -static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) { - cJSON *child = NULL; +static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) +{ + cJSON *child = NULL; - if ((item == NULL) || (array == NULL) || (array == item)) { - return false; - } - - child = array->child; - /* - * To find the last item in array quickly, we use prev in array - */ - if (child == NULL) { - /* list is empty, start new one */ - array->child = item; - item->prev = item; - item->next = NULL; - } else { - /* append to the end */ - if (child->prev) { - suffix_object(child->prev, item); - array->child->prev = item; + if ((item == NULL) || (array == NULL) || (array == item)) + { + return false; } - } - return true; + child = array->child; + /* + * To find the last item in array quickly, we use prev in array + */ + if (child == NULL) + { + /* list is empty, start new one */ + array->child = item; + item->prev = item; + item->next = NULL; + } + else + { + /* append to the end */ + if (child->prev) + { + suffix_object(child->prev, item); + array->child->prev = item; + } + } + + return true; } /* Add item to array/object. */ -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) { - return add_item_to_array(array, item); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) +{ + return add_item_to_array(array, item); } -#if defined(__clang__) || \ - (defined(__GNUC__) && \ - ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) -#pragma GCC diagnostic push +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) + #pragma GCC diagnostic push #endif #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wcast-qual" #endif /* helper function to cast away const */ -static void *cast_away_const(const void *string) { return (void *)string; } -#if defined(__clang__) || \ - (defined(__GNUC__) && \ - ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) -#pragma GCC diagnostic pop +static void* cast_away_const(const void* string) +{ + return (void*)string; +} +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) + #pragma GCC diagnostic pop #endif -static cJSON_bool add_item_to_object(cJSON *const object, - const char *const string, - cJSON *const item, - const internal_hooks *const hooks, - const cJSON_bool constant_key) { - char *new_key = NULL; - int new_type = cJSON_Invalid; - if ((object == NULL) || (string == NULL) || (item == NULL) || - (object == item)) { - return false; - } +static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key) +{ + char *new_key = NULL; + int new_type = cJSON_Invalid; - if (constant_key) { - new_key = (char *)cast_away_const(string); - new_type = item->type | cJSON_StringIsConst; - } else { - new_key = (char *)cJSON_strdup((const unsigned char *)string, hooks); - if (new_key == NULL) { - return false; + if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item)) + { + return false; } - new_type = item->type & ~cJSON_StringIsConst; - } + if (constant_key) + { + new_key = (char*)cast_away_const(string); + new_type = item->type | cJSON_StringIsConst; + } + else + { + new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); + if (new_key == NULL) + { + return false; + } - if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) { - hooks->deallocate(item->string); - } + new_type = item->type & ~cJSON_StringIsConst; + } - item->string = new_key; - item->type = new_type; + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + hooks->deallocate(item->string); + } - return add_item_to_array(object, item); + item->string = new_key; + item->type = new_type; + + return add_item_to_array(object, item); } -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) { - return add_item_to_object(object, string, item, &global_hooks, false); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) +{ + return add_item_to_object(object, string, item, &global_hooks, false); } /* Add an item to an object with constant string as key */ -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) { - return add_item_to_object(object, string, item, &global_hooks, true); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) +{ + return add_item_to_object(object, string, item, &global_hooks, true); } -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) { - if (array == NULL) { - return false; - } +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) +{ + if (array == NULL) + { + return false; + } - return add_item_to_array(array, create_reference(item, &global_hooks)); + return add_item_to_array(array, create_reference(item, &global_hooks)); } -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) { - if ((object == NULL) || (string == NULL)) { - return false; - } +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) +{ + if ((object == NULL) || (string == NULL)) + { + return false; + } - return add_item_to_object(object, string, - create_reference(item, &global_hooks), - &global_hooks, false); + return add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); } -CJSON_PUBLIC(cJSON *) -cJSON_AddNullToObject(cJSON *const object, const char *const name) { - cJSON *null = cJSON_CreateNull(); - if (add_item_to_object(object, name, null, &global_hooks, false)) { - return null; - } +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name) +{ + cJSON *null = cJSON_CreateNull(); + if (add_item_to_object(object, name, null, &global_hooks, false)) + { + return null; + } - cJSON_Delete(null); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddTrueToObject(cJSON *const object, const char *const name) { - cJSON *true_item = cJSON_CreateTrue(); - if (add_item_to_object(object, name, true_item, &global_hooks, false)) { - return true_item; - } - - cJSON_Delete(true_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddFalseToObject(cJSON *const object, const char *const name) { - cJSON *false_item = cJSON_CreateFalse(); - if (add_item_to_object(object, name, false_item, &global_hooks, false)) { - return false_item; - } - - cJSON_Delete(false_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddBoolToObject(cJSON *const object, const char *const name, - const cJSON_bool boolean) { - cJSON *bool_item = cJSON_CreateBool(boolean); - if (add_item_to_object(object, name, bool_item, &global_hooks, false)) { - return bool_item; - } - - cJSON_Delete(bool_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddNumberToObject(cJSON *const object, const char *const name, - const double number) { - cJSON *number_item = cJSON_CreateNumber(number); - if (add_item_to_object(object, name, number_item, &global_hooks, false)) { - return number_item; - } - - cJSON_Delete(number_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddStringToObject(cJSON *const object, const char *const name, - const char *const string) { - cJSON *string_item = cJSON_CreateString(string); - if (add_item_to_object(object, name, string_item, &global_hooks, false)) { - return string_item; - } - - cJSON_Delete(string_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddRawToObject(cJSON *const object, const char *const name, - const char *const raw) { - cJSON *raw_item = cJSON_CreateRaw(raw); - if (add_item_to_object(object, name, raw_item, &global_hooks, false)) { - return raw_item; - } - - cJSON_Delete(raw_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddObjectToObject(cJSON *const object, const char *const name) { - cJSON *object_item = cJSON_CreateObject(); - if (add_item_to_object(object, name, object_item, &global_hooks, false)) { - return object_item; - } - - cJSON_Delete(object_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddArrayToObject(cJSON *const object, const char *const name) { - cJSON *array = cJSON_CreateArray(); - if (add_item_to_object(object, name, array, &global_hooks, false)) { - return array; - } - - cJSON_Delete(array); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item) { - if ((parent == NULL) || (item == NULL)) { + cJSON_Delete(null); return NULL; - } - - if (item != parent->child) { - /* not the first element */ - item->prev->next = item->next; - } - if (item->next != NULL) { - /* not the last element */ - item->next->prev = item->prev; - } - - if (item == parent->child) { - /* first element */ - parent->child = item->next; - } else if (item->next == NULL) { - /* last element */ - parent->child->prev = item->prev; - } - - /* make sure the detached item doesn't point anywhere anymore */ - item->prev = NULL; - item->next = NULL; - - return item; } -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) { - if (which < 0) { +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name) +{ + cJSON *true_item = cJSON_CreateTrue(); + if (add_item_to_object(object, name, true_item, &global_hooks, false)) + { + return true_item; + } + + cJSON_Delete(true_item); return NULL; - } - - return cJSON_DetachItemViaPointer(array, - get_array_item(array, (size_t)which)); } -CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) { - cJSON_Delete(cJSON_DetachItemFromArray(array, which)); +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name) +{ + cJSON *false_item = cJSON_CreateFalse(); + if (add_item_to_object(object, name, false_item, &global_hooks, false)) + { + return false_item; + } + + cJSON_Delete(false_item); + return NULL; } -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemFromObject(cJSON *object, const char *string) { - cJSON *to_detach = cJSON_GetObjectItem(object, string); +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean) +{ + cJSON *bool_item = cJSON_CreateBool(boolean); + if (add_item_to_object(object, name, bool_item, &global_hooks, false)) + { + return bool_item; + } - return cJSON_DetachItemViaPointer(object, to_detach); + cJSON_Delete(bool_item); + return NULL; } -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) { - cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number) +{ + cJSON *number_item = cJSON_CreateNumber(number); + if (add_item_to_object(object, name, number_item, &global_hooks, false)) + { + return number_item; + } - return cJSON_DetachItemViaPointer(object, to_detach); + cJSON_Delete(number_item); + return NULL; } -CJSON_PUBLIC(void) -cJSON_DeleteItemFromObject(cJSON *object, const char *string) { - cJSON_Delete(cJSON_DetachItemFromObject(object, string)); +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string) +{ + cJSON *string_item = cJSON_CreateString(string); + if (add_item_to_object(object, name, string_item, &global_hooks, false)) + { + return string_item; + } + + cJSON_Delete(string_item); + return NULL; } -CJSON_PUBLIC(void) -cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) { - cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw) +{ + cJSON *raw_item = cJSON_CreateRaw(raw); + if (add_item_to_object(object, name, raw_item, &global_hooks, false)) + { + return raw_item; + } + + cJSON_Delete(raw_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name) +{ + cJSON *object_item = cJSON_CreateObject(); + if (add_item_to_object(object, name, object_item, &global_hooks, false)) + { + return object_item; + } + + cJSON_Delete(object_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name) +{ + cJSON *array = cJSON_CreateArray(); + if (add_item_to_object(object, name, array, &global_hooks, false)) + { + return array; + } + + cJSON_Delete(array); + return NULL; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item) +{ + if ((parent == NULL) || (item == NULL)) + { + return NULL; + } + + if (item != parent->child) + { + /* not the first element */ + item->prev->next = item->next; + } + if (item->next != NULL) + { + /* not the last element */ + item->next->prev = item->prev; + } + + if (item == parent->child) + { + /* first element */ + parent->child = item->next; + } + else if (item->next == NULL) + { + /* last element */ + parent->child->prev = item->prev; + } + + /* make sure the detached item doesn't point anywhere anymore */ + item->prev = NULL; + item->next = NULL; + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) +{ + if (which < 0) + { + return NULL; + } + + return cJSON_DetachItemViaPointer(array, get_array_item(array, (size_t)which)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) +{ + cJSON_Delete(cJSON_DetachItemFromArray(array, which)); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItem(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObject(object, string)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); } /* Replace array/object items with new ones. */ -CJSON_PUBLIC(cJSON_bool) -cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) { - cJSON *after_inserted = NULL; +CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) +{ + cJSON *after_inserted = NULL; - if (which < 0) { - return false; - } + if (which < 0) + { + return false; + } - after_inserted = get_array_item(array, (size_t)which); - if (after_inserted == NULL) { - return add_item_to_array(array, newitem); - } + after_inserted = get_array_item(array, (size_t)which); + if (after_inserted == NULL) + { + return add_item_to_array(array, newitem); + } - newitem->next = after_inserted; - newitem->prev = after_inserted->prev; - after_inserted->prev = newitem; - if (after_inserted == array->child) { - array->child = newitem; - } else { - newitem->prev->next = newitem; - } - return true; -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, - cJSON *replacement) { - if ((parent == NULL) || (replacement == NULL) || (item == NULL)) { - return false; - } - - if (replacement == item) { + newitem->next = after_inserted; + newitem->prev = after_inserted->prev; + after_inserted->prev = newitem; + if (after_inserted == array->child) + { + array->child = newitem; + } + else + { + newitem->prev->next = newitem; + } return true; - } +} - replacement->next = item->next; - replacement->prev = item->prev; - - if (replacement->next != NULL) { - replacement->next->prev = replacement; - } - if (parent->child == item) { - if (parent->child->prev == parent->child) { - replacement->prev = replacement; +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) +{ + if ((parent == NULL) || (replacement == NULL) || (item == NULL)) + { + return false; } - parent->child = replacement; - } else { /* - * To find the last item in array quickly, we use prev in array. - * We can't modify the last item's next pointer where this item was - * the parent's child - */ - if (replacement->prev != NULL) { - replacement->prev->next = replacement; + + if (replacement == item) + { + return true; } - if (replacement->next == NULL) { - parent->child->prev = replacement; + + replacement->next = item->next; + replacement->prev = item->prev; + + if (replacement->next != NULL) + { + replacement->next->prev = replacement; + } + if (parent->child == item) + { + if (parent->child->prev == parent->child) + { + replacement->prev = replacement; + } + parent->child = replacement; + } + else + { /* + * To find the last item in array quickly, we use prev in array. + * We can't modify the last item's next pointer where this item was the parent's child + */ + if (replacement->prev != NULL) + { + replacement->prev->next = replacement; + } + if (replacement->next == NULL) + { + parent->child->prev = replacement; + } } - } - item->next = NULL; - item->prev = NULL; - cJSON_Delete(item); + item->next = NULL; + item->prev = NULL; + cJSON_Delete(item); - return true; + return true; } -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) { - if (which < 0) { - return false; - } +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) +{ + if (which < 0) + { + return false; + } - return cJSON_ReplaceItemViaPointer( - array, get_array_item(array, (size_t)which), newitem); + return cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem); } -static cJSON_bool replace_item_in_object(cJSON *object, const char *string, - cJSON *replacement, - cJSON_bool case_sensitive) { - if ((replacement == NULL) || (string == NULL)) { - return false; - } +static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive) +{ + if ((replacement == NULL) || (string == NULL)) + { + return false; + } - /* replace the name in the replacement */ - if (!(replacement->type & cJSON_StringIsConst) && - (replacement->string != NULL)) { - cJSON_free(replacement->string); - } - replacement->string = - (char *)cJSON_strdup((const unsigned char *)string, &global_hooks); - replacement->type &= ~cJSON_StringIsConst; + /* replace the name in the replacement */ + if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != NULL)) + { + cJSON_free(replacement->string); + } + replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + replacement->type &= ~cJSON_StringIsConst; - return cJSON_ReplaceItemViaPointer( - object, get_object_item(object, string, case_sensitive), replacement); + return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); } -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) { - return replace_item_in_object(object, string, newitem, false); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) +{ + return replace_item_in_object(object, string, newitem, false); } -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, - cJSON *newitem) { - return replace_item_in_object(object, string, newitem, true); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) +{ + return replace_item_in_object(object, string, newitem, true); } /* Create basic types: */ -CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_NULL; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_True; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_False; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = boolean ? cJSON_True : cJSON_False; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_Number; - item->valuedouble = num; - - /* use saturation in case of overflow */ - if (num >= INT_MAX) { - item->valueint = INT_MAX; - } else if (num <= (double)INT_MIN) { - item->valueint = INT_MIN; - } else { - item->valueint = (int)num; +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_NULL; } - } - return item; + return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_String; - item->valuestring = - (char *)cJSON_strdup((const unsigned char *)string, &global_hooks); - if (!item->valuestring) { - cJSON_Delete(item); - return NULL; +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_True; } - } - return item; + return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { - item->type = cJSON_String | cJSON_IsReference; - item->valuestring = (char *)cast_away_const(string); - } +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_False; + } - return item; + return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { - item->type = cJSON_Object | cJSON_IsReference; - item->child = (cJSON *)cast_away_const(child); - } +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = boolean ? cJSON_True : cJSON_False; + } - return item; + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Number; + item->valuedouble = num; + + /* use saturation in case of overflow */ + if (num >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (num <= (double)INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)num; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_String; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) + { + item->type = cJSON_String | cJSON_IsReference; + item->valuestring = (char*)cast_away_const(string); + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { + item->type = cJSON_Object | cJSON_IsReference; + item->child = (cJSON*)cast_away_const(child); + } + + return item; } CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { - item->type = cJSON_Array | cJSON_IsReference; - item->child = (cJSON *)cast_away_const(child); - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_Raw; - item->valuestring = - (char *)cJSON_strdup((const unsigned char *)raw, &global_hooks); - if (!item->valuestring) { - cJSON_Delete(item); - return NULL; + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { + item->type = cJSON_Array | cJSON_IsReference; + item->child = (cJSON*)cast_away_const(child); } - } - return item; + return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_Array; - } +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Raw; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } - return item; + return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_Object; - } +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type=cJSON_Array; + } - return item; + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_Object; + } + + return item; } /* Create Arrays: */ -CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) { - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; - if ((count < 0) || (numbers == NULL)) { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateNumber(numbers[i]); - if (!n) { - cJSON_Delete(a); - return NULL; + if ((count < 0) || (numbers == NULL)) + { + return NULL; } - if (!i) { - a->child = n; - } else { - suffix_object(p, n); + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if (!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; } - p = n; - } - if (a && a->child) { - a->child->prev = n; - } + if (a && a->child) { + a->child->prev = n; + } - return a; + return a; } -CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) { - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; - if ((count < 0) || (numbers == NULL)) { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateNumber((double)numbers[i]); - if (!n) { - cJSON_Delete(a); - return NULL; + if ((count < 0) || (numbers == NULL)) + { + return NULL; } - if (!i) { - a->child = n; - } else { - suffix_object(p, n); + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber((double)numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; } - p = n; - } - if (a && a->child) { - a->child->prev = n; - } + if (a && a->child) { + a->child->prev = n; + } - return a; + return a; } -CJSON_PUBLIC(cJSON *) -cJSON_CreateDoubleArray(const double *numbers, int count) { - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; - if ((count < 0) || (numbers == NULL)) { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateNumber(numbers[i]); - if (!n) { - cJSON_Delete(a); - return NULL; + if ((count < 0) || (numbers == NULL)) + { + return NULL; } - if (!i) { - a->child = n; - } else { - suffix_object(p, n); + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; } - p = n; - } - if (a && a->child) { - a->child->prev = n; - } + if (a && a->child) { + a->child->prev = n; + } - return a; + return a; } -CJSON_PUBLIC(cJSON *) -cJSON_CreateStringArray(const char *const *strings, int count) { - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; - if ((count < 0) || (strings == NULL)) { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateString(strings[i]); - if (!n) { - cJSON_Delete(a); - return NULL; + if ((count < 0) || (strings == NULL)) + { + return NULL; } - if (!i) { - a->child = n; - } else { - suffix_object(p, n); + + a = cJSON_CreateArray(); + + for (i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateString(strings[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p,n); + } + p = n; } - p = n; - } - if (a && a->child) { - a->child->prev = n; - } - - return a; + if (a && a->child) { + a->child->prev = n; + } + + return a; } /* Duplication */ -CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) { - cJSON *newitem = NULL; - cJSON *child = NULL; - cJSON *next = NULL; - cJSON *newchild = NULL; +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) +{ + cJSON *newitem = NULL; + cJSON *child = NULL; + cJSON *next = NULL; + cJSON *newchild = NULL; - /* Bail on bad ptr */ - if (!item) { - goto fail; - } - /* Create new item */ - newitem = cJSON_New_Item(&global_hooks); - if (!newitem) { - goto fail; - } - /* Copy over all vars */ - newitem->type = item->type & (~cJSON_IsReference); - newitem->valueint = item->valueint; - newitem->valuedouble = item->valuedouble; - if (item->valuestring) { - newitem->valuestring = - (char *)cJSON_strdup((unsigned char *)item->valuestring, &global_hooks); - if (!newitem->valuestring) { - goto fail; + /* Bail on bad ptr */ + if (!item) + { + goto fail; } - } - if (item->string) { - newitem->string = (item->type & cJSON_StringIsConst) - ? item->string - : (char *)cJSON_strdup((unsigned char *)item->string, - &global_hooks); - if (!newitem->string) { - goto fail; + /* Create new item */ + newitem = cJSON_New_Item(&global_hooks); + if (!newitem) + { + goto fail; } - } - /* If non-recursive, then we're done! */ - if (!recurse) { + /* Copy over all vars */ + newitem->type = item->type & (~cJSON_IsReference); + newitem->valueint = item->valueint; + newitem->valuedouble = item->valuedouble; + if (item->valuestring) + { + newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); + if (!newitem->valuestring) + { + goto fail; + } + } + if (item->string) + { + newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); + if (!newitem->string) + { + goto fail; + } + } + /* If non-recursive, then we're done! */ + if (!recurse) + { + return newitem; + } + /* Walk the ->next chain for the child. */ + child = item->child; + while (child != NULL) + { + newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */ + if (!newchild) + { + goto fail; + } + if (next != NULL) + { + /* If newitem->child already set, then crosswire ->prev and ->next and move on */ + next->next = newchild; + newchild->prev = next; + next = newchild; + } + else + { + /* Set newitem->child and move to it */ + newitem->child = newchild; + next = newchild; + } + child = child->next; + } + if (newitem && newitem->child) + { + newitem->child->prev = newchild; + } + return newitem; - } - /* Walk the ->next chain for the child. */ - child = item->child; - while (child != NULL) { - newchild = cJSON_Duplicate( - child, - true); /* Duplicate (with recurse) each item in the ->next chain */ - if (!newchild) { - goto fail; - } - if (next != NULL) { - /* If newitem->child already set, then crosswire ->prev and ->next and - * move on */ - next->next = newchild; - newchild->prev = next; - next = newchild; - } else { - /* Set newitem->child and move to it */ - newitem->child = newchild; - next = newchild; - } - child = child->next; - } - if (newitem && newitem->child) { - newitem->child->prev = newchild; - } - - return newitem; fail: - if (newitem != NULL) { - cJSON_Delete(newitem); - } + if (newitem != NULL) + { + cJSON_Delete(newitem); + } - return NULL; + return NULL; } -static void skip_oneline_comment(char **input) { - *input += static_strlen("//"); +static void skip_oneline_comment(char **input) +{ + *input += static_strlen("//"); - for (; (*input)[0] != '\0'; ++(*input)) { - if ((*input)[0] == '\n') { - *input += static_strlen("\n"); - return; + for (; (*input)[0] != '\0'; ++(*input)) + { + if ((*input)[0] == '\n') { + *input += static_strlen("\n"); + return; + } } - } } -static void skip_multiline_comment(char **input) { - *input += static_strlen("/*"); +static void skip_multiline_comment(char **input) +{ + *input += static_strlen("/*"); - for (; (*input)[0] != '\0'; ++(*input)) { - if (((*input)[0] == '*') && ((*input)[1] == '/')) { - *input += static_strlen("*/"); - return; + for (; (*input)[0] != '\0'; ++(*input)) + { + if (((*input)[0] == '*') && ((*input)[1] == '/')) + { + *input += static_strlen("*/"); + return; + } } - } } static void minify_string(char **input, char **output) { - (*output)[0] = (*input)[0]; - *input += static_strlen("\""); - *output += static_strlen("\""); - - for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) { (*output)[0] = (*input)[0]; + *input += static_strlen("\""); + *output += static_strlen("\""); - if ((*input)[0] == '\"') { - (*output)[0] = '\"'; - *input += static_strlen("\""); - *output += static_strlen("\""); - return; - } else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) { - (*output)[1] = (*input)[1]; - *input += static_strlen("\""); - *output += static_strlen("\""); + + for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) { + (*output)[0] = (*input)[0]; + + if ((*input)[0] == '\"') { + (*output)[0] = '\"'; + *input += static_strlen("\""); + *output += static_strlen("\""); + return; + } else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) { + (*output)[1] = (*input)[1]; + *input += static_strlen("\""); + *output += static_strlen("\""); + } } - } } -CJSON_PUBLIC(void) cJSON_Minify(char *json) { - char *into = json; +CJSON_PUBLIC(void) cJSON_Minify(char *json) +{ + char *into = json; - if (json == NULL) { - return; - } - - while (json[0] != '\0') { - switch (json[0]) { - case ' ': - case '\t': - case '\r': - case '\n': - json++; - break; - - case '/': - if (json[1] == '/') { - skip_oneline_comment(&json); - } else if (json[1] == '*') { - skip_multiline_comment(&json); - } else { - json++; - } - break; - - case '\"': - minify_string(&json, (char **)&into); - break; - - default: - into[0] = json[0]; - json++; - into++; - } - } - - /* and null-terminate. */ - *into = '\0'; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Invalid; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_False; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xff) == cJSON_True; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & (cJSON_True | cJSON_False)) != 0; -} -CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_NULL; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Number; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_String; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Array; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Object; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Raw; -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_Compare(const cJSON *const a, const cJSON *const b, - const cJSON_bool case_sensitive) { - if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || - cJSON_IsInvalid(a)) { - return false; - } - - /* check if type is valid */ - switch (a->type & 0xFF) { - case cJSON_False: - case cJSON_True: - case cJSON_NULL: - case cJSON_Number: - case cJSON_String: - case cJSON_Raw: - case cJSON_Array: - case cJSON_Object: - break; - - default: - return false; - } - - /* identical objects are equal */ - if (a == b) { - return true; - } - - switch (a->type & 0xFF) { - /* in these cases and equal type is enough */ - case cJSON_False: - case cJSON_True: - case cJSON_NULL: - return true; - - case cJSON_Number: - if (compare_double(a->valuedouble, b->valuedouble)) { - return true; - } - return false; - - case cJSON_String: - case cJSON_Raw: - if ((a->valuestring == NULL) || (b->valuestring == NULL)) { - return false; - } - if (strcmp(a->valuestring, b->valuestring) == 0) { - return true; + if (json == NULL) + { + return; } - return false; + while (json[0] != '\0') + { + switch (json[0]) + { + case ' ': + case '\t': + case '\r': + case '\n': + json++; + break; - case cJSON_Array: { - cJSON *a_element = a->child; - cJSON *b_element = b->child; + case '/': + if (json[1] == '/') + { + skip_oneline_comment(&json); + } + else if (json[1] == '*') + { + skip_multiline_comment(&json); + } else { + json++; + } + break; - for (; (a_element != NULL) && (b_element != NULL);) { - if (!cJSON_Compare(a_element, b_element, case_sensitive)) { + case '\"': + minify_string(&json, (char**)&into); + break; + + default: + into[0] = json[0]; + json++; + into++; + } + } + + /* and null-terminate. */ + *into = '\0'; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) +{ + if (item == NULL) + { return false; - } - - a_element = a_element->next; - b_element = b_element->next; } - /* one of the arrays is longer than the other */ - if (a_element != b_element) { - return false; - } - - return true; - } - - case cJSON_Object: { - cJSON *a_element = NULL; - cJSON *b_element = NULL; - cJSON_ArrayForEach(a_element, a) { - /* TODO This has O(n^2) runtime, which is horrible! */ - b_element = get_object_item(b, a_element->string, case_sensitive); - if (b_element == NULL) { - return false; - } - - if (!cJSON_Compare(a_element, b_element, case_sensitive)) { - return false; - } - } - - /* doing this twice, once on a and b to prevent true comparison if a subset - * of b - * TODO: Do this the proper way, this is just a fix for now */ - cJSON_ArrayForEach(b_element, b) { - a_element = get_object_item(a, b_element->string, case_sensitive); - if (a_element == NULL) { - return false; - } - - if (!cJSON_Compare(b_element, a_element, case_sensitive)) { - return false; - } - } - - return true; - } - - default: - return false; - } + return (item->type & 0xFF) == cJSON_Invalid; } -CJSON_PUBLIC(void *) cJSON_malloc(size_t size) { - return global_hooks.allocate(size); +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_False; } -CJSON_PUBLIC(void) cJSON_free(void *object) { global_hooks.deallocate(object); } +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xff) == cJSON_True; +} + + +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & (cJSON_True | cJSON_False)) != 0; +} +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_NULL; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Number; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_String; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Array; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Object; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Raw; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) +{ + if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a)) + { + return false; + } + + /* check if type is valid */ + switch (a->type & 0xFF) + { + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + case cJSON_Number: + case cJSON_String: + case cJSON_Raw: + case cJSON_Array: + case cJSON_Object: + break; + + default: + return false; + } + + /* identical objects are equal */ + if (a == b) + { + return true; + } + + switch (a->type & 0xFF) + { + /* in these cases and equal type is enough */ + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + return true; + + case cJSON_Number: + if (compare_double(a->valuedouble, b->valuedouble)) + { + return true; + } + return false; + + case cJSON_String: + case cJSON_Raw: + if ((a->valuestring == NULL) || (b->valuestring == NULL)) + { + return false; + } + if (strcmp(a->valuestring, b->valuestring) == 0) + { + return true; + } + + return false; + + case cJSON_Array: + { + cJSON *a_element = a->child; + cJSON *b_element = b->child; + + for (; (a_element != NULL) && (b_element != NULL);) + { + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + + a_element = a_element->next; + b_element = b_element->next; + } + + /* one of the arrays is longer than the other */ + if (a_element != b_element) { + return false; + } + + return true; + } + + case cJSON_Object: + { + cJSON *a_element = NULL; + cJSON *b_element = NULL; + cJSON_ArrayForEach(a_element, a) + { + /* TODO This has O(n^2) runtime, which is horrible! */ + b_element = get_object_item(b, a_element->string, case_sensitive); + if (b_element == NULL) + { + return false; + } + + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + } + + /* doing this twice, once on a and b to prevent true comparison if a subset of b + * TODO: Do this the proper way, this is just a fix for now */ + cJSON_ArrayForEach(b_element, b) + { + a_element = get_object_item(a, b_element->string, case_sensitive); + if (a_element == NULL) + { + return false; + } + + if (!cJSON_Compare(b_element, a_element, case_sensitive)) + { + return false; + } + } + + return true; + } + + default: + return false; + } +} + +CJSON_PUBLIC(void *) cJSON_malloc(size_t size) +{ + return global_hooks.allocate(size); +} + +CJSON_PUBLIC(void) cJSON_free(void *object) +{ + global_hooks.deallocate(object); +} diff --git a/project/app/wifi_app/hisi_tools/app/client/cJSON.h b/project/app/wifi_app/hisi_tools/app/client/cJSON.h index 0916f8f30..e97e5f4cd 100644 --- a/project/app/wifi_app/hisi_tools/app/client/cJSON.h +++ b/project/app/wifi_app/hisi_tools/app/client/cJSON.h @@ -24,27 +24,23 @@ #define cJSON__h #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -#if !defined(__WINDOWS__) && \ - (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) +#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) #define __WINDOWS__ #endif #ifdef __WINDOWS__ -/* When compiling for windows, we specify a specific calling convention to avoid -issues where we are being called from a project with a different default calling -convention. For windows you have 3 define options: +/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options: -CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever -dllexport symbols CJSON_EXPORT_SYMBOLS - Define this on library build when you -want to dllexport symbols (default) CJSON_IMPORT_SYMBOLS - Define this if you -want to dllimport symbol +CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols +CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default) +CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol -For *nix builds that support visibility attribute, you can define similar -behavior by +For *nix builds that support visibility attribute, you can define similar behavior by setting default visibility to hidden by adding -fvisibility=hidden (for gcc) @@ -52,35 +48,31 @@ or -xldscope=hidden (for sun cc) to CFLAGS -then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way -CJSON_EXPORT_SYMBOLS does +then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does */ #define CJSON_CDECL __cdecl #define CJSON_STDCALL __stdcall -/* export symbols by default, this is necessary for copy pasting the C and - * header file */ -#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && \ - !defined(CJSON_EXPORT_SYMBOLS) +/* export symbols by default, this is necessary for copy pasting the C and header file */ +#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS) #define CJSON_EXPORT_SYMBOLS #endif #if defined(CJSON_HIDE_SYMBOLS) -#define CJSON_PUBLIC(type) type CJSON_STDCALL +#define CJSON_PUBLIC(type) type CJSON_STDCALL #elif defined(CJSON_EXPORT_SYMBOLS) -#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL +#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL #elif defined(CJSON_IMPORT_SYMBOLS) -#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL +#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL #endif #else /* !__WINDOWS__ */ #define CJSON_CDECL #define CJSON_STDCALL -#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && \ - defined(CJSON_API_VISIBILITY) -#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) +#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type #else #define CJSON_PUBLIC(type) type #endif @@ -95,140 +87,109 @@ CJSON_EXPORT_SYMBOLS does /* cJSON Types: */ #define cJSON_Invalid (0) -#define cJSON_False (1 << 0) -#define cJSON_True (1 << 1) -#define cJSON_NULL (1 << 2) +#define cJSON_False (1 << 0) +#define cJSON_True (1 << 1) +#define cJSON_NULL (1 << 2) #define cJSON_Number (1 << 3) #define cJSON_String (1 << 4) -#define cJSON_Array (1 << 5) +#define cJSON_Array (1 << 5) #define cJSON_Object (1 << 6) -#define cJSON_Raw (1 << 7) /* raw json */ +#define cJSON_Raw (1 << 7) /* raw json */ #define cJSON_IsReference 256 #define cJSON_StringIsConst 512 /* The cJSON structure: */ -typedef struct cJSON { - /* next/prev allow you to walk array/object chains. Alternatively, use - * GetArraySize/GetArrayItem/GetObjectItem */ - struct cJSON *next; - struct cJSON *prev; - /* An array or object item will have a child pointer pointing to a chain of - * the items in the array/object. */ - struct cJSON *child; +typedef struct cJSON +{ + /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON *next; + struct cJSON *prev; + /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + struct cJSON *child; - /* The type of the item, as above. */ - int type; + /* The type of the item, as above. */ + int type; - /* The item's string, if type==cJSON_String and type == cJSON_Raw */ - char *valuestring; - /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ - int valueint; - /* The item's number, if type==cJSON_Number */ - double valuedouble; + /* The item's string, if type==cJSON_String and type == cJSON_Raw */ + char *valuestring; + /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ + int valueint; + /* The item's number, if type==cJSON_Number */ + double valuedouble; - /* The item's name string, if this item is the child of, or is in the list of - * subitems of an object. */ - char *string; + /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + char *string; } cJSON; -typedef struct cJSON_Hooks { - /* malloc/free are CDECL on Windows regardless of the default calling - * convention of the compiler, so ensure the hooks allow passing those - * functions directly. */ - void *(CJSON_CDECL *malloc_fn)(size_t sz); - void(CJSON_CDECL *free_fn)(void *ptr); +typedef struct cJSON_Hooks +{ + /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ + void *(CJSON_CDECL *malloc_fn)(size_t sz); + void (CJSON_CDECL *free_fn)(void *ptr); } cJSON_Hooks; typedef int cJSON_bool; -/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse - * them. This is to prevent stack overflows. */ +/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. + * This is to prevent stack overflows. */ #ifndef CJSON_NESTING_LIMIT #define CJSON_NESTING_LIMIT 1000 #endif /* returns the version of cJSON as a string */ -CJSON_PUBLIC(const char *) cJSON_Version(void); +CJSON_PUBLIC(const char*) cJSON_Version(void); /* Supply malloc, realloc and free functions to cJSON */ -CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks); +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); -/* Memory Management: the caller is always responsible to free the results from - * all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib - * free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is - * cJSON_PrintPreallocated, where the caller has full responsibility of the - * buffer. */ -/* Supply a block of JSON, and this returns a cJSON object you can interrogate. - */ +/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ +/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithLength(const char *value, size_t buffer_length); -/* ParseWithOpts allows you to require (and check) that the JSON is null - * terminated, and to retrieve the pointer to the final byte parsed. */ -/* If you supply a ptr in return_parse_end and parsing fails, then - * return_parse_end will contain a pointer to the error so will match - * cJSON_GetErrorPtr(). */ -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithOpts(const char *value, const char **return_parse_end, - cJSON_bool require_null_terminated); -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, - const char **return_parse_end, - cJSON_bool require_null_terminated); +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length); +/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ +/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated); /* Render a cJSON entity to text for transfer/storage. */ CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); /* Render a cJSON entity to text for transfer/storage without any formatting. */ CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); -/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess - * at the final size. guessing well reduces reallocation. fmt=0 gives - * unformatted, =1 gives formatted */ -CJSON_PUBLIC(char *) -cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); -/* Render a cJSON entity to text using a buffer already allocated in memory with - * given length. Returns 1 on success and 0 on failure. */ -/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will - * use, so to be safe allocate 5 bytes more than you actually need */ -CJSON_PUBLIC(cJSON_bool) -cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, - const cJSON_bool format); +/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); +/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ +/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); /* Delete a cJSON entity and all subentities. */ CJSON_PUBLIC(void) cJSON_Delete(cJSON *item); /* Returns the number of items in an array (or object). */ CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); -/* Retrieve item number "index" from array "array". Returns NULL if - * unsuccessful. */ +/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */ CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); /* Get item "string" from object. Case insensitive. */ -CJSON_PUBLIC(cJSON *) -cJSON_GetObjectItem(const cJSON *const object, const char *const string); -CJSON_PUBLIC(cJSON *) -cJSON_GetObjectItemCaseSensitive(const cJSON *const object, - const char *const string); -CJSON_PUBLIC(cJSON_bool) -cJSON_HasObjectItem(const cJSON *object, const char *string); -/* For analysing failed parses. This returns a pointer to the parse error. - * You'll probably need to look a few chars back to make sense of it. Defined - * when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); +/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); /* Check item type and return its value */ -CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item); -CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item); +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item); +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item); /* These functions check the type of an item */ -CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); /* These calls create a cJSON item of the appropriate type. */ CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); @@ -251,126 +212,77 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); /* These utilities create an Array of count items. - * The parameter count cannot be greater than the number of elements in the - * number array, otherwise array access will be out of bounds.*/ + * The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); -CJSON_PUBLIC(cJSON *) -cJSON_CreateStringArray(const char *const *strings, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count); /* Append item to the specified array/object. */ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item); -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); -/* Use this when string is definitely const (i.e. a literal, or as good as), and - * will definitely survive the cJSON object. WARNING: When this function was - * used, make sure to always check that (item->type & cJSON_StringIsConst) is - * zero before writing to `item->string` */ -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); -/* Append reference to item to the specified array/object. Use this when you - * want to add an existing cJSON to a new cJSON, but don't want to corrupt your - * existing cJSON. */ -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); +/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. + * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before + * writing to `item->string` */ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); +/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); /* Remove/Detach items from Arrays/Objects. */ -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemFromObject(cJSON *object, const char *string); -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); -CJSON_PUBLIC(void) -cJSON_DeleteItemFromObject(cJSON *object, const char *string); -CJSON_PUBLIC(void) -cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); /* Update array items. */ -CJSON_PUBLIC(cJSON_bool) -cJSON_InsertItemInArray( - cJSON *array, int which, - cJSON *newitem); /* Shifts pre-existing items to the right. */ -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, - cJSON *replacement); -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem); -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, - cJSON *newitem); +CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); /* Duplicate a cJSON item */ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); -/* Duplicate will create a new, identical cJSON item to the one you pass, in new - * memory that will need to be released. With recurse!=0, it will duplicate any - * children connected to the item. The item->next and ->prev pointers are always - * zero on return from Duplicate. */ -/* Recursively compare two cJSON items for equality. If either a or b is NULL or - * invalid, they will be considered unequal. case_sensitive determines if object - * keys are treated case sensitive (1) or case insensitive (0) */ -CJSON_PUBLIC(cJSON_bool) -cJSON_Compare(const cJSON *const a, const cJSON *const b, - const cJSON_bool case_sensitive); +/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will + * need to be released. With recurse!=0, it will duplicate any children connected to the item. + * The item->next and ->prev pointers are always zero on return from Duplicate. */ +/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. + * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); -/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from - * strings. The input pointer json cannot point to a read-only address area, - * such as a string constant, but should point to a readable and writable adress - * area. */ +/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. + * The input pointer json cannot point to a read-only address area, such as a string constant, + * but should point to a readable and writable adress area. */ CJSON_PUBLIC(void) cJSON_Minify(char *json); /* Helper functions for creating and adding items to an object at the same time. * They return the added item or NULL on failure. */ -CJSON_PUBLIC(cJSON *) -cJSON_AddNullToObject(cJSON *const object, const char *const name); -CJSON_PUBLIC(cJSON *) -cJSON_AddTrueToObject(cJSON *const object, const char *const name); -CJSON_PUBLIC(cJSON *) -cJSON_AddFalseToObject(cJSON *const object, const char *const name); -CJSON_PUBLIC(cJSON *) -cJSON_AddBoolToObject(cJSON *const object, const char *const name, - const cJSON_bool boolean); -CJSON_PUBLIC(cJSON *) -cJSON_AddNumberToObject(cJSON *const object, const char *const name, - const double number); -CJSON_PUBLIC(cJSON *) -cJSON_AddStringToObject(cJSON *const object, const char *const name, - const char *const string); -CJSON_PUBLIC(cJSON *) -cJSON_AddRawToObject(cJSON *const object, const char *const name, - const char *const raw); -CJSON_PUBLIC(cJSON *) -cJSON_AddObjectToObject(cJSON *const object, const char *const name); -CJSON_PUBLIC(cJSON *) -cJSON_AddArrayToObject(cJSON *const object, const char *const name); +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean); +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number); +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string); +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw); +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name); -/* When assigning an integer value, it needs to be propagated to valuedouble - * too. */ -#define cJSON_SetIntValue(object, number) \ - ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) +/* When assigning an integer value, it needs to be propagated to valuedouble too. */ +#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) /* helper for the cJSON_SetNumberValue macro */ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); -#define cJSON_SetNumberValue(object, number) \ - ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) -/* Change the valuestring of a cJSON_String object, only takes effect when type - * of object is cJSON_String */ -CJSON_PUBLIC(char *) -cJSON_SetValuestring(cJSON *object, const char *valuestring); +#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) +/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */ +CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring); /* Macro for iterating over an array or object */ -#define cJSON_ArrayForEach(element, array) \ - for (element = (array != NULL) ? (array)->child : NULL; element != NULL; \ - element = element->next) +#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) -/* malloc/free objects using the malloc/free functions that have been set with - * cJSON_InitHooks */ +/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ CJSON_PUBLIC(void *) cJSON_malloc(size_t size); CJSON_PUBLIC(void) cJSON_free(void *object); diff --git a/project/app/wifi_app/hisi_tools/app/client/sample_cli.c b/project/app/wifi_app/hisi_tools/app/client/sample_cli.c index ff9571521..c59a6fb9a 100644 --- a/project/app/wifi_app/hisi_tools/app/client/sample_cli.c +++ b/project/app/wifi_app/hisi_tools/app/client/sample_cli.c @@ -1,173 +1,173 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights - * reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: sample cli file. + * Author: Hisilicon + * Create: 2020-09-09 */ /***************************************************************************** 1 Í·Îļþ°üº¬ *****************************************************************************/ -#include "hi_base.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "hi_types.h" #include "securec.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "hi_base.h" #include "cJSON.h" /***************************************************************************** 4 º¯ÊýʵÏÖ *****************************************************************************/ -hi_void client_wait_event(hi_u8 cmdval) { - ssize_t recvbytes; - char buf[SOCK_BUF_MAX]; - struct sockaddr_in clientaddr; - socklen_t addrlen = sizeof(clientaddr); - struct timeval tv; +hi_void client_wait_event(hi_u8 cmdval) +{ + ssize_t recvbytes; + char buf[SOCK_BUF_MAX]; + struct sockaddr_in clientaddr; + socklen_t addrlen = sizeof(clientaddr); + struct timeval tv; - int sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (sockfd == -1) { - sample_log_print("socket error:%s\n", strerror(errno)); - return -1; - } - - struct sockaddr_in servaddr; - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); - servaddr.sin_port = htons(SOCK_EVENT_PORT); - - if (bind(sockfd, (const struct sockaddr *)&servaddr, sizeof(servaddr)) == - -1) { - sample_log_print("bind error:%s", strerror(errno)); - goto error_bind; - } - - tv.tv_sec = 10; - tv.tv_usec = 0; - if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) != - 0) { - sample_log_print("setsockopt error:%s", strerror(errno)); - goto error_setsockopt; - } - - memset(buf, 0, sizeof(buf)); - recvbytes = recvfrom(sockfd, buf, sizeof(buf), 0, - (struct sockaddr *)&clientaddr, &addrlen); - if (recvbytes < 0) { - sample_log_print("recvfrom error:%s\n", strerror(errno)); - goto error_recvfrom; - } - - sample_log_print("SAMPLE_CLIENT:--[%s]-[%d]--\n", buf, strlen(buf)); - cJSON *root = cJSON_Parse(buf); - if (NULL == root) { - sample_log_print("SAMPLE_CLIENT:parseJson---Parse fail\n"); - goto error_recvfrom; - } - - cJSON *item = cJSON_GetObjectItem(root, "cmd"); - if (NULL != item) { - if (cmdval == atoi(item->valuestring)) { + int sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd == -1) { + sample_log_print("socket error:%s\n", strerror(errno)); + return -1; } - } - cJSON_Delete(root); + struct sockaddr_in servaddr; + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); + servaddr.sin_port = htons(SOCK_EVENT_PORT); + + if (bind(sockfd, (const struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { + sample_log_print("bind error:%s", strerror(errno)); + goto error_bind; + } + + tv.tv_sec = 10; + tv.tv_usec = 0; + if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) != 0) { + sample_log_print("setsockopt error:%s", strerror(errno)); + goto error_setsockopt; + } + + memset(buf, 0, sizeof(buf)); + recvbytes = recvfrom(sockfd, buf, sizeof(buf), 0, (struct sockaddr *)&clientaddr, &addrlen); + if (recvbytes < 0) { + sample_log_print("recvfrom error:%s\n", strerror(errno)); + goto error_recvfrom; + } + + sample_log_print("SAMPLE_CLIENT:--[%s]-[%d]--\n", buf, strlen(buf)); + cJSON* root = cJSON_Parse(buf); + if (NULL == root) { + sample_log_print("SAMPLE_CLIENT:parseJson---Parse fail\n"); + goto error_recvfrom; + } + + cJSON* item = cJSON_GetObjectItem(root, "cmd"); + if (NULL != item) { + if (cmdval == atoi(item->valuestring)) { + } + } + + cJSON_Delete(root); error_bind: error_setsockopt: error_recvfrom: - close(sockfd); + close(sockfd); } -hi_void client_send_cmd(hi_s32 sockfd, const hi_char *cmd, hi_u32 cmd_len) { - struct sockaddr_in servaddr; - ssize_t recvbytes; - hi_char buf[SOCK_BUF_MAX]; - struct sockaddr_in clientaddr; - socklen_t addrlen = sizeof(clientaddr); - struct timeval tv; - int retry = 3; +hi_void client_send_cmd(hi_s32 sockfd, const hi_char *cmd, hi_u32 cmd_len) +{ + struct sockaddr_in servaddr; + ssize_t recvbytes; + hi_char buf[SOCK_BUF_MAX]; + struct sockaddr_in clientaddr; + socklen_t addrlen = sizeof(clientaddr); + struct timeval tv; + int retry = 3; - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); - servaddr.sin_port = htons(SOCK_PORT); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); + servaddr.sin_port = htons(SOCK_PORT); - if (cmd_len > SOCK_BUF_MAX) { - sample_log_print("cmd length is overflow\n"); - return; - } - - if (sendto(sockfd, cmd, strlen(cmd), 0, (const struct sockaddr *)&servaddr, - sizeof(servaddr)) == -1) { - sample_log_print("SAMPLE_CLIENT: sendto error:%s\n", strerror(errno)); - return; - } - - tv.tv_sec = 10; - tv.tv_usec = 0; - if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) != - 0) { - sample_log_print("setsockopt error:%s", strerror(errno)); - return; - } - - memset(buf, 0, sizeof(buf)); - recvbytes = recvfrom(sockfd, buf, sizeof(buf), 0, - (struct sockaddr *)&clientaddr, &addrlen); - if (recvbytes < 0) { - sample_log_print("recvfrom error:%s\n", strerror(errno)); - return; - } - - if (strcmp("OK", buf) != 0) { - sample_log_print("SAMPLE_CLIENT: sendto cmd error!\n"); - return; - } - - if (strcmp("getmac", cmd) == 0) { - client_wait_event(2); - } else if (strcmp("getip", cmd) == 0) { - client_wait_event(3); - } else if (strcmp("wakecode", cmd) == 0) { - client_wait_event(15); - } else if (strcmp("getall", cmd) == 0) { - client_wait_event(20); - } - - sample_log_print("SAMPLE_CLIENT: send cmd ok!\n"); -} - -hi_s32 main(hi_s32 argc, const hi_char **argv) { - (void)argc; - hi_char cmd[SOCK_BUF_MAX] = {0}; - if (argc < 2 || argv == NULL) { /* 2:²ÎÊý¸öÊý */ - sample_log_print("usage sample_cli \n"); - return -1; - } - if (strcmp("pirset", argv[1]) == 0) { - if (sprintf_s(cmd, sizeof(cmd), "%s %s", argv[1], argv[2]) < 0) { - sample_log_print("sprintf_s is error\n"); + if (cmd_len > SOCK_BUF_MAX) { + sample_log_print("cmd length is overflow\n"); + return; } - } else { - if (strcpy_s(cmd, sizeof(cmd), argv[1]) < 0) { - sample_log_print("strcpt is error\n"); + + if (sendto(sockfd, cmd, strlen(cmd), 0, (const struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { + sample_log_print("SAMPLE_CLIENT: sendto error:%s\n", strerror(errno)); + return; } - cmd[strlen(argv[1])] = '\0'; - } - hi_s32 sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (sockfd == -1) { - sample_log_print("socket is error:%s\n", strerror(errno)); - return -1; - } + tv.tv_sec = 10; + tv.tv_usec = 0; + if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) != 0) { + sample_log_print("setsockopt error:%s", strerror(errno)); + return; + } - client_send_cmd(sockfd, cmd, strlen(cmd)); - close(sockfd); - return 0; + memset(buf, 0, sizeof(buf)); + recvbytes = recvfrom(sockfd, buf, sizeof(buf), 0, (struct sockaddr *)&clientaddr, &addrlen); + if (recvbytes < 0) { + sample_log_print("recvfrom error:%s\n", strerror(errno)); + return; + } + + if (strcmp("OK", buf) != 0) { + sample_log_print("SAMPLE_CLIENT: sendto cmd error!\n"); + return; + } + + if (strcmp("getmac", cmd) == 0) { + client_wait_event(2); + } else if (strcmp("getip", cmd) == 0) { + client_wait_event(3); + } else if (strcmp("wakecode", cmd) == 0) { + client_wait_event(15); + } else if (strcmp("getall", cmd) == 0) { + client_wait_event(20); + } + + sample_log_print("SAMPLE_CLIENT: send cmd ok!\n"); } + +hi_s32 main(hi_s32 argc, const hi_char **argv) +{ + (void)argc; + hi_char cmd[SOCK_BUF_MAX] = {0}; + if (argc < 2 || argv == NULL) { /* 2:²ÎÊý¸öÊý */ + sample_log_print("usage sample_cli \n"); + return -1; + } + if (strcmp("pirset", argv[1]) == 0) { + if (sprintf_s(cmd, sizeof(cmd), "%s %s", argv[1], argv[2]) < 0) { + sample_log_print("sprintf_s is error\n"); + } + } else { + if (strcpy_s(cmd, sizeof(cmd), argv[1]) < 0) { + sample_log_print("strcpt is error\n"); + } + cmd[strlen(argv[1])] = '\0'; + } + + hi_s32 sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd == -1) { + sample_log_print("socket is error:%s\n", strerror(errno)); + return -1; + } + + client_send_cmd(sockfd, cmd, strlen(cmd)); + close(sockfd); + return 0; +} + diff --git a/project/app/wifi_app/hisi_tools/app/include/hi_base.h b/project/app/wifi_app/hisi_tools/app/include/hi_base.h old mode 100644 new mode 100755 index b9dae95fe..4ea731511 --- a/project/app/wifi_app/hisi_tools/app/include/hi_base.h +++ b/project/app/wifi_app/hisi_tools/app/include/hi_base.h @@ -1,7 +1,8 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights - * reserved. Description: header file for Wi-Fi Station component Author: - * Hisilicon Create: 2020-09-09 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: header file for Wi-Fi Station component + * Author: Hisilicon + * Create: 2020-09-09 */ #ifndef __SAMPLE_COMM_H__ @@ -12,17 +13,17 @@ extern "C" { #endif /* __cplusplus */ -#define CMD_MAX_LEN 1500 -#define SOCK_BUF_MAX 1500 -#define SOCK_PORT 8822 -#define SOCK_EVENT_PORT 8823 +#define CMD_MAX_LEN 1500 +#define SOCK_BUF_MAX 1500 +#define SOCK_PORT 8822 +#define SOCK_EVENT_PORT 8823 -#define sample_log_print(fmt, args...) \ - printf("[%s][%s][l:%d]," fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, \ - ##args); +#define sample_log_print(fmt, args...) \ + printf("[%s][%s][l:%d]," fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args); #define sample_unused(x) ((x) = (x)) #ifdef __cplusplus } #endif /* __cplusplus */ #endif + diff --git a/project/app/wifi_app/hisi_tools/app/include/hi_errno.h b/project/app/wifi_app/hisi_tools/app/include/hi_errno.h index 79b8c408d..34c4d5efc 100644 --- a/project/app/wifi_app/hisi_tools/app/include/hi_errno.h +++ b/project/app/wifi_app/hisi_tools/app/include/hi_errno.h @@ -1,470 +1,474 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights - * reserved. Description: Error code returned by the interface. Author: - * Hisilicon Create: 2019-08-02 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights reserved. + * Description: Error code returned by the interface. + * Author: Hisilicon + * Create: 2019-08-02 */ #ifndef __HI_ERRNO_H__ #define __HI_ERRNO_H__ /***************************************************************************** - * 1¡¢Í¨ÓôíÎóÂë¡£×¢Òâ0x8000 0000×îºÃ±ðÓ㬲úÉú½Ø¶ÏÎóÅÐΪ³É¹¦ - *****************************************************************************/ -#define HI_SUCCESS 0 -#define HI_FAILURE (hi_u32)(-1) -#define HI_S_FAILURE (-1) -#define HI_MALLOC_FAILUE 0x80000001 -#define HI_TIMEOUT 0x80000002 -#define HI_RECVING 0x80000003 -#define HI_MEMCPY_S 0x80000004 -#define HI_MEMSET_S 0x80000005 -#define HI_SPRINTF_S 0x80000006 -#define HI_STRCPY_S 0x80000007 +* 1¡¢Í¨ÓôíÎóÂë¡£×¢Òâ0x8000 0000×îºÃ±ðÓ㬲úÉú½Ø¶ÏÎóÅÐΪ³É¹¦ +*****************************************************************************/ +#define HI_SUCCESS 0 +#define HI_FAILURE (hi_u32)(-1) +#define HI_S_FAILURE (-1) +#define HI_MALLOC_FAILUE 0x80000001 +#define HI_TIMEOUT 0x80000002 +#define HI_RECVING 0x80000003 +#define HI_MEMCPY_S 0x80000004 +#define HI_MEMSET_S 0x80000005 +#define HI_SPRINTF_S 0x80000006 +#define HI_STRCPY_S 0x80000007 /***************************************************************************** - * 2¡¢ÏµÍ³ÊÊÅä²ã:´íÎóÂë - *****************************************************************************/ +* 2¡¢ÏµÍ³ÊÊÅä²ã:´íÎóÂë +*****************************************************************************/ /* ÈÎÎñ */ -#define HI_ERR_TASK_INVALID_PARAM 0x80000080 -#define HI_ERR_TASK_CREATE_FAIL 0x80000081 -#define HI_ERR_TASK_DELETE_FAIL 0x80000082 -#define HI_ERR_TASK_SUPPEND_FAIL 0x80000083 -#define HI_ERR_TASK_RESUME_FAIL 0x80000084 -#define HI_ERR_TASK_GET_PRI_FAIL 0x80000085 -#define HI_ERR_TASK_SET_PRI_FAIL 0x80000086 -#define HI_ERR_TASK_LOCK_FAIL 0x80000087 -#define HI_ERR_TASK_UNLOCK_FAIL 0x80000088 -#define HI_ERR_TASK_DELAY_FAIL 0x80000089 -#define HI_ERR_TASK_GET_INFO_FAIL 0x8000008A -#define HI_ERR_TASK_REGISTER_SCHEDULE_FAIL 0x8000008B -#define HI_ERR_TASK_NOT_CREATED 0x8000008C +#define HI_ERR_TASK_INVALID_PARAM 0x80000080 +#define HI_ERR_TASK_CREATE_FAIL 0x80000081 +#define HI_ERR_TASK_DELETE_FAIL 0x80000082 +#define HI_ERR_TASK_SUPPEND_FAIL 0x80000083 +#define HI_ERR_TASK_RESUME_FAIL 0x80000084 +#define HI_ERR_TASK_GET_PRI_FAIL 0x80000085 +#define HI_ERR_TASK_SET_PRI_FAIL 0x80000086 +#define HI_ERR_TASK_LOCK_FAIL 0x80000087 +#define HI_ERR_TASK_UNLOCK_FAIL 0x80000088 +#define HI_ERR_TASK_DELAY_FAIL 0x80000089 +#define HI_ERR_TASK_GET_INFO_FAIL 0x8000008A +#define HI_ERR_TASK_REGISTER_SCHEDULE_FAIL 0x8000008B +#define HI_ERR_TASK_NOT_CREATED 0x8000008C /* ÖжÏISR */ -#define HI_ERR_ISR_INVALID_PARAM 0x800000C0 -#define HI_ERR_ISR_REQ_IRQ_FAIL 0x800000C1 -#define HI_ERR_ISR_ADD_JOB_MALLOC_FAIL 0x800000C2 -#define HI_ERR_ISR_ADD_JOB_SYS_FAIL 0x800000C3 -#define HI_ERR_ISR_DEL_IRQ_FAIL 0x800000C4 -#define HI_ERR_ISR_ALREADY_CREATED 0x800000C5 -#define HI_ERR_ISR_NOT_CREATED 0x800000C6 -#define HI_ERR_ISR_ENABLE_IRQ_FAIL 0x800000C7 -#define HI_ERR_ISR_IRQ_ADDR_NOK 0x800000C8 +#define HI_ERR_ISR_INVALID_PARAM 0x800000C0 +#define HI_ERR_ISR_REQ_IRQ_FAIL 0x800000C1 +#define HI_ERR_ISR_ADD_JOB_MALLOC_FAIL 0x800000C2 +#define HI_ERR_ISR_ADD_JOB_SYS_FAIL 0x800000C3 +#define HI_ERR_ISR_DEL_IRQ_FAIL 0x800000C4 +#define HI_ERR_ISR_ALREADY_CREATED 0x800000C5 +#define HI_ERR_ISR_NOT_CREATED 0x800000C6 +#define HI_ERR_ISR_ENABLE_IRQ_FAIL 0x800000C7 +#define HI_ERR_ISR_IRQ_ADDR_NOK 0x800000C8 /* ÄÚ´æ */ -#define HI_ERR_MEM_INVALID_PARAM 0x80000100 -#define HI_ERR_MEM_CREAT_POOL_FAIL 0x80000101 -#define HI_ERR_MEM_CREATE_POOL_NOT_ENOUGH_HANDLE 0x80000102 -#define HI_ERR_MEM_FREE_FAIL 0x80000103 -#define HI_ERR_MEM_RE_INIT 0x80000104 -#define HI_ERR_MEM_NOT_INIT 0x80000105 -#define HI_ERR_MEM_CREAT_POOL_MALLOC_FAIL 0x80000106 -#define HI_ERR_MEM_GET_INFO_FAIL 0x80000107 -#define HI_ERR_MEM_GET_OS_INFO_NOK 0x80000108 +#define HI_ERR_MEM_INVALID_PARAM 0x80000100 +#define HI_ERR_MEM_CREAT_POOL_FAIL 0x80000101 +#define HI_ERR_MEM_CREATE_POOL_NOT_ENOUGH_HANDLE 0x80000102 +#define HI_ERR_MEM_FREE_FAIL 0x80000103 +#define HI_ERR_MEM_RE_INIT 0x80000104 +#define HI_ERR_MEM_NOT_INIT 0x80000105 +#define HI_ERR_MEM_CREAT_POOL_MALLOC_FAIL 0x80000106 +#define HI_ERR_MEM_GET_INFO_FAIL 0x80000107 +#define HI_ERR_MEM_GET_OS_INFO_NOK 0x80000108 /* OSTIMER¶¨Ê±Æ÷ */ -#define HI_ERR_TIMER_FAILURE 0x80000140 -#define HI_ERR_TIMER_INVALID_PARAM 0x80000141 -#define HI_ERR_TIMER_CREATE_HANDLE_FAIL 0x80000142 -#define HI_ERR_TIMER_START_FAIL 0x80000143 -#define HI_ERR_TIMER_HANDLE_NOT_CREATE 0x80000144 -#define HI_ERR_TIMER_HANDLE_INVALID 0x80000145 -#define HI_ERR_TIMER_STATUS_INVALID 0x80000146 -#define HI_ERR_TIMER_STATUS_START 0x80000147 -#define HI_ERR_TIMER_INVALID_MODE 0x80000148 -#define HI_ERR_TIMER_EXPIRE_INVALID 0x80000149 -#define HI_ERR_TIMER_FUNCTION_NULL 0x8000014A -#define HI_ERR_TIMER_HANDLE_MAXSIZE 0x8000014B -#define HI_ERR_TIMER_MALLOC_FAIL 0x8000014C -#define HI_ERR_TIMER_NOT_INIT 0x8000014D +#define HI_ERR_TIMER_FAILURE 0x80000140 +#define HI_ERR_TIMER_INVALID_PARAM 0x80000141 +#define HI_ERR_TIMER_CREATE_HANDLE_FAIL 0x80000142 +#define HI_ERR_TIMER_START_FAIL 0x80000143 +#define HI_ERR_TIMER_HANDLE_NOT_CREATE 0x80000144 +#define HI_ERR_TIMER_HANDLE_INVALID 0x80000145 +#define HI_ERR_TIMER_STATUS_INVALID 0x80000146 +#define HI_ERR_TIMER_STATUS_START 0x80000147 +#define HI_ERR_TIMER_INVALID_MODE 0x80000148 +#define HI_ERR_TIMER_EXPIRE_INVALID 0x80000149 +#define HI_ERR_TIMER_FUNCTION_NULL 0x8000014A +#define HI_ERR_TIMER_HANDLE_MAXSIZE 0x8000014B +#define HI_ERR_TIMER_MALLOC_FAIL 0x8000014C +#define HI_ERR_TIMER_NOT_INIT 0x8000014D /* ÐźÅÁ¿ */ -#define HI_ERR_SEM_INVALID_PARAM 0x80000180 -#define HI_ERR_SEM_CREATE_FAIL 0x80000181 -#define HI_ERR_SEM_DELETE_FAIL 0x80000182 -#define HI_ERR_SEM_WAIT_FAIL 0x80000183 -#define HI_ERR_SEM_SIG_FAIL 0x80000184 -#define HI_ERR_SEM_WAIT_TIME_OUT 0x80000185 +#define HI_ERR_SEM_INVALID_PARAM 0x80000180 +#define HI_ERR_SEM_CREATE_FAIL 0x80000181 +#define HI_ERR_SEM_DELETE_FAIL 0x80000182 +#define HI_ERR_SEM_WAIT_FAIL 0x80000183 +#define HI_ERR_SEM_SIG_FAIL 0x80000184 +#define HI_ERR_SEM_WAIT_TIME_OUT 0x80000185 /* »¥³âËø */ -#define HI_ERR_MUX_INVALID_PARAM 0x800001C0 -#define HI_ERR_MUX_CREATE_FAIL 0x800001C1 -#define HI_ERR_MUX_DELETE_FAIL 0x800001C2 -#define HI_ERR_MUX_PEND_FAIL 0x800001C3 -#define HI_ERR_MUX_POST_FAIL 0x800001C4 +#define HI_ERR_MUX_INVALID_PARAM 0x800001C0 +#define HI_ERR_MUX_CREATE_FAIL 0x800001C1 +#define HI_ERR_MUX_DELETE_FAIL 0x800001C2 +#define HI_ERR_MUX_PEND_FAIL 0x800001C3 +#define HI_ERR_MUX_POST_FAIL 0x800001C4 /* ÏûÏ¢ */ -#define HI_ERR_MSG_INVALID_PARAM 0x80000200 -#define HI_ERR_MSG_CREATE_Q_FAIL 0x80000201 -#define HI_ERR_MSG_DELETE_Q_FAIL 0x80000202 -#define HI_ERR_MSG_WAIT_FAIL 0x80000203 -#define HI_ERR_MSG_SEND_FAIL 0x80000204 -#define HI_ERR_MSG_GET_Q_INFO_FAIL 0x80000205 -#define HI_ERR_MSG_Q_DELETE_FAIL 0x80000206 -#define HI_ERR_MSG_WAIT_TIME_OUT 0x80000207 +#define HI_ERR_MSG_INVALID_PARAM 0x80000200 +#define HI_ERR_MSG_CREATE_Q_FAIL 0x80000201 +#define HI_ERR_MSG_DELETE_Q_FAIL 0x80000202 +#define HI_ERR_MSG_WAIT_FAIL 0x80000203 +#define HI_ERR_MSG_SEND_FAIL 0x80000204 +#define HI_ERR_MSG_GET_Q_INFO_FAIL 0x80000205 +#define HI_ERR_MSG_Q_DELETE_FAIL 0x80000206 +#define HI_ERR_MSG_WAIT_TIME_OUT 0x80000207 /* ʼþ */ -#define HI_ERR_EVENT_INVALID_PARAM 0x80000240 -#define HI_ERR_EVENT_CREATE_NO_HADNLE 0x80000241 -#define HI_ERR_EVENT_CREATE_SYS_FAIL 0x80000242 -#define HI_ERR_EVENT_SEND_FAIL 0x80000243 -#define HI_ERR_EVENT_WAIT_FAIL 0x80000244 -#define HI_ERR_EVENT_CLEAR_FAIL 0x80000245 -#define HI_ERR_EVENT_RE_INIT 0x80000246 -#define HI_ERR_EVENT_NOT_ENOUGH_MEMORY 0x80000247 -#define HI_ERR_EVENT_NOT_INIT 0x80000248 -#define HI_ERR_EVENT_DELETE_FAIL 0x80000249 -#define HI_ERR_EVENT_WAIT_TIME_OUT 0x8000024A +#define HI_ERR_EVENT_INVALID_PARAM 0x80000240 +#define HI_ERR_EVENT_CREATE_NO_HADNLE 0x80000241 +#define HI_ERR_EVENT_CREATE_SYS_FAIL 0x80000242 +#define HI_ERR_EVENT_SEND_FAIL 0x80000243 +#define HI_ERR_EVENT_WAIT_FAIL 0x80000244 +#define HI_ERR_EVENT_CLEAR_FAIL 0x80000245 +#define HI_ERR_EVENT_RE_INIT 0x80000246 +#define HI_ERR_EVENT_NOT_ENOUGH_MEMORY 0x80000247 +#define HI_ERR_EVENT_NOT_INIT 0x80000248 +#define HI_ERR_EVENT_DELETE_FAIL 0x80000249 +#define HI_ERR_EVENT_WAIT_TIME_OUT 0x8000024A /* osά²â */ -#define HI_ERR_OSSTAT_INVALID_PARAM 0x80000280 -#define HI_ERR_OSSTAT_SYSTEM_CALL_ERROR 0x80000281 +#define HI_ERR_OSSTAT_INVALID_PARAM 0x80000280 +#define HI_ERR_OSSTAT_SYSTEM_CALL_ERROR 0x80000281 /* liteos fpb */ -#define HI_ERR_FPB_COMP_REPEAT 0x800002C0 -#define HI_ERR_FPB_NO_COMP 0x800002C1 -#define HI_ERR_FPB_TYPE 0x800002C2 -#define HI_ERR_FPB_NO_FREE_COMP 0x800002C3 -#define HI_ERR_FPB_ADDR_NOT_ALIGN 0x800002C4 -#define HI_ERR_FPB_TARGET_ADDR 0x800002C5 -#define HI_ERR_FPB_BUSY 0x800002C6 /* ????????? */ -#define HI_ERR_FPB_ERROR_INPUT 0x800002C7 +#define HI_ERR_FPB_COMP_REPEAT 0x800002C0 +#define HI_ERR_FPB_NO_COMP 0x800002C1 +#define HI_ERR_FPB_TYPE 0x800002C2 +#define HI_ERR_FPB_NO_FREE_COMP 0x800002C3 +#define HI_ERR_FPB_ADDR_NOT_ALIGN 0x800002C4 +#define HI_ERR_FPB_TARGET_ADDR 0x800002C5 +#define HI_ERR_FPB_BUSY 0x800002C6 /* ????????? */ +#define HI_ERR_FPB_ERROR_INPUT 0x800002C7 /* CPU */ -#define HI_ERR_CPUP_NOT_INIT 0x80000300 -#define HI_ERR_CPUP_INVALID_PARAM 0x80000301 -#define HI_ERR_CPU_CLK_INVALID_PARAM 0x80000302 +#define HI_ERR_CPUP_NOT_INIT 0x80000300 +#define HI_ERR_CPUP_INVALID_PARAM 0x80000301 +#define HI_ERR_CPU_CLK_INVALID_PARAM 0x80000302 /* file system */ -#define HI_ERR_FS_INVALID_PARAM 0x80000400 -#define HI_ERR_FS_NO_DEVICE 0x80000401 -#define HI_ERR_FS_NO_SPACE 0x80000402 /* No space left on device */ -#define HI_ERR_FS_BAD_DESCRIPTOR 0x80000403 -#define HI_ERR_FS_FILE_EXISTS 0x80000404 -#define HI_ERR_FS_NOT_FOUND 0x80000405 -#define HI_ERR_FS_NAME_TOO_LONG 0x80000406 -#define HI_ERR_FS_READ_ONLY_FS 0x80000407 /* Read-only file system */ -#define HI_ERR_FS_IO_ERROR 0x80000408 -#define HI_ERR_FS_NO_MORE_FILES 0x80000409 +#define HI_ERR_FS_INVALID_PARAM 0x80000400 +#define HI_ERR_FS_NO_DEVICE 0x80000401 +#define HI_ERR_FS_NO_SPACE 0x80000402 /* No space left on device */ +#define HI_ERR_FS_BAD_DESCRIPTOR 0x80000403 +#define HI_ERR_FS_FILE_EXISTS 0x80000404 +#define HI_ERR_FS_NOT_FOUND 0x80000405 +#define HI_ERR_FS_NAME_TOO_LONG 0x80000406 +#define HI_ERR_FS_READ_ONLY_FS 0x80000407 /* Read-only file system */ +#define HI_ERR_FS_IO_ERROR 0x80000408 +#define HI_ERR_FS_NO_MORE_FILES 0x80000409 /***************************************************************************** - * 3¡¢Çý¶¯:´íÎóÂë - *****************************************************************************/ +* 3¡¢Çý¶¯:´íÎóÂë +*****************************************************************************/ /* ´®¿Ú */ -#define HI_ERR_UART_INVALID_PARAMETER 0x80001000 -#define HI_ERR_UART_INVALID_SUSPEND 0x80001001 -#define HI_ERR_UART_INVALID_PARITY 0x80001002 -#define HI_ERR_UART_INVALID_DATA_BITS 0x80001003 -#define HI_ERR_UART_INVALID_STOP_BITS 0x80001004 -#define HI_ERR_UART_INVALID_BAUD 0x80001005 -#define HI_ERR_UART_INVALID_COM_PORT 0x80001006 -#define HI_ERR_UART_NOT_SUPPORT_DMA 0x80001007 +#define HI_ERR_UART_INVALID_PARAMETER 0x80001000 +#define HI_ERR_UART_INVALID_SUSPEND 0x80001001 +#define HI_ERR_UART_INVALID_PARITY 0x80001002 +#define HI_ERR_UART_INVALID_DATA_BITS 0x80001003 +#define HI_ERR_UART_INVALID_STOP_BITS 0x80001004 +#define HI_ERR_UART_INVALID_BAUD 0x80001005 +#define HI_ERR_UART_INVALID_COM_PORT 0x80001006 +#define HI_ERR_UART_NOT_SUPPORT_DMA 0x80001007 /* gpio */ -#define HI_ERR_GPIO_INVALID_PARAMETER 0x80001040 -#define HI_ERR_GPIO_REPEAT_INIT 0x80001041 -#define HI_ERR_GPIO_NOT_INIT 0x80001042 -#define HI_ERR_GPIO_NOT_SUPPORT 0x80001043 +#define HI_ERR_GPIO_INVALID_PARAMETER 0x80001040 +#define HI_ERR_GPIO_REPEAT_INIT 0x80001041 +#define HI_ERR_GPIO_NOT_INIT 0x80001042 +#define HI_ERR_GPIO_NOT_SUPPORT 0x80001043 /* ¿´ÃŹ· */ -#define HI_ERR_WATCHDOG_PARA_ERROR 0x80001080 +#define HI_ERR_WATCHDOG_PARA_ERROR 0x80001080 /* Flash */ -#define HI_ERR_FLASH_NOT_INIT 0x800010C0 -#define HI_ERR_FLASH_INVALID_PARAM 0x800010C1 -#define HI_ERR_FLASH_INVALID_PARAM_BEYOND_ADDR 0x800010C2 -#define HI_ERR_FLASH_INVALID_PARAM_SIZE_ZERO 0x800010C3 -#define HI_ERR_FLASH_INVALID_PARAM_ERASE_NOT_ALIGN 0x800010C4 -#define HI_ERR_FLASH_INVALID_PARAM_IOCTRL_DATA_NULL 0x800010C5 -#define HI_ERR_FLASH_INVALID_PARAM_DATA_NULL 0x800010C6 -#define HI_ERR_FLASH_INVALID_PARAM_PAD1 0x800010C7 -#define HI_ERR_FLASH_INVALID_PARAM_PAD2 0x800010C8 -#define HI_ERR_FLASH_INVALID_PARAM_PAD3 0x800010C9 -#define HI_ERR_FLASH_INVALID_PARAM_PAD4 0x800010CA -#define HI_ERR_FLASH_TIME_OUT_WAIT_READY 0x800010CB -#define HI_ERR_FLASH_QUAD_MODE_READ_REG1 0x800010CC -#define HI_ERR_FLASH_QUAD_MODE_READ_REG2 0x800010CD -#define HI_ERR_FLASH_QUAD_MODE_COMPARE_REG 0x800010CE -#define HI_ERR_FLASH_NO_MATCH_FLASH 0x800010CF -#define HI_ERR_FLASH_WRITE_ENABLE 0x800010D0 -#define HI_ERR_FLASH_NO_MATCH_ERASE_SIZE 0x800010D1 -#define HI_ERR_FLASH_MAX_SPI_OP 0x800010D2 -#define HI_ERR_FLASH_NOT_SUPPORT_IOCTRL_ID 0x800010D3 -#define HI_ERR_FLASH_INVALID_CHIP_ID 0x800010D4 -#define HI_ERR_FLASH_RE_INIT 0x800010D5 -#define HI_ERR_FLASH_WRITE_NOT_SUPPORT_ERASE 0x800010D6 -#define HI_ERR_FLASH_WRITE_COMPARE_WRONG 0x800010D7 -#define HI_ERR_FLASH_WAIT_CFG_START_TIME_OUT 0x800010D8 -#define HI_ERR_FLASH_PATITION_INIT_FAIL 0x800010D9 -#define HI_ERR_FLASH_INITILIZATION 0x800010DA -#define HI_ERR_FLASH_ERASE_NOT_4K_ALIGN 0x800010DB -#define HI_ERR_FLASH_PROTECT_NOT_SUPPORT 0x800010DC -#define HI_ERR_FLASH_PROTECT_NOT_INIT 0x800010DD -#define HI_ERR_FLASH_PROTECT_RE_INIT 0x800010DE -#define HI_ERR_FLASH_PROTECT_NOT_FIND_CHIP 0x800010DF -#define HI_ERR_FLASH_MEMCPY_FAIL 0x800010E0 +#define HI_ERR_FLASH_NOT_INIT 0x800010C0 +#define HI_ERR_FLASH_INVALID_PARAM 0x800010C1 +#define HI_ERR_FLASH_INVALID_PARAM_BEYOND_ADDR 0x800010C2 +#define HI_ERR_FLASH_INVALID_PARAM_SIZE_ZERO 0x800010C3 +#define HI_ERR_FLASH_INVALID_PARAM_ERASE_NOT_ALIGN 0x800010C4 +#define HI_ERR_FLASH_INVALID_PARAM_IOCTRL_DATA_NULL 0x800010C5 +#define HI_ERR_FLASH_INVALID_PARAM_DATA_NULL 0x800010C6 +#define HI_ERR_FLASH_INVALID_PARAM_PAD1 0x800010C7 +#define HI_ERR_FLASH_INVALID_PARAM_PAD2 0x800010C8 +#define HI_ERR_FLASH_INVALID_PARAM_PAD3 0x800010C9 +#define HI_ERR_FLASH_INVALID_PARAM_PAD4 0x800010CA +#define HI_ERR_FLASH_TIME_OUT_WAIT_READY 0x800010CB +#define HI_ERR_FLASH_QUAD_MODE_READ_REG1 0x800010CC +#define HI_ERR_FLASH_QUAD_MODE_READ_REG2 0x800010CD +#define HI_ERR_FLASH_QUAD_MODE_COMPARE_REG 0x800010CE +#define HI_ERR_FLASH_NO_MATCH_FLASH 0x800010CF +#define HI_ERR_FLASH_WRITE_ENABLE 0x800010D0 +#define HI_ERR_FLASH_NO_MATCH_ERASE_SIZE 0x800010D1 +#define HI_ERR_FLASH_MAX_SPI_OP 0x800010D2 +#define HI_ERR_FLASH_NOT_SUPPORT_IOCTRL_ID 0x800010D3 +#define HI_ERR_FLASH_INVALID_CHIP_ID 0x800010D4 +#define HI_ERR_FLASH_RE_INIT 0x800010D5 +#define HI_ERR_FLASH_WRITE_NOT_SUPPORT_ERASE 0x800010D6 +#define HI_ERR_FLASH_WRITE_COMPARE_WRONG 0x800010D7 +#define HI_ERR_FLASH_WAIT_CFG_START_TIME_OUT 0x800010D8 +#define HI_ERR_FLASH_PATITION_INIT_FAIL 0x800010D9 +#define HI_ERR_FLASH_INITILIZATION 0x800010DA +#define HI_ERR_FLASH_ERASE_NOT_4K_ALIGN 0x800010DB +#define HI_ERR_FLASH_PROTECT_NOT_SUPPORT 0x800010DC +#define HI_ERR_FLASH_PROTECT_NOT_INIT 0x800010DD +#define HI_ERR_FLASH_PROTECT_RE_INIT 0x800010DE +#define HI_ERR_FLASH_PROTECT_NOT_FIND_CHIP 0x800010DF +#define HI_ERR_FLASH_MEMCPY_FAIL 0x800010E0 /* HRTIMER¶¨Ê±Æ÷ */ -#define HI_ERR_HRTIMER_ALREADY_INIT 0x80001100 -#define HI_ERR_HRTIMER_NOT_INIT 0x80001101 -#define HI_ERR_HRTIMER_HAVE_NO_AVAILABLE_HANDLE 0x80001102 -#define HI_ERR_HRTIMER_NOT_CREATE_HANDLE 0x80001103 -#define HI_ERR_HRTIMER_IN_START_STATUS 0x80001104 -#define HI_ERR_HRTIMER_NOT_START 0x80001105 -#define HI_ERR_HRTIMER_INVALID_ID 0x80001106 -#define HI_ERR_HRTIMER_INVALID_PARAMETER 0x80001107 -#define HI_ERR_HRTIMER_MALLOC_FAILUE 0x80001108 +#define HI_ERR_HRTIMER_ALREADY_INIT 0x80001100 +#define HI_ERR_HRTIMER_NOT_INIT 0x80001101 +#define HI_ERR_HRTIMER_HAVE_NO_AVAILABLE_HANDLE 0x80001102 +#define HI_ERR_HRTIMER_NOT_CREATE_HANDLE 0x80001103 +#define HI_ERR_HRTIMER_IN_START_STATUS 0x80001104 +#define HI_ERR_HRTIMER_NOT_START 0x80001105 +#define HI_ERR_HRTIMER_INVALID_ID 0x80001106 +#define HI_ERR_HRTIMER_INVALID_PARAMETER 0x80001107 +#define HI_ERR_HRTIMER_MALLOC_FAILUE 0x80001108 /* hardware timer */ -#define HI_ERR_HWTIMER_INVALID_PARAMETER 0x80001140 -#define HI_ERR_HWTIMER_INITILIZATION_ALREADY 0x80001141 -#define HI_ERR_HWTIMER_NO_INIT 0x80001142 +#define HI_ERR_HWTIMER_INVALID_PARAMETER 0x80001140 +#define HI_ERR_HWTIMER_INITILIZATION_ALREADY 0x80001141 +#define HI_ERR_HWTIMER_NO_INIT 0x80001142 /* i2c */ -#define HI_ERR_I2C_NOT_INIT 0x80001180 -#define HI_ERR_I2C_INVALID_PARAMETER 0x80001181 -#define HI_ERR_I2C_TIMEOUT_START 0x80001182 -#define HI_ERR_I2C_TIMEOUT_WAIT 0x80001183 -#define HI_ERR_I2C_TIMEOUT_STOP 0x80001184 -#define HI_ERR_I2C_TIMEOUT_RCV_BYTE 0x80001185 -#define HI_ERR_I2C_TIMEOUT_RCV_BYTE_PROC 0x80001186 -#define HI_ERR_I2C_WAIT_SEM_FAIL 0x80001187 -#define HI_ERR_I2C_START_ACK_ERR 0x80001188 -#define HI_ERR_I2C_WAIT_ACK_ERR 0x80001189 +#define HI_ERR_I2C_NOT_INIT 0x80001180 +#define HI_ERR_I2C_INVALID_PARAMETER 0x80001181 +#define HI_ERR_I2C_TIMEOUT_START 0x80001182 +#define HI_ERR_I2C_TIMEOUT_WAIT 0x80001183 +#define HI_ERR_I2C_TIMEOUT_STOP 0x80001184 +#define HI_ERR_I2C_TIMEOUT_RCV_BYTE 0x80001185 +#define HI_ERR_I2C_TIMEOUT_RCV_BYTE_PROC 0x80001186 +#define HI_ERR_I2C_WAIT_SEM_FAIL 0x80001187 +#define HI_ERR_I2C_START_ACK_ERR 0x80001188 +#define HI_ERR_I2C_WAIT_ACK_ERR 0x80001189 /* spi */ -#define HI_ERR_SPI_NOT_INIT 0x800011C0 -#define HI_ERR_SPI_REINIT 0x800011C1 -#define HI_ERR_SPI_PARAMETER_WRONG 0x800011C2 -#define HI_ERR_SPI_BUSY 0x800011C3 -#define HI_ERR_SPI_WRITE_TIMEOUT 0x800011C4 -#define HI_ERR_SPI_READ_TIMEOUT 0x800011C5 -#define HI_ERR_SPI_NOT_SUPPORT_DMA 0x800011C6 +#define HI_ERR_SPI_NOT_INIT 0x800011C0 +#define HI_ERR_SPI_REINIT 0x800011C1 +#define HI_ERR_SPI_PARAMETER_WRONG 0x800011C2 +#define HI_ERR_SPI_BUSY 0x800011C3 +#define HI_ERR_SPI_WRITE_TIMEOUT 0x800011C4 +#define HI_ERR_SPI_READ_TIMEOUT 0x800011C5 +#define HI_ERR_SPI_NOT_SUPPORT_DMA 0x800011C6 /* efuse */ -#define HI_ERR_EFUSE_INVALIDATE_ID 0x80001200 -#define HI_ERR_EFUSE_INVALIDATE_PARA 0x80001201 -#define HI_ERR_EFUSE_WRITE_ERR 0x80001202 -#define HI_ERR_EFUSE_INVALIDATE_AUTH 0x80001203 -#define HI_ERR_EFUSE_BUSY 0x80001204 -#define HI_ERR_EFUSE_TIMEOUT 0x80001205 +#define HI_ERR_EFUSE_INVALIDATE_ID 0x80001200 +#define HI_ERR_EFUSE_INVALIDATE_PARA 0x80001201 +#define HI_ERR_EFUSE_WRITE_ERR 0x80001202 +#define HI_ERR_EFUSE_INVALIDATE_AUTH 0x80001203 +#define HI_ERR_EFUSE_BUSY 0x80001204 +#define HI_ERR_EFUSE_TIMEOUT 0x80001205 /* cipher */ -#define HI_ERR_CIPHER_NOT_INIT 0x80001240 -#define HI_ERR_CIPHER_INVALID_POINT 0x80001241 -#define HI_ERR_CIPHER_INVALID_PARAMETER 0x80001242 -#define HI_ERR_CIPHER_NO_AVAILABLE_RNG 0x80001243 -#define HI_ERR_CIPHER_FAILED_MEM 0x80001244 -#define HI_ERR_CIPHER_OVERFLOW 0x80001245 -#define HI_ERR_CIPHER_TIMEOUT 0x80001246 -#define HI_ERR_CIPHER_UNSUPPORTED 0x80001247 -#define HI_ERR_CIPHER_REGISTER_IRQ 0x80001248 -#define HI_ERR_CIPHER_ILLEGAL_KEY 0x80001249 -#define HI_ERR_CIPHER_INVALID_ADDR 0x8000124A -#define HI_ERR_CIPHER_INVALID_LENGTH 0x8000124B -#define HI_ERR_CIPHER_ILLEGAL_DATA 0x8000124C -#define HI_ERR_CIPHER_RSA_SIGN 0x8000124D -#define HI_ERR_CIPHER_RSA_VERIFY 0x8000124E -#define HI_ERR_CIPHER_RESULT_WARNING 0x8000124F -#define HI_ERR_CIPHER_FLUSH_DCACHE_FAILED 0x80001250 +#define HI_ERR_CIPHER_NOT_INIT 0x80001240 +#define HI_ERR_CIPHER_INVALID_POINT 0x80001241 +#define HI_ERR_CIPHER_INVALID_PARAMETER 0x80001242 +#define HI_ERR_CIPHER_NO_AVAILABLE_RNG 0x80001243 +#define HI_ERR_CIPHER_FAILED_MEM 0x80001244 +#define HI_ERR_CIPHER_OVERFLOW 0x80001245 +#define HI_ERR_CIPHER_TIMEOUT 0x80001246 +#define HI_ERR_CIPHER_UNSUPPORTED 0x80001247 +#define HI_ERR_CIPHER_REGISTER_IRQ 0x80001248 +#define HI_ERR_CIPHER_ILLEGAL_KEY 0x80001249 +#define HI_ERR_CIPHER_INVALID_ADDR 0x8000124A +#define HI_ERR_CIPHER_INVALID_LENGTH 0x8000124B +#define HI_ERR_CIPHER_ILLEGAL_DATA 0x8000124C +#define HI_ERR_CIPHER_RSA_SIGN 0x8000124D +#define HI_ERR_CIPHER_RSA_VERIFY 0x8000124E +#define HI_ERR_CIPHER_RESULT_WARNING 0x8000124F +#define HI_ERR_CIPHER_FLUSH_DCACHE_FAILED 0x80001250 /* sdio */ -#define HI_ERR_SDIO_INVALID_PARAMETER 0x80001280 +#define HI_ERR_SDIO_INVALID_PARAMETER 0x80001280 /* tsensor */ -#define HI_ERR_TSENSOR_INVALID_PARAMETER 0x800012C0 +#define HI_ERR_TSENSOR_INVALID_PARAMETER 0x800012C0 /* adc */ -#define HI_ERR_ADC_PARAMETER_WRONG 0x80001300 -#define HI_ERR_ADC_INVALID_CHANNEL_ID 0x80001301 -#define HI_ERR_ADC_TIMEOUT 0x80001302 -#define HI_ERR_ADC_NOT_INIT 0x80001303 +#define HI_ERR_ADC_PARAMETER_WRONG 0x80001300 +#define HI_ERR_ADC_INVALID_CHANNEL_ID 0x80001301 +#define HI_ERR_ADC_TIMEOUT 0x80001302 +#define HI_ERR_ADC_NOT_INIT 0x80001303 /* pmw */ -#define HI_ERR_PWM_NO_INIT 0x80001340 -#define HI_ERR_PWM_INITILIZATION_ALREADY 0x80001341 -#define HI_ERR_PWM_INVALID_PARAMETER 0x80001342 +#define HI_ERR_PWM_NO_INIT 0x80001340 +#define HI_ERR_PWM_INITILIZATION_ALREADY 0x80001341 +#define HI_ERR_PWM_INVALID_PARAMETER 0x80001342 + /* dma */ -#define HI_ERR_DMA_INVALID_PARA 0x80001380 -#define HI_ERR_DMA_NOT_INIT 0x80001381 -#define HI_ERR_DMA_BUSY 0x80001382 -#define HI_ERR_DMA_TRANSFER_FAIL 0x80001383 -#define HI_ERR_DMA_TRANSFER_TIMEOUT 0x80001384 -#define HI_ERR_DMA_GET_NOTE_FAIL 0x80001385 -#define HI_ERR_DMA_LLI_NOT_CREATE 0x80001386 -#define HI_ERR_DMA_CH_IRQ_ENABLE_FAIL 0x80001387 +#define HI_ERR_DMA_INVALID_PARA 0x80001380 +#define HI_ERR_DMA_NOT_INIT 0x80001381 +#define HI_ERR_DMA_BUSY 0x80001382 +#define HI_ERR_DMA_TRANSFER_FAIL 0x80001383 +#define HI_ERR_DMA_TRANSFER_TIMEOUT 0x80001384 +#define HI_ERR_DMA_GET_NOTE_FAIL 0x80001385 +#define HI_ERR_DMA_LLI_NOT_CREATE 0x80001386 +#define HI_ERR_DMA_CH_IRQ_ENABLE_FAIL 0x80001387 /* audio */ -#define HI_ERR_AUDIO_BUSY 0x800013C0 -#define HI_ERR_AUDIO_INVALID_PARAMETER 0x800013C1 +#define HI_ERR_AUDIO_BUSY 0x800013C0 +#define HI_ERR_AUDIO_INVALID_PARAMETER 0x800013C1 /* i2s */ -#define HI_ERR_I2S_INVALID_PARAMETER 0x80001400 -#define HI_ERR_I2S_WRITE_TIMEOUT 0x80001401 +#define HI_ERR_I2S_INVALID_PARAMETER 0x80001400 +#define HI_ERR_I2S_WRITE_TIMEOUT 0x80001401 /***************************************************************************** - * 4¡¢ÖмäÓ¦ÓÃ:´íÎóÂë - *****************************************************************************/ +* 4¡¢ÖмäÓ¦ÓÃ:´íÎóÂë +*****************************************************************************/ /* NV */ -#define HI_ERR_NV_FILE_ERR 0x80003000 -#define HI_ERR_NV_MEMCPY_FAIL 0x80003001 -#define HI_ERR_NV_WRITE_FILE_FAIL 0x80003002 -#define HI_ERR_NV_UPDATA_DATA_FAIL 0x80003003 -#define HI_ERR_NV_UPDATA_FILE_FAIL 0x80003004 -#define HI_ERR_NV_NOT_SUPPORT_WRITE 0x80003005 -#define HI_ERR_NV_FSEC_TOTAL_NUM_INVALID 0x80003006 /* ¹¤³§NVÏî¸öÊý·Ç·¨ */ -#define HI_ERR_NV_FAIL_N_TIMES 0x80003007 -#define HI_ERR_NV_SEM_FAIL 0x80003008 -#define HI_ERR_NV_LEN_ERR 0x80003009 -#define HI_ERR_NV_NOT_FOUND 0x8000300A -#define HI_ERR_NV_FULL 0x8000300B -#define HI_ERR_NV_NOT_ENOUGH_MEMORY 0x8000300C -#define HI_ERR_NV_NOT_SUPPORT 0x8000300D -#define HI_ERR_NV_NOT_SUPPORT_ID 0x8000300E -#define HI_ERR_NV_BAD_DATA 0x8000300F -#define HI_ERR_NV_INVALID_TYPE 0x80003010 +#define HI_ERR_NV_FILE_ERR 0x80003000 +#define HI_ERR_NV_MEMCPY_FAIL 0x80003001 +#define HI_ERR_NV_WRITE_FILE_FAIL 0x80003002 +#define HI_ERR_NV_UPDATA_DATA_FAIL 0x80003003 +#define HI_ERR_NV_UPDATA_FILE_FAIL 0x80003004 +#define HI_ERR_NV_NOT_SUPPORT_WRITE 0x80003005 +#define HI_ERR_NV_FSEC_TOTAL_NUM_INVALID 0x80003006 /* ¹¤³§NVÏî¸öÊý·Ç·¨ */ +#define HI_ERR_NV_FAIL_N_TIMES 0x80003007 +#define HI_ERR_NV_SEM_FAIL 0x80003008 +#define HI_ERR_NV_LEN_ERR 0x80003009 +#define HI_ERR_NV_NOT_FOUND 0x8000300A +#define HI_ERR_NV_FULL 0x8000300B +#define HI_ERR_NV_NOT_ENOUGH_MEMORY 0x8000300C +#define HI_ERR_NV_NOT_SUPPORT 0x8000300D +#define HI_ERR_NV_NOT_SUPPORT_ID 0x8000300E +#define HI_ERR_NV_BAD_DATA 0x8000300F +#define HI_ERR_NV_INVALID_TYPE 0x80003010 /* NV¶Áȡʧ°Ü" "Read NVIM Failure" */ -#define HI_ERR_NV_ERROR_READ 0x80003011 +#define HI_ERR_NV_ERROR_READ 0x80003011 /* NVдʧ°Ü£¬³¤¶È¹ý³¤""Write Error for Length Overflow" */ -#define HI_ERR_NV_NOT_SUPPORT_LENTH 0x80003012 +#define HI_ERR_NV_NOT_SUPPORT_LENTH 0x80003012 /* NVдʧ°Ü,Flash»µ¿é" "Write Error for Flash Bad Block" */ -#define HI_ERR_NV_BAD_BLOCK 0x80003013 +#define HI_ERR_NV_BAD_BLOCK 0x80003013 /* NVдʧ°Ü,ÆäËû´íÎó" "Write Error for Unknown Reason" */ -#define HI_ERR_NV_ERROR_WRITE 0x80003014 -#define HI_ERR_NV_INITILIZATION 0x80003015 -#define HI_ERR_NV_INVALID_PARAMETER 0x80003016 +#define HI_ERR_NV_ERROR_WRITE 0x80003014 +#define HI_ERR_NV_INITILIZATION 0x80003015 +#define HI_ERR_NV_INVALID_PARAMETER 0x80003016 /* µÍ¹¦ºÄ */ -#define HI_ERR_LOWPOWER_INVALID_PARAMETER 0x80003040 +#define HI_ERR_LOWPOWER_INVALID_PARAMETER 0x80003040 /* upgrade common error */ -#define HI_ERR_UPG_COMMON 0x80003060 -#define HI_ERR_UPG_NULL_POINTER (HI_ERR_UPG_COMMON + 0x0) -#define HI_ERR_UPG_PARAMETER (HI_ERR_UPG_COMMON + 0x1) -#define HI_ERR_UPG_BACKUP_ADDR (HI_ERR_UPG_COMMON + 0x2) -#define HI_ERR_UPG_BUSY (HI_ERR_UPG_COMMON + 0x3) -#define HI_ERR_UPG_FLASH_BAD (HI_ERR_UPG_COMMON + 0x4) -#define HI_ERR_UPG_START_ADDR (HI_ERR_UPG_COMMON + 0x5) -#define HI_ERR_UPG_INITILIZATION_ALREADY (HI_ERR_UPG_COMMON + 0x6) -#define HI_ERR_UPG_FILE_LEN (HI_ERR_UPG_COMMON + 0x7) -#define HI_ERR_UPG_NOT_START (HI_ERR_UPG_COMMON + 0x8) -#define HI_ERR_UPG_MALLOC_FAIL (HI_ERR_UPG_COMMON + 0x9) -#define HI_ERR_UPG_GET_SECTION_HEAD (HI_ERR_UPG_COMMON + 0xA) -#define HI_ERR_UPG_BUF_LEN (HI_ERR_UPG_COMMON + 0xB) -#define HI_ERR_UPG_FLASH_SIZE (HI_ERR_UPG_COMMON + 0xC) -#define HI_ERR_UPG_NV_SIZE (HI_ERR_UPG_COMMON + 0xD) -#define HI_ERR_UPG_ALREADY_FINISH (HI_ERR_UPG_COMMON + 0xE) -#define HI_ERR_UPG_RSA_KEY_ADDR (HI_ERR_UPG_COMMON + 0xF) -#define HI_ERR_UPG_ECC_KEY_ADDR (HI_ERR_UPG_COMMON + 0x10) -#define HI_ERR_UPG_FILE_LEN_OVER (HI_ERR_UPG_COMMON + 0x11) -#define HI_ERR_UPG_STOP (HI_ERR_UPG_COMMON + 0x12) -#define HI_ERR_UPG_LOW_FIRMWARE_VER (HI_ERR_UPG_COMMON + 0x13) -#define HI_ERR_UPG_FULL_FIRMWARE_VER (HI_ERR_UPG_COMMON + 0x14) -#define HI_ERR_UPG_LOW_BOOT_VER (HI_ERR_UPG_COMMON + 0x15) -#define HI_ERR_UPG_FULL_BOOT_VER (HI_ERR_UPG_COMMON + 0x16) -#define HI_ERR_UPG_FIRST_PACKET_OFFSET (HI_ERR_UPG_COMMON + 0x17) -#define HI_ERR_UPG_MEMCPY_FAIL (HI_ERR_UPG_COMMON + 0x18) +#define HI_ERR_UPG_COMMON 0x80003060 +#define HI_ERR_UPG_NULL_POINTER (HI_ERR_UPG_COMMON + 0x0) +#define HI_ERR_UPG_PARAMETER (HI_ERR_UPG_COMMON + 0x1) +#define HI_ERR_UPG_BACKUP_ADDR (HI_ERR_UPG_COMMON + 0x2) +#define HI_ERR_UPG_BUSY (HI_ERR_UPG_COMMON + 0x3) +#define HI_ERR_UPG_FLASH_BAD (HI_ERR_UPG_COMMON + 0x4) +#define HI_ERR_UPG_START_ADDR (HI_ERR_UPG_COMMON + 0x5) +#define HI_ERR_UPG_INITILIZATION_ALREADY (HI_ERR_UPG_COMMON + 0x6) +#define HI_ERR_UPG_FILE_LEN (HI_ERR_UPG_COMMON + 0x7) +#define HI_ERR_UPG_NOT_START (HI_ERR_UPG_COMMON + 0x8) +#define HI_ERR_UPG_MALLOC_FAIL (HI_ERR_UPG_COMMON + 0x9) +#define HI_ERR_UPG_GET_SECTION_HEAD (HI_ERR_UPG_COMMON + 0xA) +#define HI_ERR_UPG_BUF_LEN (HI_ERR_UPG_COMMON + 0xB) +#define HI_ERR_UPG_FLASH_SIZE (HI_ERR_UPG_COMMON + 0xC) +#define HI_ERR_UPG_NV_SIZE (HI_ERR_UPG_COMMON + 0xD) +#define HI_ERR_UPG_ALREADY_FINISH (HI_ERR_UPG_COMMON + 0xE) +#define HI_ERR_UPG_RSA_KEY_ADDR (HI_ERR_UPG_COMMON + 0xF) +#define HI_ERR_UPG_ECC_KEY_ADDR (HI_ERR_UPG_COMMON + 0x10) +#define HI_ERR_UPG_FILE_LEN_OVER (HI_ERR_UPG_COMMON + 0x11) +#define HI_ERR_UPG_STOP (HI_ERR_UPG_COMMON + 0x12) +#define HI_ERR_UPG_LOW_FIRMWARE_VER (HI_ERR_UPG_COMMON + 0x13) +#define HI_ERR_UPG_FULL_FIRMWARE_VER (HI_ERR_UPG_COMMON + 0x14) +#define HI_ERR_UPG_LOW_BOOT_VER (HI_ERR_UPG_COMMON + 0x15) +#define HI_ERR_UPG_FULL_BOOT_VER (HI_ERR_UPG_COMMON + 0x16) +#define HI_ERR_UPG_FIRST_PACKET_OFFSET (HI_ERR_UPG_COMMON + 0x17) +#define HI_ERR_UPG_MEMCPY_FAIL (HI_ERR_UPG_COMMON + 0x18) /* upgrade file check error */ -#define HI_ERR_UPG_CHECK 0x80003080 -#define HI_ERR_UPG_IMAGE_ID (HI_ERR_UPG_CHECK + 0x0) -#define HI_ERR_UPG_FILE_TYPE (HI_ERR_UPG_CHECK + 0x1) -#define HI_ERR_UPG_HEAD_LEN (HI_ERR_UPG_CHECK + 0x2) -#define HI_ERR_UPG_SIGN_ALG (HI_ERR_UPG_CHECK + 0x3) -#define HI_ERR_UPG_RSA_KEY_LEN (HI_ERR_UPG_CHECK + 0x4) -#define HI_ERR_UPG_RSA_HEAD_SIGN (HI_ERR_UPG_CHECK + 0x5) -#define HI_ERR_UPG_ECC_KEY_LEN (HI_ERR_UPG_CHECK + 0x6) -#define HI_ERR_UPG_ECC_HEAD_SIGN (HI_ERR_UPG_CHECK + 0x7) -#define HI_ERR_UPG_COMMON_SHA256 (HI_ERR_UPG_CHECK + 0x8) -#define HI_ERR_UPG_SECTION_SHA256 (HI_ERR_UPG_CHECK + 0x9) -#define HI_ERR_UPG_FIRMWARE_VER (HI_ERR_UPG_CHECK + 0xA) -#define HI_ERR_UPG_BOOT_VER (HI_ERR_UPG_CHECK + 0xB) -#define HI_ERR_UPG_BOOT_HEAD (HI_ERR_UPG_CHECK + 0xC) -#define HI_ERR_UPG_BOOT_LEN (HI_ERR_UPG_CHECK + 0xD) -#define HI_ERR_UPG_BOOT_ROOT_KEY (HI_ERR_UPG_CHECK + 0xE) -#define HI_ERR_UPG_BOOT_ROOT_KEY_LEN (HI_ERR_UPG_CHECK + 0xF) -#define HI_ERR_UPG_BOOT_KEY_ID (HI_ERR_UPG_CHECK + 0x10) -#define HI_ERR_UPG_BOOT_SIGN_ALG (HI_ERR_UPG_CHECK + 0x11) -#define HI_ERR_UPG_BOOT_SUB_KEY (HI_ERR_UPG_CHECK + 0x12) -#define HI_ERR_UPG_BOOT_SUB_KEY_CAT (HI_ERR_UPG_CHECK + 0x13) -#define HI_ERR_UPG_BOOT_SUB_KEY_RSIM (HI_ERR_UPG_CHECK + 0x14) -#define HI_ERR_UPG_BOOT_DIE_ID (HI_ERR_UPG_CHECK + 0x15) -#define HI_ERR_UPG_BOOT_HASH (HI_ERR_UPG_CHECK + 0x16) -#define HI_ERR_UPG_BOOT_SUB_KEY_LEN (HI_ERR_UPG_CHECK + 0x17) +#define HI_ERR_UPG_CHECK 0x80003080 +#define HI_ERR_UPG_IMAGE_ID (HI_ERR_UPG_CHECK + 0x0) +#define HI_ERR_UPG_FILE_TYPE (HI_ERR_UPG_CHECK + 0x1) +#define HI_ERR_UPG_HEAD_LEN (HI_ERR_UPG_CHECK + 0x2) +#define HI_ERR_UPG_SIGN_ALG (HI_ERR_UPG_CHECK + 0x3) +#define HI_ERR_UPG_RSA_KEY_LEN (HI_ERR_UPG_CHECK + 0x4) +#define HI_ERR_UPG_RSA_HEAD_SIGN (HI_ERR_UPG_CHECK + 0x5) +#define HI_ERR_UPG_ECC_KEY_LEN (HI_ERR_UPG_CHECK + 0x6) +#define HI_ERR_UPG_ECC_HEAD_SIGN (HI_ERR_UPG_CHECK + 0x7) +#define HI_ERR_UPG_COMMON_SHA256 (HI_ERR_UPG_CHECK + 0x8) +#define HI_ERR_UPG_SECTION_SHA256 (HI_ERR_UPG_CHECK + 0x9) +#define HI_ERR_UPG_FIRMWARE_VER (HI_ERR_UPG_CHECK + 0xA) +#define HI_ERR_UPG_BOOT_VER (HI_ERR_UPG_CHECK + 0xB) +#define HI_ERR_UPG_BOOT_HEAD (HI_ERR_UPG_CHECK + 0xC) +#define HI_ERR_UPG_BOOT_LEN (HI_ERR_UPG_CHECK + 0xD) +#define HI_ERR_UPG_BOOT_ROOT_KEY (HI_ERR_UPG_CHECK + 0xE) +#define HI_ERR_UPG_BOOT_ROOT_KEY_LEN (HI_ERR_UPG_CHECK + 0xF) +#define HI_ERR_UPG_BOOT_KEY_ID (HI_ERR_UPG_CHECK + 0x10) +#define HI_ERR_UPG_BOOT_SIGN_ALG (HI_ERR_UPG_CHECK + 0x11) +#define HI_ERR_UPG_BOOT_SUB_KEY (HI_ERR_UPG_CHECK + 0x12) +#define HI_ERR_UPG_BOOT_SUB_KEY_CAT (HI_ERR_UPG_CHECK + 0x13) +#define HI_ERR_UPG_BOOT_SUB_KEY_RSIM (HI_ERR_UPG_CHECK + 0x14) +#define HI_ERR_UPG_BOOT_DIE_ID (HI_ERR_UPG_CHECK + 0x15) +#define HI_ERR_UPG_BOOT_HASH (HI_ERR_UPG_CHECK + 0x16) +#define HI_ERR_UPG_BOOT_SUB_KEY_LEN (HI_ERR_UPG_CHECK + 0x17) /* DIAG */ -#define HI_ERR_DIAG_NOT_FOUND 0x800030C0 -#define HI_ERR_DIAG_INVALID_ID 0x800030C1 -#define HI_ERR_DIAG_FULL 0x800030C2 -#define HI_ERR_DIAG_CONSUMED 0x800030C3 -#define HI_ERR_DIAG_CONTINUE 0x800030C4 -#define HI_ERR_DIAG_TOO_SMALL_BUFFER 0x800030C5 -#define HI_ERR_DIAG_NO_MORE_DATA 0x800030C6 -#define HI_ERR_DIAG_NOT_ENOUGH_MEMORY 0x800030C7 -#define HI_ERR_DIAG_INVALID_HEAP_ADDR 0x800030C8 -#define HI_ERR_DIAG_NOT_CONNECT 0x800030C9 -#define HI_ERR_DIAG_BUSY 0x800030CA -#define HI_ERR_DIAG_TOO_LARGE_FRAME 0x800030CB -#define HI_ERR_DIAG_RAM_ALIGN 0x800030CC -#define HI_ERR_DIAG_NOT_SUPPORT 0x800030CD -#define HI_ERR_DIAG_UNAVAILABLE 0x800030CE -#define HI_ERR_DIAG_CFG_NOT_ALLOW 0x800030CF -#define HI_ERR_DIAG_INVALID_CODE_ADDR 0x800030D0 -#define HI_ERR_DIAG_OBJ_NOT_FOUND 0x800030D1 -#define HI_ERR_DIAG_QUEUE_FULL 0x800030D2 -#define HI_ERR_DIAG_NO_MORE_MEMORY 0x800030D3 -#define HI_ERR_DIAG_SYSTEM_CALL_ERROR 0x800030D4 -#define HI_ERR_DIAG_NO_INIT 0x800030D5 -#define HI_ERR_DIAG_INVALID_PARAMETER 0x800030D6 -#define HI_ERR_DIAG_STAT_NOT_SUPPORT 0x800030D7 -#define HI_ERR_DIAG_ID_OR_CALLBACK_ALREADY_REGISTERED 0x800030D8 -#define HI_ERR_DIAG_SET_CONN_ACK_INFO 0x800030D9 -#define HI_ERR_DIAG_CMD_NUM_EXCEED_UPPER_LIMIT 0x800030DA -#define HI_ERR_DIAG_MEMCPY_FAIL 0x800030DB +#define HI_ERR_DIAG_NOT_FOUND 0x800030C0 +#define HI_ERR_DIAG_INVALID_ID 0x800030C1 +#define HI_ERR_DIAG_FULL 0x800030C2 +#define HI_ERR_DIAG_CONSUMED 0x800030C3 +#define HI_ERR_DIAG_CONTINUE 0x800030C4 +#define HI_ERR_DIAG_TOO_SMALL_BUFFER 0x800030C5 +#define HI_ERR_DIAG_NO_MORE_DATA 0x800030C6 +#define HI_ERR_DIAG_NOT_ENOUGH_MEMORY 0x800030C7 +#define HI_ERR_DIAG_INVALID_HEAP_ADDR 0x800030C8 +#define HI_ERR_DIAG_NOT_CONNECT 0x800030C9 +#define HI_ERR_DIAG_BUSY 0x800030CA +#define HI_ERR_DIAG_TOO_LARGE_FRAME 0x800030CB +#define HI_ERR_DIAG_RAM_ALIGN 0x800030CC +#define HI_ERR_DIAG_NOT_SUPPORT 0x800030CD +#define HI_ERR_DIAG_UNAVAILABLE 0x800030CE +#define HI_ERR_DIAG_CFG_NOT_ALLOW 0x800030CF +#define HI_ERR_DIAG_INVALID_CODE_ADDR 0x800030D0 +#define HI_ERR_DIAG_OBJ_NOT_FOUND 0x800030D1 +#define HI_ERR_DIAG_QUEUE_FULL 0x800030D2 +#define HI_ERR_DIAG_NO_MORE_MEMORY 0x800030D3 +#define HI_ERR_DIAG_SYSTEM_CALL_ERROR 0x800030D4 +#define HI_ERR_DIAG_NO_INIT 0x800030D5 +#define HI_ERR_DIAG_INVALID_PARAMETER 0x800030D6 +#define HI_ERR_DIAG_STAT_NOT_SUPPORT 0x800030D7 +#define HI_ERR_DIAG_ID_OR_CALLBACK_ALREADY_REGISTERED 0x800030D8 +#define HI_ERR_DIAG_SET_CONN_ACK_INFO 0x800030D9 +#define HI_ERR_DIAG_CMD_NUM_EXCEED_UPPER_LIMIT 0x800030DA +#define HI_ERR_DIAG_MEMCPY_FAIL 0x800030DB /* reset ¸´Î» */ -#define HI_ERR_RESET_TOO_LARGE_DATA 0x80003100 -#define HI_ERR_RESET_INVALID_PARAMETER 0x80003101 +#define HI_ERR_RESET_TOO_LARGE_DATA 0x80003100 +#define HI_ERR_RESET_INVALID_PARAMETER 0x80003101 /* syserror */ -#define HI_ERR_SYSERROR_NOT_FOUND 0x80003140 -#define HI_ERR_SYSERROR_INVALID_PARAMETER 0x80003141 +#define HI_ERR_SYSERROR_NOT_FOUND 0x80003140 +#define HI_ERR_SYSERROR_INVALID_PARAMETER 0x80003141 + /* APP */ -#define HI_ERR_APP_INITILIZATION_ALREADY 0x80003180 -#define HI_ERR_APP_INVALID_PARAMETER 0x80003181 +#define HI_ERR_APP_INITILIZATION_ALREADY 0x80003180 +#define HI_ERR_APP_INVALID_PARAMETER 0x80003181 /* CRC */ -#define HI_ERR_CRC_INVALID_PARAMETER 0x800031C0 +#define HI_ERR_CRC_INVALID_PARAMETER 0x800031C0 + /* sigma */ -#define HI_ERR_SIGMA_INVALID_PARAMETER 0x80003200 +#define HI_ERR_SIGMA_INVALID_PARAMETER 0x80003200 /* data collect */ -#define HI_ERR_DATACOLLECT_INVALID_PARAMETER 0x80003240 -#define HI_ERR_DATACOLLECT_BUSY 0x80003241 +#define HI_ERR_DATACOLLECT_INVALID_PARAMETER 0x80003240 +#define HI_ERR_DATACOLLECT_BUSY 0x80003241 /* AT */ -#define HI_ERR_AT_NAME_OR_FUNC_REPEAT_REGISTERED 0x80003280 -#define HI_ERR_AT_INVALID_PARAMETER 0x80003281 +#define HI_ERR_AT_NAME_OR_FUNC_REPEAT_REGISTERED 0x80003280 +#define HI_ERR_AT_INVALID_PARAMETER 0x80003281 /***************************************************************************** - * 5¡¢Ð­ÒéÕ»:´íÎóÂë - *****************************************************************************/ +* 5¡¢Ð­ÒéÕ»:´íÎóÂë +*****************************************************************************/ /* wifi */ /* ˵Ã÷:wifi´íÎóÂëhi_err_code_enum ½«base»ùÖµÐÞ¸ÄΪÆðʼֵ£¬ÆäËû´íÎóÂëÒ»´ÎÑÓ˳ */ /* dmac */ -#define HI_ERR_WIFI_DMAC_NOT_SUPPORT 0x80004000 +#define HI_ERR_WIFI_DMAC_NOT_SUPPORT 0x80004000 /* hmac */ -#define HI_ERR_WIFI_HMAC_INVALID_PARAMETER 0x80004040 +#define HI_ERR_WIFI_HMAC_INVALID_PARAMETER 0x80004040 /* wal */ -#define HI_ERR_WIFI_WAL_MALLOC_FAIL 0x80004080 -#define HI_ERR_WIFI_WAL_FAILURE 0x80004081 -#define HI_ERR_WIFI_WAL_BUSY 0x80004082 -#define HI_ERR_WIFI_WAL_INVALID_PARAMETER 0x80004083 +#define HI_ERR_WIFI_WAL_MALLOC_FAIL 0x80004080 +#define HI_ERR_WIFI_WAL_FAILURE 0x80004081 +#define HI_ERR_WIFI_WAL_BUSY 0x80004082 +#define HI_ERR_WIFI_WAL_INVALID_PARAMETER 0x80004083 /***************************************************************************** - * 6¡¢Hisi±£Áô unit128¸ö - * 7¡¢¿Í»§Ê¹ÓÃÔ¤Áô unit64¸ö - *****************************************************************************/ +* 6¡¢Hisi±£Áô unit128¸ö +* 7¡¢¿Í»§Ê¹ÓÃÔ¤Áô unit64¸ö +*****************************************************************************/ #endif /* __HI_ERRNO_H__ */ diff --git a/project/app/wifi_app/hisi_tools/app/include/hi_stdlib.h b/project/app/wifi_app/hisi_tools/app/include/hi_stdlib.h index 2bea96b80..be0c21913 100644 --- a/project/app/wifi_app/hisi_tools/app/include/hi_stdlib.h +++ b/project/app/wifi_app/hisi_tools/app/include/hi_stdlib.h @@ -1,9 +1,9 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights - * reserved. Description: A parameter is added to the security C APIs based on - * the standard C interface, that is, the upper limit of the write operation - * address space to prevent out-of-bounds write. Author: Hisilicon Create: - * 2018-08-04 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: A parameter is added to the security C APIs based on the standard C interface, that is, the upper + * limit of the write operation address space to prevent out-of-bounds write. + * Author: Hisilicon + * Create: 2018-08-04 */ /** @@ -31,27 +31,22 @@ typedef unsigned int size_t; /** * @ingroup iot_secure_c -* @brief Copies the source string to the destination -buffer.CNcomment:¸´ÖÆÔ´×Ö·û´®µ½Ä¿µÄ»º³åÇø¡£CNend +* @brief Copies the source string to the destination buffer.CNcomment:¸´ÖÆÔ´×Ö·û´®µ½Ä¿µÄ»º³åÇø¡£CNend * * @par ÃèÊö: Copies the source string to the destination buffer. CNcomment:¸´ÖÆÔ´×Ö·û´®µ½Ä¿µÄ»º³åÇø¡£CNend * * @attention None * -* @param dest [OUT] type #char *, Destination -buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend -* @param dest_max [IN] type #size_t, Size of the destination -buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend -* @param src [IN] type #const #char *, Source -buffer.CNcomment:Ô´»º³åÇø¡£CNend +* @param dest [OUT] type #char *, Destination buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend +* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend +* @param src [IN] type #const #char *, Source buffer.CNcomment:Ô´»º³åÇø¡£CNend * * @retval #EOK Success * @retval #Other Failure * * @par ÒÀÀµ: -* @li hi_stdlib.h: This file declares the -APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend +* @li hi_stdlib.h: This file declares the APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend * @see None * @since Hi3861_V100R001C00 */ @@ -59,33 +54,28 @@ extern errno_t strcpy_s(char *dest, size_t dest_max, const char *src); /** * @ingroup iot_secure_c -* @brief Copies the source string of a specified length to the destination -buffer. CNcomment:¸´ÖÆÖ¸¶¨³¤¶ÈÔ´×Ö·û´®µ½Ä¿µÄ»º³åÇø¡£CNend +* @brief Copies the source string of a specified length to the destination buffer. +CNcomment:¸´ÖÆÖ¸¶¨³¤¶ÈÔ´×Ö·û´®µ½Ä¿µÄ»º³åÇø¡£CNend * -* @par ÃèÊö:Copies the source string of a specified length to the destination -buffer. CNcomment:¸´ÖÆÖ¸¶¨³¤¶ÈÔ´×Ö·û´®µ½Ä¿µÄ»º³åÇø¡£CNend +* @par ÃèÊö:Copies the source string of a specified length to the destination buffer. +CNcomment:¸´ÖÆÖ¸¶¨³¤¶ÈÔ´×Ö·û´®µ½Ä¿µÄ»º³åÇø¡£CNend * @attention None * -* @param dest [IN] type #char *, Destination -buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend -* @param dest_max [IN] type #size_t, Size of the destination -buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend -* @param src [IN] type #const #char *, Source -buffer.CNcomment:Ô´»º³åÇø¡£CNend -* @param count [IN] type #size_t, Number of characters copied from the source -buffer. CNcomment:´ÓÔ´»º³åÇøÖи´ÖƵÄ×Ö·ûÊý¡£CNend +* @param dest [IN] type #char *, Destination buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend +* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend +* @param src [IN] type #const #char *, Source buffer.CNcomment:Ô´»º³åÇø¡£CNend +* @param count [IN] type #size_t, Number of characters copied from the source buffer. +CNcomment:´ÓÔ´»º³åÇøÖи´ÖƵÄ×Ö·ûÊý¡£CNend * * @retval #EOK Success * @retval #Other Failure * * @par ÒÀÀµ: -* @li hi_stdlib.h: This file declares the -APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend +* @li hi_stdlib.h: This file declares the APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend * @see None * @since Hi3861_V100R001C00 */ -extern errno_t strncpy_s(char *dest, size_t dest_max, const char *src, - size_t count); +extern errno_t strncpy_s(char *dest, size_t dest_max, const char *src, size_t count); /** * @ingroup iot_secure_c @@ -96,19 +86,15 @@ CNcomment: CNcomment:½«Ô´×Ö·û´®Á¬½Óµ½Ä¿µÄ×Ö·û´®ºóÃæ¡£CNend * @attention None * -* @param dest [IN] type #char *, Destination -buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend -* @param dest_max [IN] type #size_t, Size of the destination -buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend -* @param src [IN] type #const #char *, Source -buffer.CNcomment:Ô´»º³åÇø¡£CNend +* @param dest [IN] type #char *, Destination buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend +* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend +* @param src [IN] type #const #char *, Source buffer.CNcomment:Ô´»º³åÇø¡£CNend * * @retval #EOK Success * @retval #Other Failure * * @par ÒÀÀµ: -* @li hi_stdlib.h: This file declares the -APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend +* @li hi_stdlib.h: This file declares the APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend * @see None * @since Hi3861_V100R001C00 */ @@ -116,34 +102,28 @@ extern errno_t strcat_s(char *dest, size_t dest_max, const char *src); /** * @ingroup iot_secure_c -* @brief Concatenates the source string of a specified length to the end of the -destination string. CNcomment:½«Ö¸¶¨³¤¶ÈµÄÔ´×Ö·û´®Á¬½Óµ½Ä¿µÄ×Ö·û´®ºóÃæ¡£CNend +* @brief Concatenates the source string of a specified length to the end of the destination string. +CNcomment:½«Ö¸¶¨³¤¶ÈµÄÔ´×Ö·û´®Á¬½Óµ½Ä¿µÄ×Ö·û´®ºóÃæ¡£CNend * -* @par ÃèÊö: Concatenates the source string of a specified length to the end of -the destination string. +* @par ÃèÊö: Concatenates the source string of a specified length to the end of the destination string. CNcomment:½«Ö¸¶¨³¤¶ÈµÄÔ´×Ö·û´®Á¬½Óµ½Ä¿µÄ×Ö·û´®ºóÃæ¡£CNend * @attention None * -* @param dest [IN] type #char *, Destination -buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend -* @param dest_max [IN] type #size_t, Size of the destination -buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend -* @param src [IN] type #const #char *, Source -buffer.CNcomment:Ô´»º³åÇø¡£CNend -* @param count [IN] type #size_t, Number of characters copied from the source -buffer. CNcomment:´ÓÔ´»º³åÇøÁ¬½ÓµÄ×Ö·ûÊý¡£CNend +* @param dest [IN] type #char *, Destination buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend +* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend +* @param src [IN] type #const #char *, Source buffer.CNcomment:Ô´»º³åÇø¡£CNend +* @param count [IN] type #size_t, Number of characters copied from the source buffer. +CNcomment:´ÓÔ´»º³åÇøÁ¬½ÓµÄ×Ö·ûÊý¡£CNend * * @retval #EOK Success * @retval #Other Failure * * @par ÒÀÀµ: -* @li hi_stdlib.h: This file declares the -APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend +* @li hi_stdlib.h: This file declares the APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend * @see None * @since Hi3861_V100R001C00 */ -extern errno_t strncat_s(char *dest, size_t dest_max, const char *src, - size_t count); +extern errno_t strncat_s(char *dest, size_t dest_max, const char *src, size_t count); /** * @ingroup iot_secure_c @@ -154,26 +134,21 @@ CNcomment: CNcomment:¸´ÖÆÔ´»º³åÇøµÄÊý¾Ýµ½Ä¿µÄ»º³åÇø¡£CNend * @attention None * -* @param dest [IN] type #char *, Destination -buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend -* @param dest_max [IN] type #size_t, Size of the destination -buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend -* @param src [IN] type #const #char *, Source -buffer.CNcomment:Ô´»º³åÇø¡£CNend -* @param count [IN] type #size_t, Number of characters copied from the source -buffer. CNcomment:´ÓÔ´»º³åÇøÖи´ÖƵÄ×Ö·ûÊý¡£CNend +* @param dest [IN] type #char *, Destination buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend +* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend +* @param src [IN] type #const #char *, Source buffer.CNcomment:Ô´»º³åÇø¡£CNend +* @param count [IN] type #size_t, Number of characters copied from the source buffer. +CNcomment:´ÓÔ´»º³åÇøÖи´ÖƵÄ×Ö·ûÊý¡£CNend * * @retval #EOK Success * @retval #Other Failure * * @par ÒÀÀµ: -* @li hi_stdlib.h: This file declares the -APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend +* @li hi_stdlib.h: This file declares the APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend * @see None * @since Hi3861_V100R001C00 */ -extern errno_t memcpy_s(void *dest, size_t dest_max, const void *src, - size_t count); +extern errno_t memcpy_s(void *dest, size_t dest_max, const void *src, size_t count); /** * @ingroup iot_secure_c @@ -184,21 +159,17 @@ CNcomment: CNcomment:ÉèÖÃÄ¿µÄ»º³åÇøÎªÌØ¶¨Öµ¡£CNend * @attention None * -* @param dest [IN] type #char *, Destination -buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend -* @param dest_max [IN] type #size_t, Size of the destination -buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend -* @param c [IN] type #const #char *, Source -buffer.CNcomment:ÌØ¶¨Öµ¡£CNend -* @param count [IN] type #size_t, Number of characters copied from the source -buffer. CNcomment:ÉèÖÃÎªÌØ¶¨ÖµµÄ×Ö·ûÊý¡£CNend +* @param dest [IN] type #char *, Destination buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend +* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend +* @param c [IN] type #const #char *, Source buffer.CNcomment:ÌØ¶¨Öµ¡£CNend +* @param count [IN] type #size_t, Number of characters copied from the source buffer. +CNcomment:ÉèÖÃÎªÌØ¶¨ÖµµÄ×Ö·ûÊý¡£CNend * * @retval #EOK Success * @retval #Other Failure * * @par ÒÀÀµ: -* @li hi_stdlib.h: This file declares the -APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend +* @li hi_stdlib.h: This file declares the APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend * @see None * @since Hi3861_V100R001C00 */ @@ -213,51 +184,42 @@ CNcomment: CNcomment:ÒÆ¶¯Ô´»º³åÇøµÄÊý¾Ýµ½Ä¿µÄ»º³åÇø¡£CNend * @attention None * -* @param dest [IN] type #char *, Destination -buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend -* @param dest_max [IN] type #size_t, Size of the destination -buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend -* @param src [IN] type #const #char *, Source -buffer.CNcomment:Ô´»º³åÇø¡£CNend -* @param count [IN] type #size_t, Number of characters copied from the source -buffer. CNcomment:´ÓÔ´»º³åÇøÖÐÒÆ¶¯µÄ×Ö·ûÊý¡£CNend +* @param dest [IN] type #char *, Destination buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend +* @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend +* @param src [IN] type #const #char *, Source buffer.CNcomment:Ô´»º³åÇø¡£CNend +* @param count [IN] type #size_t, Number of characters copied from the source buffer. +CNcomment:´ÓÔ´»º³åÇøÖÐÒÆ¶¯µÄ×Ö·ûÊý¡£CNend * * @retval #EOK Success * @retval #Other Failure * * @par ÒÀÀµ: -* @li hi_stdlib.h: This file declares the -APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend +* @li hi_stdlib.h: This file declares the APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend * @see None * @since Hi3861_V100R001C00 */ -extern errno_t memmove_s(void *dest, size_t dest_max, const void *src, - size_t count); +extern errno_t memmove_s(void *dest, size_t dest_max, const void *src, size_t count); /** * @ingroup iot_secure_c * @brief Splits a string into substrings according to the specified separators. CNcomment:½«×Ö·û´®°´ÕÕÖ¸¶¨µÄ·Ö¸ô·û·Ö¸î³É×Ó×Ö·û´®¡£CNend * -* @par ÃèÊö: Splits a string into substrings according to the specified -separators. CNcomment:½«×Ö·û´®°´ÕÕÖ¸¶¨µÄ·Ö¸ô·û·Ö¸î³É×Ó×Ö·û´®¡£CNend +* @par ÃèÊö: Splits a string into substrings according to the specified separators. +CNcomment:½«×Ö·û´®°´ÕÕÖ¸¶¨µÄ·Ö¸ô·û·Ö¸î³É×Ó×Ö·û´®¡£CNend * @attention None * -* @param token [IN] type #char *¡£ String to be -split.CNcomment:Òª·Ö¸îµÄ×Ö·û´®¡£CNend -* @param delimit [IN] type #const char *¡£ String -separator.CNcomment:×Ö·û´®·Ö¸ô·û¡£CNend -* @param context [IN] type #char* ¡£Position information after a call to -HI_strtok_s is saved. CNcomment:±£´æµ÷ÓÃHI_strtok_sºóµÄλÖÃÐÅÏ¢¡£CNend +* @param token [IN] type #char *¡£ String to be split.CNcomment:Òª·Ö¸îµÄ×Ö·û´®¡£CNend +* @param delimit [IN] type #const char *¡£ String separator.CNcomment:×Ö·û´®·Ö¸ô·û¡£CNend +* @param context [IN] type #char* ¡£Position information after a call to HI_strtok_s is saved. +CNcomment:±£´æµ÷ÓÃHI_strtok_sºóµÄλÖÃÐÅÏ¢¡£CNend * -* @retval #char* Point to the next token. -CNcomment:Ö¸ÏòÔÚtokenÖеÄÏÂÒ»¸ötoken¡£CNend +* @retval #char* Point to the next token. CNcomment:Ö¸ÏòÔÚtokenÖеÄÏÂÒ»¸ötoken¡£CNend * @retval #HI_NULL A specified substring is not found or an error occurs. CNcomment:ûÓÐÕÒµ½Ö¸¶¨µÄ×Ó×Ö·û´®»òÕß·¢Éú´íÎó¡£CNend * * @par ÒÀÀµ: -* @li hi_stdlib.h: This file declares the -APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend +* @li hi_stdlib.h: This file declares the APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend * @see None * @since Hi3861_V100R001C00 */ @@ -272,21 +234,17 @@ CNcomment: CNcomment:½«Êý¾Ý¸ñʽ»¯Êä³öµ½Ä¿µÄ»º³åÇø¡£CNend * @attention None * -* @param dest [OUT] type #char *¡£ Destination -buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend -* @param dest_max [IN] type #size_t¡£ Size of the destination -buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend -* @param format [IN] type #const #char *¡£ Formatting control -string.CNcomment:¸ñʽ»¯¿ØÖÆ×Ö·û´®¡£CNend +* @param dest [OUT] type #char *¡£ Destination buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend +* @param dest_max [IN] type #size_t¡£ Size of the destination buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend +* @param format [IN] type #const #char *¡£ Formatting control string.CNcomment:¸ñʽ»¯¿ØÖÆ×Ö·û´®¡£CNend * @param ... [IN] Optional parameter CNcomment:¿ÉÑ¡²ÎÊý¡£CNend * -* @retval #>=0 Return the number of bytes stored in dest, not counting the -terminating null character. CNcomment:·µ»Ø´æ´¢ÔÚdestµÄ×Ö½ÚÊý£¬²»°üÀ¨½áÊø·ûCNend +* @retval #>=0 Return the number of bytes stored in dest, not counting the terminating null character. +CNcomment:·µ»Ø´æ´¢ÔÚdestµÄ×Ö½ÚÊý£¬²»°üÀ¨½áÊø·ûCNend * @retval #-1 Failure * * @par ÒÀÀµ: -* @li hi_stdlib.h: This file declares the -APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend +* @li hi_stdlib.h: This file declares the APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend * @see None * @since Hi3861_V100R001C00 */ @@ -294,38 +252,30 @@ extern int sprintf_s(char *dest, size_t dest_max, const char *format, ...); /** * @ingroup iot_secure_c -* @brief Formats the data according to a specified length and outputs the data -to the destination buffer. +* @brief Formats the data according to a specified length and outputs the data to the destination buffer. CNcomment:½«Êý¾Ý°´ÕÕÖ¸¶¨³¤¶È¸ñʽ»¯Êä³öµ½Ä¿µÄ»º³åÇø¡£CNend * -* @par ÃèÊö: Formats the data according to a specified length and outputs the -data to the destination buffer. +* @par ÃèÊö: Formats the data according to a specified length and outputs the data to the destination buffer. CNcomment:½«Êý¾Ý°´ÕÕÖ¸¶¨³¤¶È¸ñʽ»¯Êä³öµ½Ä¿µÄ»º³åÇø¡£CNend * @attention None * -* @param dest [OUT] type #char *¡£ Destination -buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend -* @param dest_max [IN] type #size_t¡£ Size of the destination -buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend -* @param count [IN] type #size_t¡£ Number of formatted characters to be -output to the destination buffer. +* @param dest [OUT] type #char *¡£ Destination buffer.CNcomment:Ä¿µÄ»º³åÇø¡£CNend +* @param dest_max [IN] type #size_t¡£ Size of the destination buffer.CNcomment:Ä¿µÄ»º³åÇø´óС¡£CNend +* @param count [IN] type #size_t¡£ Number of formatted characters to be output to the destination buffer. CNcomment:ÒªÊä³öµ½Ä¿µÄ»º³åÇøµÄ¸ñʽ»¯×Ö·û¸öÊý¡£CNend -* @param format [IN] type #const #char *¡£ Formatting control -string.CNcomment:¸ñʽ»¯¿ØÖÆ×Ö·û´®¡£CNend +* @param format [IN] type #const #char *¡£ Formatting control string.CNcomment:¸ñʽ»¯¿ØÖÆ×Ö·û´®¡£CNend * @param ... [IN] Optional parameter CNcomment:¿ÉÑ¡²ÎÊý¡£CNend * -* @retval #>=0 Return the number of bytes stored in dest, not counting the -terminating null character. CNcomment:·µ»Ø´æ´¢ÔÚdestµÄ×Ö½ÚÊý£¬²»°üÀ¨½áÊø·ûCNend +* @retval #>=0 Return the number of bytes stored in dest, not counting the terminating null character. +CNcomment:·µ»Ø´æ´¢ÔÚdestµÄ×Ö½ÚÊý£¬²»°üÀ¨½áÊø·ûCNend * @retval #-1 Failure * * @par ÒÀÀµ: -* @li hi_stdlib.h: This file declares the -APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend +* @li hi_stdlib.h: This file declares the APIs.CNcomment:¸Ã½Ó¿ÚÉùÃ÷ËùÔÚµÄÍ·Îļþ¡£CNend * @see None * @since Hi3861_V100R001C00 */ -extern int snprintf_s(char *dest, size_t dest_max, size_t count, - const char *format, ...); +extern int snprintf_s(char *dest, size_t dest_max, size_t count, const char *format, ...); /* * C¿â½Ó¿Ú @@ -347,3 +297,4 @@ extern UT_CONST char *strchr(const char *s, int c); HI_END_HEADER #endif /* __HI_STDLIB_H__ */ + diff --git a/project/app/wifi_app/hisi_tools/app/include/hi_types.h b/project/app/wifi_app/hisi_tools/app/include/hi_types.h index e8262a770..d05f8e5f3 100644 --- a/project/app/wifi_app/hisi_tools/app/include/hi_types.h +++ b/project/app/wifi_app/hisi_tools/app/include/hi_types.h @@ -1,31 +1,36 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights - * reserved. Description: file hi_types.h. Author: HiSilicon Create: 2019-4-3 - */ +* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights reserved. +* Description: file hi_types.h. +* Author: HiSilicon +* Create: 2019-4-3 +*/ /** - * @file hi_types.h - * - * Copyright (c) Hisilicon Technologies Co., Ltd. 2018. All rights reserved. \n - * - * Êý¾ÝÀàÐÍ˵Ã÷ - */ +* @file hi_types.h +* +* Copyright (c) Hisilicon Technologies Co., Ltd. 2018. All rights reserved. \n +* +* Êý¾ÝÀàÐÍ˵Ã÷ +*/ #ifndef __HI_TYPES_H__ #define __HI_TYPES_H__ -#include #include +#include + /* linux´íÎóÂë */ -#define OAL_SUCC 0 -#define OAL_EFAIL 1 /* ÄÚºËͨÓôíÎó·µ»ØÖµ -1 */ -#define OAL_EIO 5 /* I/O error */ -#define OAL_ENOMEM 12 /* Out of memory */ -#define OAL_EFAUL 14 /* Bad address */ -#define OAL_EBUSY 16 /* Device or resource busy */ -#define OAL_ENODEV 19 /* No such device */ -#define OAL_EINVAL 22 /* Invalid argument */ +#define OAL_SUCC 0 +#define OAL_EFAIL 1 /* ÄÚºËͨÓôíÎó·µ»ØÖµ -1 */ +#define OAL_EIO 5 /* I/O error */ +#define OAL_ENOMEM 12 /* Out of memory */ +#define OAL_EFAUL 14 /* Bad address */ +#define OAL_EBUSY 16 /* Device or resource busy */ +#define OAL_ENODEV 19 /* No such device */ +#define OAL_EINVAL 22 /* Invalid argument */ #define oal_reference(data) ((void)(data)) + #endif // __HI_TYPES_H__ + diff --git a/project/app/wifi_app/hisi_tools/app/include/hi_types_base.h b/project/app/wifi_app/hisi_tools/app/include/hi_types_base.h index dff21c21c..8dee14c08 100644 --- a/project/app/wifi_app/hisi_tools/app/include/hi_types_base.h +++ b/project/app/wifi_app/hisi_tools/app/include/hi_types_base.h @@ -1,6 +1,7 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights - * reserved. Description: Êý¾ÝÀàÐͶ¨ÒåºÍ¹«ÓúêºÍ½á¹¹¶¨Òå Author: Hisilicon + * Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights reserved. + * Description: Êý¾ÝÀàÐͶ¨ÒåºÍ¹«ÓúêºÍ½á¹¹¶¨Òå + * Author: Hisilicon * Create: 2019-06-02 */ @@ -21,8 +22,7 @@ #endif #if !defined(HI_HAVE_CROSS_COMPILER_DIAB_AS) -#if defined(HI_HAVE_CROSS_COMPILER_ARM_GCC) || \ - defined(HI_HAVE_CROSS_COMPILER_ARM_ARMCC) || \ +#if defined(HI_HAVE_CROSS_COMPILER_ARM_GCC) || defined(HI_HAVE_CROSS_COMPILER_ARM_ARMCC) || \ defined(HI_HAVE_CROSS_COMPILER_DIAB) #undef HI_HAVE_CROSS_COMPILER #define HI_HAVE_CROSS_COMPILER @@ -33,89 +33,85 @@ #endif #ifdef PRODUCT_CFG_OS_WIN -#undef SAL_HAVE_OS_WIN_VER -#undef SAL_HAVE_OS_NU_VER -#undef SAL_HAVE_OS_VX_VER +# undef SAL_HAVE_OS_WIN_VER +# undef SAL_HAVE_OS_NU_VER +# undef SAL_HAVE_OS_VX_VER #define SAL_HAVE_OS_WIN_VER #endif -#if defined(PRODUCT_CFG_OS_LOS) -#undef SAL_HAVE_OS_VX_VER -#define SAL_HAVE_OS_VX_VER +#if defined (PRODUCT_CFG_OS_LOS) +# undef SAL_HAVE_OS_VX_VER +# define SAL_HAVE_OS_VX_VER #else -#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1200) -#pragma once -#ifndef SAL_HAVE_SIMU_WIN_VER -#define SAL_HAVE_SIMU_WIN_VER -#ifdef _USRDLL -#if !defined(PRODUCT_CFG_MSVC_HIDE_AUTOLINK_OUTPUT_INFO) -#pragma message("Windows VC Simulator DLL Version ") -#endif -#endif -#ifdef _LIB -#if !defined(PRODUCT_CFG_MSVC_HIDE_AUTOLINK_OUTPUT_INFO) -#pragma message("Windows VC Simulator lib Version ") -#endif -#endif -#ifdef _CONSOLE -#if !defined(PRODUCT_CFG_MSVC_HIDE_AUTOLINK_OUTPUT_INFO) -#pragma message("Windows VC Simulator console Version ") -#endif -#endif -#else -#if !defined(PRODUCT_CFG_MSVC_HIDE_AUTOLINK_OUTPUT_INFO) -#pragma message("Windows Version") -#endif -#endif -#endif +# if defined (_WIN32) && defined (_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +# ifndef SAL_HAVE_SIMU_WIN_VER +# define SAL_HAVE_SIMU_WIN_VER +# ifdef _USRDLL +# if !defined(PRODUCT_CFG_MSVC_HIDE_AUTOLINK_OUTPUT_INFO) +# pragma message("Windows VC Simulator DLL Version ") +# endif +# endif +# ifdef _LIB +# if !defined(PRODUCT_CFG_MSVC_HIDE_AUTOLINK_OUTPUT_INFO) +# pragma message("Windows VC Simulator lib Version ") +# endif +# endif +# ifdef _CONSOLE +# if !defined(PRODUCT_CFG_MSVC_HIDE_AUTOLINK_OUTPUT_INFO) +# pragma message("Windows VC Simulator console Version ") +# endif +# endif +# else +# if !defined(PRODUCT_CFG_MSVC_HIDE_AUTOLINK_OUTPUT_INFO) +# pragma message("Windows Version") +# endif +# endif +# endif #endif #undef HI_SYS_DEBUG -#if (defined(PRODUCT_CFG_VERSION_DEBUG) || defined(SAL_HAVE_DEBUG_VERSION)) && \ - !defined(SAL_HAVE_RELEASE_VERSION) -#define HI_SYS_DEBUG +#if (defined(PRODUCT_CFG_VERSION_DEBUG) || defined(SAL_HAVE_DEBUG_VERSION)) && !defined(SAL_HAVE_RELEASE_VERSION) +# define HI_SYS_DEBUG #endif #if defined(PRODUCT_CFG_OS_WIN) -#pragma warning(disable : 4200) /* disable nonstandard extension used : \ - zero-sized array in struct/union. */ -#pragma warning(disable : 4214) /* allows bitfield structure members to be of \ - any integral type. */ -#pragma warning(disable : 4201) -#pragma warning(disable : 4514) -#pragma warning(disable : 4127) +#pragma warning(disable:4200) /* disable nonstandard extension used : zero-sized array in struct/union. */ +#pragma warning(disable:4214) /* allows bitfield structure members to be of any integral type. */ +#pragma warning(disable:4201) +#pragma warning(disable:4514) +#pragma warning(disable:4127) #endif /* »ù±¾Êý¾ÝÀàÐͶ¨Òå */ -typedef unsigned int hi_u32; -typedef int hi_s32; -typedef unsigned short hi_u16; -typedef signed short hi_s16; -typedef unsigned char hi_u8; -typedef signed char hi_s8; -typedef void hi_void; -typedef char hi_char; -typedef unsigned char hi_uchar; -typedef hi_u8 hi_bool; -typedef void *hi_pvoid; -typedef hi_u8 hi_byte; -typedef hi_pvoid hi_handle; -typedef hi_byte *hi_pbyte; -typedef float hi_float; -typedef double hi_double; -typedef volatile hi_u32 hi_u32_reg; -typedef hi_pvoid hi_func_ptr; -typedef hi_u32 hi_func; -typedef unsigned int hi_size_t; -typedef int hi_ssize_t; -typedef int hi_offset_t; +typedef unsigned int hi_u32; +typedef int hi_s32; +typedef unsigned short hi_u16; +typedef signed short hi_s16; +typedef unsigned char hi_u8; +typedef signed char hi_s8; +typedef void hi_void; +typedef char hi_char; +typedef unsigned char hi_uchar; +typedef hi_u8 hi_bool; +typedef void* hi_pvoid; +typedef hi_u8 hi_byte; +typedef hi_pvoid hi_handle; +typedef hi_byte* hi_pbyte; +typedef float hi_float; +typedef double hi_double; +typedef volatile hi_u32 hi_u32_reg; +typedef hi_pvoid hi_func_ptr; +typedef hi_u32 hi_func; +typedef unsigned int hi_size_t; +typedef int hi_ssize_t; +typedef int hi_offset_t; -/* for 64bits platform, intptr_t/uintptr_t should be defined as 64bits length. - */ -typedef int intptr_t; +/* for 64bits platform, intptr_t/uintptr_t should be defined as 64bits length. */ +typedef int intptr_t; #if defined(__LITEOS__) -typedef unsigned int uintptr_t; +typedef unsigned int uintptr_t; #endif #undef ERROR @@ -127,152 +123,151 @@ typedef unsigned int uintptr_t; #define NULL 0 #endif -#define HI_CONST const -#define HI_REG register +#define HI_CONST const +#define HI_REG register -#define HI_U32_MAX 0xFFFFFFFF -#define HI_U64_MAX 0xFFFFFFFFFFFFFFFFUL -#define HI_U16_MAX 0xFFFF +#define HI_U32_MAX 0xFFFFFFFF +#define HI_U64_MAX 0xFFFFFFFFFFFFFFFFUL +#define HI_U16_MAX 0xFFFF typedef hi_pvoid (*hi_pvoid_callback_f)(hi_void); -typedef hi_void (*hi_void_callback_f)(hi_void); -typedef hi_void (*hi_void_callback)(hi_void); -typedef hi_bool (*hi_bool_callback_f)(hi_void); -typedef hi_void (*hi_void_u32_callback_f)(hi_u32); -typedef hi_u32 (*hi_u32_pvoid_callback_f)(hi_pvoid); -typedef hi_u32 (*hi_u32_void_callback)(hi_void); /* ÖܱߴúÂë´ýˢР*/ -typedef hi_u32 (*hi_u32_u32_pvoid_callback_f)(hi_pvoid, hi_u32); -typedef hi_s32 (*funcptr)(hi_void); /* ptr to function returning int */ -typedef hi_void (*voidfuncptr)(hi_void); /* ptr to function returning void */ +typedef hi_void (*hi_void_callback_f)(hi_void); +typedef hi_void (*hi_void_callback)(hi_void); +typedef hi_bool (*hi_bool_callback_f)(hi_void); +typedef hi_void (*hi_void_u32_callback_f)(hi_u32); +typedef hi_u32 (*hi_u32_pvoid_callback_f)(hi_pvoid); +typedef hi_u32 (*hi_u32_void_callback)(hi_void); /* ÖܱߴúÂë´ýˢР*/ +typedef hi_u32 (*hi_u32_u32_pvoid_callback_f)(hi_pvoid, hi_u32); +typedef hi_s32 (*funcptr)(hi_void); /* ptr to function returning int */ +typedef hi_void (*voidfuncptr)(hi_void); /* ptr to function returning void */ -typedef HI_CONST hi_char *hi_pcstr; +typedef HI_CONST hi_char* hi_pcstr; #ifdef PRODUCT_CFG_OS_WIN -typedef unsigned __int64 hi_u64; +typedef unsigned __int64 hi_u64; typedef __int64 hi_s64; #elif defined(HI_HAVE_CROSS_COMPILER_ARM_ARMCC) -typedef unsigned __int64 hi_u64; +typedef unsigned __int64 hi_u64; typedef __int64 hi_s64; #elif defined(HI_HAVE_CROSS_COMPILER_ARM_GCC) || defined(HAVE_PCLINT_CHECK) -typedef unsigned long long hi_u64; -typedef long long hi_s64; +typedef unsigned long long hi_u64; +typedef long long hi_s64; #elif defined(HI_HAVE_CROSS_COMPILER_DIAB) -typedef unsigned long long hi_u64; -typedef long long hi_s64; +typedef unsigned long long hi_u64; +typedef long long hi_s64; #elif !defined(PRODUCT_CFG_HSO) /* #error "unknown compiler" */ -typedef unsigned __int64 hi_u64; +typedef unsigned __int64 hi_u64; typedef __int64 hi_s64; #endif -#define HI_S32_BITS 32 -#define HI_S32_MAX (~(~0 << (HI_S32_BITS - 1))) +#define HI_S32_BITS 32 +#define HI_S32_MAX (~(~0 << (HI_S32_BITS - 1))) -#define HI_PUBLIC extern +#define HI_PUBLIC extern #if !defined(PRODUCT_CFG_FEATURE_UT) -#define HI_PRV static +# define HI_PRV static #else -#define HI_PRV +# define HI_PRV #endif -#define STATIC static +# define STATIC static #endif /* HI_HAVE_CROSS_COMPILER_DIAB_AS */ #ifdef PRODUCT_CFG_OS_WIN -#define HI_API _declspec(dllexport) -#define HI_INLINE __inline +# define HI_API _declspec(dllexport) +# define HI_INLINE __inline #elif defined(HI_HAVE_CROSS_COMPILER_ARM_GCC) -#define HI_INLINE inline -#define HI_API +# define HI_INLINE inline +# define HI_API #elif defined(HI_HAVE_CROSS_COMPILER_ARM_ARMCC) -#define HI_INLINE inline -#define HI_API +# define HI_INLINE inline +# define HI_API #elif defined(HI_HAVE_CROSS_COMPILER_DIAB) -#define HI_INLINE __inline__ -#define HI_API -#else -#define HI_INLINE __inline -#define HI_API +# define HI_INLINE __inline__ +# define HI_API +# else +# define HI_INLINE __inline +# define HI_API #endif #define HI_PRVL HI_PRV HI_INLINE #if defined(__ONEBUILDER__CROSS_COMPILER_PRODUCT_CONFIG__) -#if defined(HI_HAVE_CROSS_COMPILER_ARM_ARMCC) || \ - defined(HI_HAVE_CROSS_COMPILER_ARM_GCC) -#define hi_section(name_string) __attribute__((section(name_string))) -#define HI_PACKED __attribute__((packed)) -#define HI_ALIGNED4 __attribute__((aligned(4))) +#if defined(HI_HAVE_CROSS_COMPILER_ARM_ARMCC) || defined(HI_HAVE_CROSS_COMPILER_ARM_GCC) +# define hi_section(name_string) __attribute__ ((section(name_string))) +# define HI_PACKED __attribute__((packed)) +# define HI_ALIGNED4 __attribute__ ((aligned (4))) #elif defined(HI_HAVE_CROSS_COMPILER_DIAB) -#define hi_section(name_string) __attribute__((section(name_string))) -#define HI_PACKED __attribute__((packed)) -#define HI_ALIGNED4 __attribute__((aligned(4))) +# define hi_section(name_string) __attribute__ ((section(name_string))) +# define HI_PACKED __attribute__((packed)) +# define HI_ALIGNED4 __attribute__ ((aligned (4))) #endif #elif defined(SAL_HAVE_OS_WIN_VER) || defined(PRODUCT_CFG_HSO) -#define hi_section(name_string) -#define HI_PACKED -#define HI_ALIGNED4 +# define hi_section(name_string) +# define HI_PACKED +# define HI_ALIGNED4 #else -#define hi_section(name_string) -#define HI_PACKED -#define HI_ALIGNED4 +# define hi_section(name_string) +# define HI_PACKED +# define HI_ALIGNED4 #endif #if defined(SAL_HAVE_OS_WIN_VER) -#if defined(_DEBUG) || defined(PRODUCT_CFG_VERSION_DEBUG) -#define hi_dll_lib_name(x) x##"_debug.dll" -#else -#define hi_dll_lib_name(x) x##"_release.dll" -#endif +# if defined(_DEBUG) || defined(PRODUCT_CFG_VERSION_DEBUG) +# define hi_dll_lib_name(x) x ## "_debug.dll" +# else +# define hi_dll_lib_name(x) x ## "_release.dll" +# endif #else #if defined(HI_HAVE_CROSS_COMPILER_ARM_GCC) -#define hi_dll_lib_name(x) x +# define hi_dll_lib_name(x) x #else -#define hi_dll_lib_name(x) x##".lib" +# define hi_dll_lib_name(x) x ## ".lib" #endif #endif #if defined(SAL_HAVE_NO_EXTERN_DEFINED) -#define HI_EXTERN -#define HI_EXTERN_C +# define HI_EXTERN +# define HI_EXTERN_C #else -#if defined(PRODUCT_CFG_OS_WIN) -#define HI_EXTERN extern HI_API -#define HI_EXTERN_C HI_EXTERN -#define HI_EAPI extern HI_API -#else -#define HI_EXTERN extern -#define HI_EAPI -#define HI_EXTERN_C -#endif +# if defined(PRODUCT_CFG_OS_WIN) +# define HI_EXTERN extern HI_API +# define HI_EXTERN_C HI_EXTERN +# define HI_EAPI extern HI_API +# else +# define HI_EXTERN extern +# define HI_EAPI +# define HI_EXTERN_C +# endif #endif #ifdef __cplusplus -#define HI_CPP_START extern "C" { -#define HI_CPP_END } +# define HI_CPP_START extern "C" { +# define HI_CPP_END } #else -#define HI_CPP_START -#define HI_CPP_END +# define HI_CPP_START +# define HI_CPP_END #endif #if defined(HI_HAVE_CROSS_COMPILER_ARM_ARMCC) -#define HI_NOP __asm { nop } -#define hi_dbg_break() __asm { swi 0x14DEAD } +#define HI_NOP __asm { nop } +#define hi_dbg_break() __asm { swi 0x14DEAD } #elif defined(HI_HAVE_CROSS_COMPILER_DIAB) #define HI_NOP #define hi_dbg_break() #else #define HI_NOP #ifdef PRODUCT_CFG_OS_WIN -#define hi_dbg_break() _asm { int 3 } +#define hi_dbg_break() _asm { int 3 } #else #define hi_dbg_break() #endif #endif -#define HI_START_HEADER HI_CPP_START -#define HI_END_HEADER HI_CPP_END +#define HI_START_HEADER HI_CPP_START +#define HI_END_HEADER HI_CPP_END #undef HI_OUT #undef HI_IN @@ -281,275 +276,239 @@ typedef __int64 hi_s64; #define HI_IN #define HI_INOUT -#define HI_FALSE 0 -#define HI_TRUE 1 -#define HI_SWITCH_OFF 0 -#define HI_SWITCH_ON 1 +#define HI_FALSE 0 +#define HI_TRUE 1 +#define HI_SWITCH_OFF 0 +#define HI_SWITCH_ON 1 #ifdef __cplusplus -#define HI_NULL 0 +#define HI_NULL 0 #else -#define HI_NULL ((void *)0) +#define HI_NULL ((void *)0) #endif -#define hi_array_count(x) (sizeof(x) / sizeof((x)[0])) + +#define hi_array_count(x) (sizeof(x) / sizeof((x)[0])) #if !defined(hi_unref_param) && !defined(HI_HAVE_CROSS_COMPILER_DIAB) -#define hi_unref_param(P) ((P) = (P)) +#define hi_unref_param(P) ((P) = (P)) #else #define hi_unref_param(P) #endif #if defined(PRODUCT_CFG_PLATFORM_HI3921) #if defined(HI_HAVE_CROSS_COMPILER_ARM_ARMCC) -#define HI_VOLATILE volatile -#define hi_sys_get_lr() __return_address() +#define HI_VOLATILE volatile +#define hi_sys_get_lr() __return_address() #elif defined(HAVE_PCLINT_CHECK) #define HI_VOLATILE -#define hi_sys_get_lr() 0 +#define hi_sys_get_lr() 0 #elif defined(HI_HAVE_CROSS_COMPILER_DIAB) -#define HI_VOLATILE volatile -#define hi_sys_get_lr() 0 +#define HI_VOLATILE volatile +#define hi_sys_get_lr() 0 #else -#define HI_VOLATILE __volatile__ -#define hi_sys_get_lr() 0 +#define HI_VOLATILE __volatile__ +#define hi_sys_get_lr() 0 #endif #else #define HI_VOLATILE -#define hi_sys_get_lr() 0 +#define hi_sys_get_lr() 0 #endif -#define hi_aligin_u32_size(x) (((x) & (~3)) + 4) /* ¹¹Ôì4¸ö×Ö½Ú¶ÔÆë */ -#define hi_is_align_u32(x) (!((x)&3)) /* ÅжÏÊÇ·ñΪ4×Ö½Ú¶ÔÆë */ -#define hi_is_unalign_u32(x) ((x)&3) /* ÅжÏÊÇ·ñΪ4×Ö½Ú¶ÔÆë */ +#define hi_aligin_u32_size(x) (((x) & (~3)) + 4) /* ¹¹Ôì4¸ö×Ö½Ú¶ÔÆë */ +#define hi_is_align_u32(x) (!((x) & 3)) /* ÅжÏÊÇ·ñΪ4×Ö½Ú¶ÔÆë */ +#define hi_is_unalign_u32(x) ((x) & 3) /* ÅжÏÊÇ·ñΪ4×Ö½Ú¶ÔÆë */ #if defined(HAVE_PCLINT_CHECK) -#define hi_fieldoffset(s, m) (0) +#define hi_fieldoffset(s, m) (0) #else -#define hi_fieldoffset(s, m) ((hi_u32) & (((s *)0)->m)) /* ½á¹¹³ÉÔ±Æ«ÒÆ */ +#define hi_fieldoffset(s, m) ((hi_u32)&(((s *)0)->m)) /* ½á¹¹³ÉÔ±Æ«ÒÆ */ #endif -#define HI_CHAR_CR '\r' /* 0x0D */ -#define HI_CHAR_LF '\n' /* 0x0A */ -#define hi_tolower(x) \ - ((x) | 0x20) /* Works only for digits and letters, but small and fast */ +#define HI_CHAR_CR '\r' /* 0x0D */ +#define HI_CHAR_LF '\n' /* 0x0A */ +#define hi_tolower(x) ((x) | 0x20) /* Works only for digits and letters, but small and fast */ -#define hi_array_size(_array) (sizeof(_array) / sizeof((_array)[0])) -#define hi_makeu16(a, b) ((hi_u16)(((hi_u8)(a)) | ((hi_u16)((hi_u8)(b))) << 8)) -#define hi_makeu32(a, b) \ - ((hi_u32)(((hi_u16)(a)) | ((hi_u32)((hi_u16)(b))) << 16)) -#define hi_makeu64(a, b) \ - ((hi_u64)(((hi_u32)(a)) | ((hi_u64)((hi_u32)(b))) << 32)) -#define hi_joinu32(a, b, c, d) \ - ((a) | ((hi_u32)(b) << 8) | ((hi_u32)(c) << 16) | ((hi_u32)(d) << 24)) +#define hi_array_size(_array) (sizeof(_array) / sizeof((_array)[0])) +#define hi_makeu16(a, b) ((hi_u16)(((hi_u8)(a)) | ((hi_u16)((hi_u8)(b))) << 8)) +#define hi_makeu32(a, b) ((hi_u32)(((hi_u16)(a)) | ((hi_u32)((hi_u16)(b))) << 16)) +#define hi_makeu64(a, b) ((hi_u64)(((hi_u32)(a)) | ((hi_u64)((hi_u32)(b))) <<32)) +#define hi_joinu32(a, b, c, d) ((a) | ((hi_u32)(b) << 8) | ((hi_u32)(c) << 16) | ((hi_u32)(d) << 24)) -#define hi_hiu32(l) ((hi_u32)(((hi_u64)(l) >> 32) & 0xFFFFFFFF)) -#define hi_lou32(l) ((hi_u32)(l)) +#define hi_hiu32(l) ((hi_u32)(((hi_u64)(l) >> 32) & 0xFFFFFFFF)) +#define hi_lou32(l) ((hi_u32)(l)) -#define hi_hiu16(l) ((hi_u16)(((hi_u32)(l) >> 16) & 0xFFFF)) -#define hi_lou16(l) ((hi_u16)(l)) -#define hi_hiu8(l) ((hi_u8)(((hi_u16)(l) >> 8) & 0xFF)) -#define hi_lou8(l) ((hi_u8)(l)) +#define hi_hiu16(l) ((hi_u16)(((hi_u32)(l) >> 16) & 0xFFFF)) +#define hi_lou16(l) ((hi_u16)(l)) +#define hi_hiu8(l) ((hi_u8)(((hi_u16)(l) >> 8) & 0xFF)) +#define hi_lou8(l) ((hi_u8)(l)) -#define hi_max(a, b) (((a) > (b)) ? (a) : (b)) -#define hi_min(a, b) (((a) < (b)) ? (a) : (b)) -#define hi_sub(a, b) (((a) > (b)) ? ((a) - (b)) : 0) -#define hi_abs_sub(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) -#define hi_byte_align(value, align) (((value) + (align)-1) & (~((align)-1))) -#define hi_is_byte_align(value, align) (((hi_u32)(value) & ((align)-1)) == 0) -#define hi_inc_wraparound(value, round_size) \ - ++(value); \ - (value) &= ((round_size)-1) -#define hi_dec_wraparound(value, round_size) \ - --(value); \ - (value) &= ((round_size)-1) +#define hi_max(a, b) (((a) > (b)) ? (a) : (b)) +#define hi_min(a, b) (((a) < (b)) ? (a) : (b)) +#define hi_sub(a, b) (((a) > (b)) ? ((a) - (b)) : 0) +#define hi_abs_sub(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) +#define hi_byte_align(value, align) (((value) + (align) - 1) & (~((align) -1))) +#define hi_is_byte_align(value, align) (((hi_u32)(value) & ((align) - 1))== 0) +#define hi_inc_wraparound(value, round_size) ++(value); (value) &= ((round_size) - 1) +#define hi_dec_wraparound(value, round_size) --(value); (value) &= ((round_size) - 1) -#define hi_swap_byteorder_16(value) \ - ((((value)&0xFF) << 8) + (((value)&0xFF00) >> 8)) +#define hi_swap_byteorder_16(value) ((((value) & 0xFF) << 8) + (((value) & 0xFF00) >> 8)) -#define hi_swap_byteorder_32(value) \ - ((hi_u32)(((value)&0x000000FF) << 24) + \ - (hi_u32)(((value)&0x0000FF00) << 8) + (hi_u32)(((value)&0x00FF0000) >> 8) + \ - (hi_u32)(((value)&0xFF000000) >> 24)) +#define hi_swap_byteorder_32(value) \ + ((hi_u32)(((value) & 0x000000FF) << 24) + \ + (hi_u32)(((value) & 0x0000FF00) << 8) + \ + (hi_u32)(((value) & 0x00FF0000) >> 8) + \ + (hi_u32)(((value) & 0xFF000000) >> 24)) -#define hi_swap_byteorder_64(value) \ - ((((value)&0x00000000000000ffULL) << 56) + \ - (((value)&0x000000000000ff00ULL) << 40) + \ - (((value)&0x0000000000ff0000ULL) << 24) + \ - (((value)&0x00000000ff000000ULL) << 8) + \ - (((value)&0x000000ff00000000ULL) >> 8) + \ - (((value)&0x0000ff0000000000ULL) >> 24) + \ - (((value)&0x00ff000000000000ULL) >> 40) + \ - (((value)&0xff00000000000000ULL) >> 56)) +#define hi_swap_byteorder_64(value) \ + ((((value) & 0x00000000000000ffULL) << 56) + \ + (((value) & 0x000000000000ff00ULL) << 40) + \ + (((value) & 0x0000000000ff0000ULL) << 24) + \ + (((value) & 0x00000000ff000000ULL) << 8) + \ + (((value) & 0x000000ff00000000ULL) >> 8) + \ + (((value) & 0x0000ff0000000000ULL) >> 24) + \ + (((value) & 0x00ff000000000000ULL) >> 40) + \ + (((value) & 0xff00000000000000ULL) >> 56)) #undef MIN_T -#define MIN_T hi_min +#define MIN_T hi_min -#define hi_make_identifier(a, b, c, d) \ - hi_makeu32(hi_makeu16(a, b), hi_makeu16(c, d)) -#define hi_make_ver16(spc, b) \ - ((hi_u16)(((hi_u8)((spc)&0x0F)) | ((hi_u16)((hi_u8)(b))) << 12)) +#define hi_make_identifier(a, b, c, d) hi_makeu32(hi_makeu16(a, b), hi_makeu16(c, d)) +#define hi_make_ver16(spc, b) ((hi_u16)(((hi_u8)((spc)&0x0F)) | ((hi_u16)((hi_u8)(b))) << 12)) -#define hi_set_bit_i(val, n) ((val) |= (1 << (n))) -#define hi_clr_bit_i(val, n) ((val) &= ~(1 << (n))) -#define hi_is_bit_set_i(val, n) ((val) & (1 << (n))) -#define hi_is_bit_clr_i(val, n) (~((val) & (1 << (n)))) -#define hi_switch_bit_i(val, n) ((val) ^= (1 << (n))) -#define hi_get_bit_i(val, n) (((val) >> (n)) & 1) -#define hi_reg_clr_bit_i(reg, n) \ - ((*(volatile unsigned int *)(reg)) &= ~(1 << (n))) +#define hi_set_bit_i(val, n) ((val) |= (1 << (n))) +#define hi_clr_bit_i(val, n) ((val) &= ~(1 << (n))) +#define hi_is_bit_set_i(val, n) ((val) & (1 << (n))) +#define hi_is_bit_clr_i(val, n) (~((val) & (1 << (n)))) +#define hi_switch_bit_i(val, n) ((val) ^= (1 << (n))) +#define hi_get_bit_i(val, n) (((val) >> (n)) & 1) +#define hi_reg_clr_bit_i(reg, n) ((*(volatile unsigned int *)(reg)) &= ~(1 << (n))) -#define hi_u8_bit_val(b7, b6, b5, b4, b3, b2, b1, b0) \ - (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) | ((b3) << 3) | \ - ((b2) << 2) | ((b1) << 1) | ((b0) << 0)) -#define hi_u16_bit_val(b12, b11, b10, b9, b8, b7, b6, b5, b4, b3, b2, b1, b0) \ - (hi_u16)(((b12) << 12) | ((b11) << 11) | ((b10) << 10) | ((b9) << 9) | \ - ((b8) << 8) | ((b7) << 7) | ((b6) << 6) | ((b5) << 5) | \ - ((b4) << 4) | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | \ - ((b0) << 0)) +#define hi_u8_bit_val(b7, b6, b5, b4, b3, b2, b1, b0) \ + (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | ((b0) << 0)) +#define hi_u16_bit_val(b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,b2,b1,b0) \ + (hi_u16)(((b12) << 12) | ((b11) << 11) | ((b10) << 10) | ((b9) << 9) | ((b8) << 8) | ((b7) << 7) | \ + ((b6) << 6) | ((b5) << 5) | ((b4) << 4) | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | ((b0) << 0)) #if defined(__ONEBUILDER__CROSS_COMPILER_PRODUCT_CONFIG__) -#define HSO_ENUM HI_ALIGNED4 enum -#define HI_U8A HI_ALIGNED4 hi_u8 -#define HI_U16A HI_ALIGNED4 hi_u16 -#define HI_CHARTA HI_ALIGNED4 hi_char +#define HSO_ENUM HI_ALIGNED4 enum +#define HI_U8A HI_ALIGNED4 hi_u8 +#define HI_U16A HI_ALIGNED4 hi_u16 +#define HI_CHARTA HI_ALIGNED4 hi_char #else -#define HSO_ENUM enum -#define HI_U8A hi_u8 -#define HI_U16A hi_u16 -#define HI_CHARTA hi_char +#define HSO_ENUM enum +#define HI_U8A hi_u8 +#define HI_U16A hi_u16 +#define HI_CHARTA hi_char #endif #if defined(PRODUCT_CFG_HSO) && defined(HI_HAVE_NOTIVE_COMPILER_VC) -#define __FUNCTION__ "NA" +#define __FUNCTION__ "NA" #endif /*****************************************************************************/ -#define hi_set_u32_ptr_val(ptr, offset, val) \ - (*((hi_u32 *)(((hi_u8 *)(ptr)) + (offset))) = (val)) -#define hi_get_u32_ptr_val(ptr, offset) \ - *((hi_u32 *)(((hi_u8 *)(ptr)) + (offset))) +#define hi_set_u32_ptr_val(ptr, offset, val) (*((hi_u32*)(((hi_u8*)(ptr)) + (offset))) = (val)) +#define hi_get_u32_ptr_val(ptr, offset) *((hi_u32*)(((hi_u8*)(ptr)) + (offset))) /*****************************************************************************/ /*****************************************************************************/ -#define HI_SIZE_1K 1024 -#define HI_SIZE_1M (1024 * 1024) +#define HI_SIZE_1K 1024 +#define HI_SIZE_1M (1024 * 1024) /*****************************************************************************/ #ifndef bit -#define bit(x) (1UL << (x)) +#define bit(x) (1UL << (x)) #endif -#define BIT31 ((hi_u32)(1UL << 31)) -#define BIT30 ((hi_u32)(1 << 30)) -#define BIT29 ((hi_u32)(1 << 29)) -#define BIT28 ((hi_u32)(1 << 28)) -#define BIT27 ((hi_u32)(1 << 27)) -#define BIT26 ((hi_u32)(1 << 26)) -#define BIT25 ((hi_u32)(1 << 25)) -#define BIT24 ((hi_u32)(1 << 24)) -#define BIT23 ((hi_u32)(1 << 23)) -#define BIT22 ((hi_u32)(1 << 22)) -#define BIT21 ((hi_u32)(1 << 21)) -#define BIT20 ((hi_u32)(1 << 20)) -#define BIT19 ((hi_u32)(1 << 19)) -#define BIT18 ((hi_u32)(1 << 18)) -#define BIT17 ((hi_u32)(1 << 17)) -#define BIT16 ((hi_u32)(1 << 16)) -#define BIT15 ((hi_u32)(1 << 15)) -#define BIT14 ((hi_u32)(1 << 14)) -#define BIT13 ((hi_u32)(1 << 13)) -#define BIT12 ((hi_u32)(1 << 12)) -#define BIT11 ((hi_u32)(1 << 11)) -#define BIT10 ((hi_u32)(1 << 10)) -#define BIT9 ((hi_u32)(1 << 9)) -#define BIT8 ((hi_u32)(1 << 8)) -#define BIT7 ((hi_u32)(1 << 7)) -#define BIT6 ((hi_u32)(1 << 6)) -#define BIT5 ((hi_u32)(1 << 5)) -#define BIT4 ((hi_u32)(1 << 4)) -#define BIT3 ((hi_u32)(1 << 3)) -#define BIT2 ((hi_u32)(1 << 2)) -#define BIT1 ((hi_u32)(1 << 1)) -#define BIT0 ((hi_u32)(1 << 0)) +#define BIT31 ((hi_u32)(1UL << 31)) +#define BIT30 ((hi_u32)(1 << 30)) +#define BIT29 ((hi_u32)(1 << 29)) +#define BIT28 ((hi_u32)(1 << 28)) +#define BIT27 ((hi_u32)(1 << 27)) +#define BIT26 ((hi_u32)(1 << 26)) +#define BIT25 ((hi_u32)(1 << 25)) +#define BIT24 ((hi_u32)(1 << 24)) +#define BIT23 ((hi_u32)(1 << 23)) +#define BIT22 ((hi_u32)(1 << 22)) +#define BIT21 ((hi_u32)(1 << 21)) +#define BIT20 ((hi_u32)(1 << 20)) +#define BIT19 ((hi_u32)(1 << 19)) +#define BIT18 ((hi_u32)(1 << 18)) +#define BIT17 ((hi_u32)(1 << 17)) +#define BIT16 ((hi_u32)(1 << 16)) +#define BIT15 ((hi_u32)(1 << 15)) +#define BIT14 ((hi_u32)(1 << 14)) +#define BIT13 ((hi_u32)(1 << 13)) +#define BIT12 ((hi_u32)(1 << 12)) +#define BIT11 ((hi_u32)(1 << 11)) +#define BIT10 ((hi_u32)(1 << 10)) +#define BIT9 ((hi_u32)(1 << 9)) +#define BIT8 ((hi_u32)(1 << 8)) +#define BIT7 ((hi_u32)(1 << 7)) +#define BIT6 ((hi_u32)(1 << 6)) +#define BIT5 ((hi_u32)(1 << 5)) +#define BIT4 ((hi_u32)(1 << 4)) +#define BIT3 ((hi_u32)(1 << 3)) +#define BIT2 ((hi_u32)(1 << 2)) +#define BIT1 ((hi_u32)(1 << 1)) +#define BIT0 ((hi_u32)(1 << 0)) -#define HALFWORD_BIT_WIDTH 16 +#define HALFWORD_BIT_WIDTH 16 /* ¼Ä´æÆ÷·ÃÎÊ½Ó¿Ú */ -#define hi_reg_write(addr, val) \ - (*(volatile unsigned int *)(uintptr_t)(addr) = (val)) -#define hi_reg_read(addr, val) \ - ((val) = *(volatile unsigned int *)(uintptr_t)(addr)) -#define hi_reg_write32(addr, val) \ - (*(volatile unsigned int *)(uintptr_t)(addr) = (val)) -#define hi_reg_read32(addr, val) \ - ((val) = *(volatile unsigned int *)(uintptr_t)(addr)) -#define hi_reg_read_val32(addr) (*(volatile unsigned int *)(uintptr_t)(addr)) -#define hi_reg_setbitmsk(addr, msk) ((hi_reg_read_val32(addr)) |= (msk)) -#define hi_reg_clrbitmsk(addr, msk) ((hi_reg_read_val32(addr)) &= ~(msk)) -#define hi_reg_clrbit(addr, pos) \ - ((hi_reg_read_val32(addr)) &= ~((unsigned int)(1) << (pos))) -#define hi_reg_setbit(addr, pos) \ - ((hi_reg_read_val32(addr)) |= ((unsigned int)(1) << (pos))) -#define hi_reg_clrbits(addr, pos, bits) \ - (hi_reg_read_val32(addr) &= ~((((unsigned int)1 << (bits)) - 1) << (pos))) -#define hi_reg_setbits(addr, pos, bits, val) \ - (hi_reg_read_val32(addr) = \ - (hi_reg_read_val32(addr) & \ - (~((((unsigned int)1 << (bits)) - 1) << (pos)))) | \ - ((unsigned int)((val) & (((unsigned int)1 << (bits)) - 1)) << (pos))) -#define hi_reg_getbits(addr, pos, bits) \ - ((hi_reg_read_val32(addr) >> (pos)) & (((unsigned int)1 << (bits)) - 1)) +#define hi_reg_write(addr, val) (*(volatile unsigned int *)(uintptr_t)(addr) = (val)) +#define hi_reg_read(addr, val) ((val) = *(volatile unsigned int *)(uintptr_t)(addr)) +#define hi_reg_write32(addr, val) (*(volatile unsigned int *)(uintptr_t)(addr) = (val)) +#define hi_reg_read32(addr, val) ((val) = *(volatile unsigned int *)(uintptr_t)(addr)) +#define hi_reg_read_val32(addr) (*(volatile unsigned int*)(uintptr_t)(addr)) +#define hi_reg_setbitmsk(addr, msk) ((hi_reg_read_val32(addr)) |= (msk)) +#define hi_reg_clrbitmsk(addr, msk) ((hi_reg_read_val32(addr)) &= ~(msk)) +#define hi_reg_clrbit(addr, pos) ((hi_reg_read_val32(addr)) &= ~((unsigned int)(1) << (pos))) +#define hi_reg_setbit(addr, pos) ((hi_reg_read_val32(addr)) |= ((unsigned int)(1) << (pos))) +#define hi_reg_clrbits(addr, pos, bits) (hi_reg_read_val32(addr) &= ~((((unsigned int)1 << (bits)) - 1) << (pos))) +#define hi_reg_setbits(addr, pos, bits, val) (hi_reg_read_val32(addr) = \ + (hi_reg_read_val32(addr) & (~((((unsigned int)1 << (bits)) - 1) << (pos)))) | \ + ((unsigned int)((val) & (((unsigned int)1 << (bits)) - 1)) << (pos))) +#define hi_reg_getbits(addr, pos, bits) ((hi_reg_read_val32(addr) >> (pos)) & (((unsigned int)1 << (bits)) - 1)) -#define hi_reg_write16(addr, val) \ - (*(volatile unsigned short *)(uintptr_t)(addr) = (val)) -#define hi_reg_read16(addr, val) \ - ((val) = *(volatile unsigned short *)(uintptr_t)(addr)) -#define hi_reg_read_val16(addr) (*(volatile unsigned short *)(uintptr_t)(addr)) -#define hi_reg_clrbit16(addr, pos) \ - ((hi_reg_read_val16(addr)) &= ~((unsigned short)(1) << (pos))) -#define hi_reg_setbit16(addr, pos) \ - ((hi_reg_read_val16(addr)) |= ((unsigned short)(1) << (pos))) -#define hi_reg_clrbits16(addr, pos, bits) \ - (hi_reg_read_val16(addr) &= ~((((unsigned short)1 << (bits)) - 1) << (pos))) -#define hi_reg_setbits16(addr, pos, bits, val) \ - (hi_reg_read_val16(addr) = \ - (hi_reg_read_val16(addr) & \ - (~((((unsigned short)1 << (bits)) - 1) << (pos)))) | \ - ((unsigned short)((val) & (((unsigned short)1 << (bits)) - 1)) \ - << (pos))) -#define hi_reg_getbits16(addr, pos, bits) \ - ((hi_reg_read_val16(addr) >> (pos)) & (((unsigned short)1 << (bits)) - 1)) +#define hi_reg_write16(addr, val) (*(volatile unsigned short *)(uintptr_t)(addr) = (val)) +#define hi_reg_read16(addr, val) ((val) = *(volatile unsigned short *)(uintptr_t)(addr)) +#define hi_reg_read_val16(addr) (*(volatile unsigned short*)(uintptr_t)(addr)) +#define hi_reg_clrbit16(addr, pos) ((hi_reg_read_val16(addr)) &= ~((unsigned short)(1) << (pos))) +#define hi_reg_setbit16(addr, pos) ((hi_reg_read_val16(addr)) |= ((unsigned short)(1) << (pos))) +#define hi_reg_clrbits16(addr, pos, bits) (hi_reg_read_val16(addr) &= ~((((unsigned short)1 << (bits)) - 1) << (pos))) +#define hi_reg_setbits16(addr, pos, bits, val) (hi_reg_read_val16(addr) = \ + (hi_reg_read_val16(addr) & (~((((unsigned short)1 << (bits)) - 1) << (pos)))) | \ + ((unsigned short)((val) & (((unsigned short)1 << (bits)) - 1)) << (pos))) +#define hi_reg_getbits16(addr, pos, bits) ((hi_reg_read_val16(addr) >> (pos)) & (((unsigned short)1 << (bits)) - 1)) -#define reg_write32(addr, val) \ - (*(volatile unsigned int *)(uintptr_t)(addr) = (val)) -#define reg_read32(addr, val) \ - ((val) = *(volatile unsigned int *)(uintptr_t)(addr)) -#define reg_read_val(addr) (*(volatile unsigned *)(uintptr_t)(addr)) +#define reg_write32(addr, val) (*(volatile unsigned int *)(uintptr_t)(addr) = (val)) +#define reg_read32(addr, val) ((val) = *(volatile unsigned int *)(uintptr_t)(addr)) +#define reg_read_val(addr) (*(volatile unsigned *)(uintptr_t)(addr)) #ifndef BSP_RAM_TEXT_SECTION -#define BSP_RAM_TEXT_SECTION __attribute__((section(".bsp.ram.text"))) +#define BSP_RAM_TEXT_SECTION __attribute__ ((section(".bsp.ram.text"))) #endif #ifndef BSP_ROM_RODATA_SECTION -#define BSP_ROM_RODATA_SECTION __attribute__((section(".bsp.rom.rodata"))) +#define BSP_ROM_RODATA_SECTION __attribute__ ((section(".bsp.rom.rodata"))) #endif #ifndef BSP_ROM_DATA0_SECTION -#define BSP_ROM_DATA0_SECTION __attribute__((section(".bsp.rom.data0"))) +#define BSP_ROM_DATA0_SECTION __attribute__ ((section(".bsp.rom.data0"))) #endif #ifndef ROM_TEXT_PATCH_SECTION -#define ROM_TEXT_PATCH_SECTION __attribute__((section(".rom.text.patch"))) +#define ROM_TEXT_PATCH_SECTION __attribute__ ((section(".rom.text.patch"))) #endif #ifndef LP_RAM_BSS_SECTION -#define LP_RAM_BSS_SECTION __attribute__((section(".lowpower.ram.bss"))) +#define LP_RAM_BSS_SECTION __attribute__ ((section(".lowpower.ram.bss"))) #endif #ifndef ROM_DATA_PATCH_SECTION -#define ROM_DATA_PATCH_SECTION __attribute__((section(".rom.data.patch"))) +#define ROM_DATA_PATCH_SECTION __attribute__ ((section(".rom.data.patch"))) #endif #ifdef HAVE_PCLINT_CHECK -#define hi_likely(x) (x) -#define hi_unlikely(x) (x) +#define hi_likely(x) (x) +#define hi_unlikely(x) (x) #else #define hi_likely(x) __builtin_expect(!!(x), 1) #define hi_unlikely(x) __builtin_expect(!!(x), 0) @@ -557,19 +516,20 @@ typedef __int64 hi_s64; #define HI_ALWAYS_STAIC_INLINE __attribute__((always_inline)) static inline #ifdef HAVE_PCLINT_CHECK -#define hi_offset_of_member(type, member) 0 +#define hi_offset_of_member(type, member) 0 #else -#define hi_offset_of_member(type, member) ((hi_u32)(&((type *)0)->member)) +#define hi_offset_of_member(type, member) ((hi_u32)(&((type *)0)->member)) #endif -#define BITS_PER_BYTE 8 -#define HEXADECIMAL 16 -#define DECIMAL 10 +#define BITS_PER_BYTE 8 +#define HEXADECIMAL 16 +#define DECIMAL 10 #define SZ_1KB 1024 #define SZ_1MB (SZ_1KB * SZ_1KB) #define SZ_4KB 4096 /*****************************************************************************/ #include -#define HI_SYS_WAIT_FOREVER 0xFFFFFFFF +#define HI_SYS_WAIT_FOREVER 0xFFFFFFFF #endif /* __HI_TYPES__BASE_H__ */ + diff --git a/project/app/wifi_app/hisi_tools/app/link/hichannel_host.c b/project/app/wifi_app/hisi_tools/app/link/hichannel_host.c index 350f32168..4a3c405ed 100644 --- a/project/app/wifi_app/hisi_tools/app/link/hichannel_host.c +++ b/project/app/wifi_app/hisi_tools/app/link/hichannel_host.c @@ -1,207 +1,211 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights - * reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: sample cli file. + * Author: Hisilicon + * Create: 2020-09-09 */ /***************************************************************************** 1 Í·Îļþ°üº¬ *****************************************************************************/ +#include +#include #include +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include -#include +#include "securec.h" #include "hi_base.h" #include "hichannel_host.h" -#include "securec.h" /***************************************************************************** 2 ºê¶¨Ò塢ȫ¾Ö±äÁ¿ *****************************************************************************/ -#define NETLINK_SOCKET_PORT_ID 1100 -#define NETLINK_CHANNEL_MODEID 28 +#define NETLINK_SOCKET_PORT_ID 1100 +#define NETLINK_CHANNEL_MODEID 28 #undef NLMSG_ALIGNTO -#define NLMSG_ALIGNTO 1 -#define USLEEP_TIMES 10 +#define NLMSG_ALIGNTO 1 +#define USLEEP_TIMES 10 typedef struct { - hi_s32 skfd; - pthread_t channel_thread; - hi_channel_rx_func rx_func; + hi_s32 skfd; + pthread_t channel_thread; + hi_channel_rx_func rx_func; } netlink_monitor_s; /***************************************************************************** 3 ö¾Ù¡¢½á¹¹Ì嶨Òå *****************************************************************************/ -static hi_bool g_channel_terminate = HI_FALSE; +static hi_bool g_channel_terminate = HI_FALSE; static netlink_monitor_s *g_channel_monitor = HI_NULL; /***************************************************************************** 4 º¯ÊýʵÏÖ *****************************************************************************/ -static hi_void *hi_channel_host_thread(hi_void *args) { - hi_s32 rev_len; - hi_s32 payload_len; - hi_char msg[SYSTEM_CMD_SIZE]; - struct nlmsghdr *nlh = HI_NULL; - struct sockaddr_nl daddr; - socklen_t len = sizeof(struct sockaddr_nl); - sample_unused(args); +static hi_void *hi_channel_host_thread(hi_void *args) +{ + hi_s32 rev_len; + hi_s32 payload_len; + hi_char msg[SYSTEM_CMD_SIZE]; + struct nlmsghdr *nlh = HI_NULL; + struct sockaddr_nl daddr; + socklen_t len = sizeof(struct sockaddr_nl); + sample_unused(args); - while (!g_channel_terminate) { - (hi_void) memset_s(&msg[0], sizeof(msg), 0, sizeof(msg)); - rev_len = recvfrom(g_channel_monitor->skfd, &msg[0], sizeof(msg), - MSG_WAITALL, (struct sockaddr *)&daddr, &len); - if (rev_len == -1) { - if (errno == EINTR) { - usleep(USLEEP_TIMES); - continue; - } else { - sample_log_print("recvfrom error! fd:%d\n", g_channel_monitor->skfd); - return HI_NULL; - } + while (!g_channel_terminate) { + (hi_void)memset_s(&msg[0], sizeof(msg), 0, sizeof(msg)); + rev_len = recvfrom(g_channel_monitor->skfd, &msg[0], sizeof(msg), + MSG_WAITALL, (struct sockaddr *)&daddr, &len); + if (rev_len == -1) { + if (errno == EINTR) { + usleep(USLEEP_TIMES); + continue; + } else { + sample_log_print("recvfrom error! fd:%d\n", g_channel_monitor->skfd); + return HI_NULL; + } + } + + if (rev_len <= NLMSG_HDRLEN) { + usleep(USLEEP_TIMES); + continue; + } + + nlh = (struct nlmsghdr *)msg; + payload_len = rev_len - NLMSG_HDRLEN; + sample_log_print("hi_channel_host_thread:%x,%d,%d,%d\n", nlh->nlmsg_type, payload_len, rev_len, NLMSG_HDRLEN); + if (g_channel_monitor->rx_func != HI_NULL) { + g_channel_monitor->rx_func((hi_u8 *)NLMSG_DATA(nlh), payload_len); + } } - if (rev_len <= NLMSG_HDRLEN) { - usleep(USLEEP_TIMES); - continue; - } - - nlh = (struct nlmsghdr *)msg; - payload_len = rev_len - NLMSG_HDRLEN; - sample_log_print("hi_channel_host_thread:%x,%d,%d,%d\n", nlh->nlmsg_type, - payload_len, rev_len, NLMSG_HDRLEN); - if (g_channel_monitor->rx_func != HI_NULL) { - g_channel_monitor->rx_func((hi_u8 *)NLMSG_DATA(nlh), payload_len); - } - } - - return HI_NULL; + return HI_NULL; } -hi_s32 hi_channel_register_rx_cb(hi_channel_rx_func rx_func) { - if ((g_channel_monitor == HI_NULL) || (rx_func == HI_NULL)) { - sample_log_print("hi_channel_register_rx_cb is fail\n"); - return HI_FAILURE; - } +hi_s32 hi_channel_register_rx_cb(hi_channel_rx_func rx_func) +{ + if ((g_channel_monitor == HI_NULL) || (rx_func == HI_NULL)) { + sample_log_print("hi_channel_register_rx_cb is fail\n"); + return HI_FAILURE; + } - g_channel_monitor->rx_func = rx_func; - return HI_SUCCESS; + g_channel_monitor->rx_func = rx_func; + return HI_SUCCESS; } -hi_s32 hi_channel_send_to_dev(unsigned char *buf, int len) { - int ret; - struct nlmsghdr *nlh = HI_NULL; - struct sockaddr_nl daddr; +hi_s32 hi_channel_send_to_dev(unsigned char *buf, int len) +{ + int ret; + struct nlmsghdr *nlh = HI_NULL; + struct sockaddr_nl daddr; - if ((buf == HI_NULL) || (len <= 0) || (len > MAX_SEND_DATA_SIZE)) { - sample_log_print("sendto sata len:%d\n", len); - return HI_FAILURE; - } + if ((buf == HI_NULL) || (len <= 0) || (len > MAX_SEND_DATA_SIZE)) { + sample_log_print("sendto sata len:%d\n", len); + return HI_FAILURE; + } - (hi_void) memset_s(&daddr, sizeof(daddr), 0, sizeof(daddr)); - daddr.nl_family = AF_NETLINK; /* netlink id */ - nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(len)); - if (nlh == HI_NULL) { - sample_log_print("malloc mem is fail\n"); - return HI_FAILURE; - } + (hi_void)memset_s(&daddr, sizeof(daddr), 0, sizeof(daddr)); + daddr.nl_family = AF_NETLINK; /* netlink id */ + nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(len)); + if (nlh == HI_NULL) { + sample_log_print("malloc mem is fail\n"); + return HI_FAILURE; + } + + (hi_void)memset_s(nlh, sizeof(nlh), 0x00, sizeof(nlh)); + nlh->nlmsg_len = NLMSG_SPACE(len); + nlh->nlmsg_pid = NETLINK_SOCKET_PORT_ID; + (hi_void)memcpy_s(NLMSG_DATA(nlh), NLMSG_SPACE(len), buf, len); + ret = sendto(g_channel_monitor->skfd, nlh, nlh->nlmsg_len, 0, + (struct sockaddr *)&daddr, sizeof(struct sockaddr_nl)); + if (ret == -1) { + sample_log_print("sendto error:%s\n", strerror(errno)); + free(nlh); + return HI_FAILURE; + } - (hi_void) memset_s(nlh, sizeof(nlh), 0x00, sizeof(nlh)); - nlh->nlmsg_len = NLMSG_SPACE(len); - nlh->nlmsg_pid = NETLINK_SOCKET_PORT_ID; - (hi_void) memcpy_s(NLMSG_DATA(nlh), NLMSG_SPACE(len), buf, len); - ret = sendto(g_channel_monitor->skfd, nlh, nlh->nlmsg_len, 0, - (struct sockaddr *)&daddr, sizeof(struct sockaddr_nl)); - if (ret == -1) { - sample_log_print("sendto error:%s\n", strerror(errno)); free(nlh); - return HI_FAILURE; - } - - free(nlh); - return 0; + return 0; } -hi_s32 hi_channel_init(hi_void) { - hi_s32 ret; - struct sockaddr_nl saddr = {0}; +hi_s32 hi_channel_init(hi_void) +{ + hi_s32 ret; + struct sockaddr_nl saddr = {0}; - if (g_channel_monitor != HI_NULL) { - sample_log_print("hi_channel_init is fail\n"); - return HI_FAILURE; - } + if (g_channel_monitor != HI_NULL) { + sample_log_print("hi_channel_init is fail\n"); + return HI_FAILURE; + } - g_channel_monitor = (netlink_monitor_s *)malloc(sizeof(netlink_monitor_s)); - if (g_channel_monitor == HI_NULL) { - return HI_FAILURE; - } + g_channel_monitor = (netlink_monitor_s *)malloc(sizeof(netlink_monitor_s)); + if (g_channel_monitor == HI_NULL) { + return HI_FAILURE; + } - g_channel_terminate = HI_FALSE; - (hi_void) memset_s(g_channel_monitor, sizeof(netlink_monitor_s), 0, - sizeof(netlink_monitor_s)); - g_channel_monitor->skfd = -1; - g_channel_monitor->skfd = - socket(AF_NETLINK, SOCK_RAW, NETLINK_CHANNEL_MODEID); - if (g_channel_monitor->skfd == -1) { - sample_log_print("create is fail:%s\n", strerror(errno)); - goto deinit; - } + g_channel_terminate = HI_FALSE; + (hi_void)memset_s(g_channel_monitor, sizeof(netlink_monitor_s), 0, sizeof(netlink_monitor_s)); + g_channel_monitor->skfd = -1; + g_channel_monitor->skfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_CHANNEL_MODEID); + if (g_channel_monitor->skfd == -1) { + sample_log_print("create is fail:%s\n", strerror(errno)); + goto deinit; + } - (hi_void) memset_s(&saddr, sizeof(saddr), 0x00, sizeof(saddr)); - saddr.nl_family = AF_NETLINK; /* netlink id */ - saddr.nl_pid = NETLINK_SOCKET_PORT_ID; /* self pid */ + (hi_void)memset_s(&saddr, sizeof(saddr), 0x00, sizeof(saddr)); + saddr.nl_family = AF_NETLINK; /* netlink id */ + saddr.nl_pid = NETLINK_SOCKET_PORT_ID; /* self pid */ - ret = bind(g_channel_monitor->skfd, (struct sockaddr *)&saddr, sizeof(saddr)); - if (ret != 0) { - goto deinit; - } + ret = bind(g_channel_monitor->skfd, (struct sockaddr *)&saddr, sizeof(saddr)); + if (ret != 0) { + goto deinit; + } - ret = pthread_create(&g_channel_monitor->channel_thread, HI_NULL, - hi_channel_host_thread, HI_NULL); - if (ret != HI_SUCCESS) { - goto deinit; - } + ret = pthread_create(&g_channel_monitor->channel_thread, HI_NULL, hi_channel_host_thread, HI_NULL); + if (ret != HI_SUCCESS) { + goto deinit; + } - return HI_SUCCESS; + return HI_SUCCESS; deinit: - if (g_channel_monitor->skfd != -1) { - close(g_channel_monitor->skfd); - g_channel_monitor->skfd = -1; - } + if (g_channel_monitor->skfd != -1) { + close(g_channel_monitor->skfd); + g_channel_monitor->skfd = -1; + } - if (g_channel_monitor != HI_NULL) { - free(g_channel_monitor); - g_channel_monitor = HI_NULL; - } - return HI_FAILURE; -} - -hi_s32 hi_channel_deinit(hi_void) { - if (g_channel_monitor == HI_NULL) { - sample_log_print("hi_channel_deinit is fail\n"); + if (g_channel_monitor != HI_NULL) { + free(g_channel_monitor); + g_channel_monitor = HI_NULL; + } return HI_FAILURE; - } - - g_channel_terminate = HI_TRUE; - - if (g_channel_monitor->channel_thread) { - pthread_cancel(g_channel_monitor->channel_thread); - pthread_join(g_channel_monitor->channel_thread, HI_NULL); - } - - if (g_channel_monitor->skfd != -1) { - close(g_channel_monitor->skfd); - g_channel_monitor->skfd = -1; - } - - if (g_channel_monitor != HI_NULL) { - free(g_channel_monitor); - g_channel_monitor = HI_NULL; - } - - return HI_SUCCESS; } + +hi_s32 hi_channel_deinit(hi_void) +{ + if (g_channel_monitor == HI_NULL) { + sample_log_print("hi_channel_deinit is fail\n"); + return HI_FAILURE; + } + + g_channel_terminate = HI_TRUE; + + if (g_channel_monitor->channel_thread) { + pthread_cancel(g_channel_monitor->channel_thread); + pthread_join(g_channel_monitor->channel_thread, HI_NULL); + } + + if (g_channel_monitor->skfd != -1) { + close(g_channel_monitor->skfd); + g_channel_monitor->skfd = -1; + } + + if (g_channel_monitor != HI_NULL) { + free(g_channel_monitor); + g_channel_monitor = HI_NULL; + } + + return HI_SUCCESS; +} + diff --git a/project/app/wifi_app/hisi_tools/app/link/hichannel_host.h b/project/app/wifi_app/hisi_tools/app/link/hichannel_host.h index 57f017799..265e65668 100644 --- a/project/app/wifi_app/hisi_tools/app/link/hichannel_host.h +++ b/project/app/wifi_app/hisi_tools/app/link/hichannel_host.h @@ -1,6 +1,8 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights - * reserved. Description: sample link file. Author: Hisilicon Create: 2020-09-09 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: sample link file. + * Author: Hisilicon + * Create: 2020-09-09 */ #ifndef HISI_LINK_H @@ -13,9 +15,9 @@ extern "C" { /***************************************************************************** 1 ºê¶¨Òå *****************************************************************************/ -#define SYSTEM_CMD_SIZE 384 /* СÓÚÕâ¸öÖµµÄÊý¾Ý±¨ÎÄͨ¹ý¸ßÓÅÏȼ¶Í¨µÀ´«Êä */ -#define MAX_SEND_DATA_SIZE 1500 /* СÓÚÕâ¸öÖµµÄÊý¾Ý±¨ÎÄͨ¹ýµÍÓÅÏȼ¶Í¨µÀ´«Êä */ -#define SYSTEM_NETDEV_NAME "wlan0" +#define SYSTEM_CMD_SIZE 384 /* СÓÚÕâ¸öÖµµÄÊý¾Ý±¨ÎÄͨ¹ý¸ßÓÅÏȼ¶Í¨µÀ´«Êä */ +#define MAX_SEND_DATA_SIZE 1500 /* СÓÚÕâ¸öÖµµÄÊý¾Ý±¨ÎÄͨ¹ýµÍÓÅÏȼ¶Í¨µÀ´«Êä */ +#define SYSTEM_NETDEV_NAME "wlan0" typedef void (*hi_channel_rx_func)(unsigned char *msg_data, int len); /***************************************************************************** diff --git a/project/app/wifi_app/hisi_tools/app/link/hichannel_host_comm.c b/project/app/wifi_app/hisi_tools/app/link/hichannel_host_comm.c index 1b09ee62a..1e5eaa64c 100644 --- a/project/app/wifi_app/hisi_tools/app/link/hichannel_host_comm.c +++ b/project/app/wifi_app/hisi_tools/app/link/hichannel_host_comm.c @@ -1,20 +1,21 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights - * reserved. Description: sample common file. Author: Hisilicon Create: - * 2018-08-04 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: sample common file. + * Author: Hisilicon + * Create: 2018-08-04 */ /***************************************************************************** 1 Í·Îļþ°üº¬ *****************************************************************************/ +#include +#include +#include +#include +#include +#include "securec.h" #include "hichannel_host_comm.h" #include "hi_base.h" -#include "securec.h" -#include -#include -#include -#include -#include /***************************************************************************** 2 ºê¶¨Ò塢ȫ¾Ö±äÁ¿ @@ -24,119 +25,117 @@ static sample_cmd_common g_cmd_com = {0}; /***************************************************************************** 4 º¯ÊýʵÏÖ *****************************************************************************/ -hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg, - hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset) { - const hi_char *pc_cmd_copy = HI_NULL; - hi_u32 pos = 0; +hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg, hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset) +{ + const hi_char *pc_cmd_copy = HI_NULL; + hi_u32 pos = 0; - if ((pc_cmd == HI_NULL) || (pc_arg == HI_NULL) || - (pul_cmd_offset == HI_NULL)) { - sample_log_print( - "pc_cmd/pc_arg/pul_cmd_offset null ptr error %pK, %pK, %pK!\n", pc_cmd, - pc_arg, pul_cmd_offset); - return HI_FAILURE; - } - - pc_cmd_copy = pc_cmd; - - while (*pc_cmd_copy != '\0' && - !((*(pc_cmd_copy) == ',') && (*(pc_cmd_copy - 1) != '\\'))) { - if ((*(pc_cmd_copy + 1) == ',') && (*(pc_cmd_copy) == '\\')) { - ++pc_cmd_copy; - continue; - } - pc_arg[pos] = *pc_cmd_copy; - ++pos; - ++pc_cmd_copy; - - if (pos >= pc_arg_len) { - sample_log_print("ul_pos >= WLAN_CMD_NAME_MAX_LEN, ul_pos %d!\n", pos); - return HI_FAILURE; - } - } - - pc_arg[pos] = '\0'; - - /* ×Ö·û´®µ½½á⣬·µ»Ø´íÎóÂë */ - if (pos == 0) { - sample_log_print("return param pc_arg is null!}\r\n"); - return HI_FAILURE; - } - *pul_cmd_offset = (hi_u32)(pc_cmd_copy - pc_cmd); - - return HI_SUCCESS; -} - -hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len, - hi_void *msg) { - hi_u8 cmd_id; - hi_u32 off_set = 0; - hi_char wlan_name[SAMPLE_CMD_MAX_LEN] = {0}; - - if (cmd == HI_NULL) { - return HI_FAILURE; - } - - if (sample_get_cmd_one_arg(cmd, wlan_name, SAMPLE_CMD_MAX_LEN, &off_set) != - HI_SUCCESS) { - return HI_FAILURE; - } - cmd += (off_set + 1); - - for (cmd_id = 0; cmd_id < g_cmd_com.count; cmd_id++) { - if (strcmp(g_cmd_com.cmd_tbl[cmd_id].cmd_name, wlan_name) == 0) { - if (g_cmd_com.cmd_tbl[cmd_id].func(wdata, cmd, len, msg) != HI_SUCCESS) { - sample_log_print("cmd exec fail!\n"); + if ((pc_cmd == HI_NULL) || (pc_arg == HI_NULL) || (pul_cmd_offset == HI_NULL)) { + sample_log_print("pc_cmd/pc_arg/pul_cmd_offset null ptr error %pK, %pK, %pK!\n", \ + pc_cmd, pc_arg, pul_cmd_offset); return HI_FAILURE; - } - return HI_SUCCESS; } - } - return HI_FAILURE; + pc_cmd_copy = pc_cmd; + + while (*pc_cmd_copy != '\0' && !((*(pc_cmd_copy) == ',') && (*(pc_cmd_copy - 1) != '\\'))) { + if ((*(pc_cmd_copy + 1) == ',') && (*(pc_cmd_copy) == '\\')) { + ++pc_cmd_copy; + continue; + } + pc_arg[pos] = *pc_cmd_copy; + ++pos; + ++pc_cmd_copy; + + if (pos >= pc_arg_len) { + sample_log_print("ul_pos >= WLAN_CMD_NAME_MAX_LEN, ul_pos %d!\n", pos); + return HI_FAILURE; + } + } + + pc_arg[pos] = '\0'; + + /* ×Ö·û´®µ½½á⣬·µ»Ø´íÎóÂë */ + if (pos == 0) { + sample_log_print("return param pc_arg is null!}\r\n"); + return HI_FAILURE; + } + *pul_cmd_offset = (hi_u32)(pc_cmd_copy - pc_cmd); + + return HI_SUCCESS; } -hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len, - hi_void *msg) { - hi_char *pcmd = HI_NULL; - hi_char *pcmd_tmp = HI_NULL; - if (len > SAMPLE_CMD_MAX_LEN) { - sample_log_print("command len > %d!\n", SAMPLE_CMD_MAX_LEN); - return HI_FAILURE; - } - pcmd = malloc(SAMPLE_CMD_MAX_LEN); - if (pcmd == HI_NULL) { - return HI_FAILURE; - } - if (cmd != HI_NULL) { - if (memcpy_s(pcmd, len, cmd, len) != EOK) { - sample_log_print("command memcpy_s failed!\n"); - free(pcmd); - return HI_FAILURE; - } - } +hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len, hi_void *msg) +{ + hi_u8 cmd_id; + hi_u32 off_set = 0; + hi_char wlan_name[SAMPLE_CMD_MAX_LEN] = {0}; - pcmd[len] = '\0'; - pcmd_tmp = pcmd; - if (sample_parse_cmd(wdata, pcmd_tmp, len, msg) != HI_SUCCESS) { + if (cmd == HI_NULL) { + return HI_FAILURE; + } + + if (sample_get_cmd_one_arg(cmd, wlan_name, SAMPLE_CMD_MAX_LEN, &off_set) != HI_SUCCESS) { + return HI_FAILURE; + } + cmd += (off_set + 1); + + for (cmd_id = 0; cmd_id < g_cmd_com.count; cmd_id++) { + if (strcmp(g_cmd_com.cmd_tbl[cmd_id].cmd_name, wlan_name) == 0) { + if (g_cmd_com.cmd_tbl[cmd_id].func(wdata, cmd, len, msg) != HI_SUCCESS) { + sample_log_print("cmd exec fail!\n"); + return HI_FAILURE; + } + return HI_SUCCESS; + } + } + + return HI_FAILURE; +} + +hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len, hi_void *msg) +{ + hi_char *pcmd = HI_NULL; + hi_char *pcmd_tmp = HI_NULL; + if (len > SAMPLE_CMD_MAX_LEN) { + sample_log_print("command len > %d!\n", SAMPLE_CMD_MAX_LEN); + return HI_FAILURE; + } + pcmd = malloc(SAMPLE_CMD_MAX_LEN); + if (pcmd == HI_NULL) { + return HI_FAILURE; + } + if (cmd != HI_NULL) { + if (memcpy_s(pcmd, len, cmd, len) != EOK) { + sample_log_print("command memcpy_s failed!\n"); + free(pcmd); + return HI_FAILURE; + } + } + + pcmd[len] = '\0'; + pcmd_tmp = pcmd; + if (sample_parse_cmd(wdata, pcmd_tmp, len, msg) != HI_SUCCESS) { + free(pcmd); + return HI_FAILURE; + } free(pcmd); - return HI_FAILURE; - } - free(pcmd); - return HI_SUCCESS; + return HI_SUCCESS; } -hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num) { - hi_u32 i; - sample_cmd_common *tmp_list = HI_NULL; - tmp_list = (sample_cmd_common *)&g_cmd_com; - for (i = 0; i < num; i++) { - if (cmd_tbl[i].cmd_name == HI_NULL || cmd_tbl[i].func == HI_NULL) { - sample_log_print("SAMPLE_COMMON: register cmd table failed!\n"); - return HI_FAILURE; +hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num) +{ + hi_u32 i; + sample_cmd_common *tmp_list = HI_NULL; + tmp_list = (sample_cmd_common *)&g_cmd_com; + for (i = 0; i < num; i++) { + if (cmd_tbl[i].cmd_name == HI_NULL || cmd_tbl[i].func == HI_NULL) { + sample_log_print("SAMPLE_COMMON: register cmd table failed!\n"); + return HI_FAILURE; + } } - } - tmp_list->cmd_tbl = cmd_tbl; - tmp_list->count = num; - return HI_SUCCESS; + tmp_list->cmd_tbl = cmd_tbl; + tmp_list->count = num; + return HI_SUCCESS; } + diff --git a/project/app/wifi_app/hisi_tools/app/link/hichannel_host_comm.h b/project/app/wifi_app/hisi_tools/app/link/hichannel_host_comm.h index 009608115..16ee7d042 100644 --- a/project/app/wifi_app/hisi_tools/app/link/hichannel_host_comm.h +++ b/project/app/wifi_app/hisi_tools/app/link/hichannel_host_comm.h @@ -1,7 +1,8 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights - * reserved. Description: sample common file. Author: Hisilicon Create: - * 2018-08-04 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: sample common file. + * Author: Hisilicon + * Create: 2018-08-04 */ #ifndef __SAMPLE_COMMON_H__ @@ -19,30 +20,27 @@ /***************************************************************************** 3 ö¾Ù¡¢½á¹¹Ì嶨Òå *****************************************************************************/ -typedef hi_s32 (*sample_cmd_func)(hi_void *wdata, hi_char *param, hi_u32 len, - hi_void *pmsg); +typedef hi_s32(*sample_cmd_func)(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg); typedef struct { - hi_char *cmd_name; /* ÃüÁî×Ö·û´® */ - sample_cmd_func func; /* ÃüÁî¶ÔÓ¦´¦Àíº¯Êý */ + hi_char *cmd_name; /* ÃüÁî×Ö·û´® */ + sample_cmd_func func; /* ÃüÁî¶ÔÓ¦´¦Àíº¯Êý */ } sample_cmd_entry_stru; typedef struct { - sample_cmd_entry_stru *cmd_tbl; /* ÃüÁî±í */ - hi_u32 count; /* ÃüÁî×ÜÊý */ + sample_cmd_entry_stru *cmd_tbl; /* ÃüÁî±í */ + hi_u32 count; /* ÃüÁî×ÜÊý */ } sample_cmd_common; /***************************************************************************** 4 º¯ÊýÉùÃ÷ *****************************************************************************/ -hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg, - hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset); +hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg, hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset); -hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len, - hi_void *msg); +hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len, hi_void *msg); -hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len, - hi_void *msg); +hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len, hi_void *msg); hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num); #endif + diff --git a/project/app/wifi_app/hisi_tools/app/link/hichannel_main.c b/project/app/wifi_app/hisi_tools/app/link/hichannel_main.c index f430bd30f..eb86f580c 100644 --- a/project/app/wifi_app/hisi_tools/app/link/hichannel_main.c +++ b/project/app/wifi_app/hisi_tools/app/link/hichannel_main.c @@ -1,35 +1,35 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights - * reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: sample cli file. + * Author: Hisilicon + * Create: 2020-09-09 */ /***************************************************************************** 1 Í·Îļþ°üº¬ *****************************************************************************/ -#include -#include -#include -#include -#include +#include #include -#include +#include #include #include -#include +#include +#include +#include +#include +#include +#include "securec.h" #include "hi_base.h" #include "hichannel_host.h" #include "hichannel_host_comm.h" -#include "securec.h" /***************************************************************************** 2 ºê¶¨Ò塢ȫ¾Ö±äÁ¿ *****************************************************************************/ -static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param, - hi_u32 len, hi_void *pmsg); -static hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, - hi_u32 len, hi_void *pmsg); +static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg); +static hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg); -static const sample_cmd_entry_stru g_sample_cmd[] = { +static const sample_cmd_entry_stru g_sample_cmd[] = { {"help", sample_help_cmd_process}, {"exit", sample_exit_cmd_process}, }; @@ -43,494 +43,490 @@ static const sample_cmd_entry_stru g_sample_cmd[] = { 3 ö¾Ù¡¢½á¹¹Ì嶨Òå *****************************************************************************/ typedef enum { - /* commands */ - SAMPLE_CMD_IOCTL, - SAMPLE_CMD_HELP, - SAMPLE_CMD_EXIT, - SAMPLE_CMD_BUTT, + /* commands */ + SAMPLE_CMD_IOCTL, + SAMPLE_CMD_HELP, + SAMPLE_CMD_EXIT, + SAMPLE_CMD_BUTT, } sample_cmd_e; typedef enum { - HOST_CMD_GET_MAC, - HOST_CMD_GET_IP, - HOST_CMD_SET_FILTER, - HOST_CMD_TBTT, -} host_cmd_e; + HOST_CMD_GET_MAC, + HOST_CMD_GET_IP, + HOST_CMD_SET_FILTER, + HOST_CMD_TBTT, +}host_cmd_e; /* command/event information */ typedef struct { - sample_cmd_e what; - hi_u32 len; - hi_u8 obj[CMD_MAX_LEN]; + sample_cmd_e what; + hi_u32 len; + hi_u8 obj[CMD_MAX_LEN]; } sample_message_s; struct snode { - sample_message_s message; - struct snode *next; + sample_message_s message; + struct snode *next; }; struct squeue { - struct snode *front; - struct snode *rear; + struct snode *front; + struct snode *rear; }; typedef struct { - pthread_mutex_t mut; - pthread_cond_t cond; - struct squeue cmd_queue; - pthread_t sock_thread; - hi_s32 sockfd; + pthread_mutex_t mut; + pthread_cond_t cond; + struct squeue cmd_queue; + pthread_t sock_thread; + hi_s32 sockfd; } sample_link_s; static hi_bool g_terminate = HI_FALSE; static sample_link_s *g_sample_link = HI_NULL; -static hi_char host_cmd[][MAX_CMD_LEN] = {"cmd_get_mac", "cmd_get_ip", - "cmd_set_filter"}; +static hi_char host_cmd[][MAX_CMD_LEN] = {"cmd_get_mac", "cmd_get_ip", "cmd_set_filter"}; /***************************************************************************** 4 º¯ÊýʵÏÖ *****************************************************************************/ -static hi_void sample_usage(hi_void) { - printf("\nUsage:\n"); - printf("\tsample_cli quit quit sample_ap\n"); - printf("\tsample_cli help show this message\n"); +static hi_void sample_usage(hi_void) +{ + printf("\nUsage:\n"); + printf("\tsample_cli quit quit sample_ap\n"); + printf("\tsample_cli help show this message\n"); } -hi_s32 sample_str_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, - hi_void *pmsg) { - sample_unused(wdata); - sample_message_s *msg = (sample_message_s *)pmsg; - msg->what = SAMPLE_CMD_IOCTL; - msg->len = len; - (hi_void) memcpy_s(msg->obj, CMD_MAX_LEN, param, len); - msg->obj[CMD_MAX_LEN - 1] = '\0'; - return HI_SUCCESS; -} - -hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, - hi_void *pmsg) { - sample_unused(wdata); - sample_unused(param); - sample_unused(len); - sample_message_s *msg = (sample_message_s *)pmsg; - msg->what = SAMPLE_CMD_HELP; - return HI_SUCCESS; -} - -static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param, - hi_u32 len, hi_void *pmsg) { - sample_unused(wdata); - sample_unused(param); - sample_unused(len); - sample_message_s *msg = (sample_message_s *)pmsg; - msg->what = SAMPLE_CMD_EXIT; - return HI_SUCCESS; -} - -static hi_void sample_cleanup(hi_void) { - sample_log_print("sample_cleanup enter\n"); - if (g_sample_link->sock_thread) { - pthread_cancel(g_sample_link->sock_thread); - pthread_join(g_sample_link->sock_thread, HI_NULL); - } - - pthread_mutex_destroy(&g_sample_link->mut); - pthread_cond_destroy(&g_sample_link->cond); - - if (g_sample_link->sockfd != -1) { - close(g_sample_link->sockfd); - } - - if (g_sample_link != HI_NULL) { - free(g_sample_link); - g_sample_link = HI_NULL; - } -} - -static hi_void sample_terminate(hi_s32 sig) { - sample_unused(sig); - sample_cleanup(); - g_terminate = HI_TRUE; - _exit(0); -} - -static hi_void sample_power(hi_s32 sig) { sample_unused(sig); } - -static hi_s32 sample_wlan_init_up(hi_void) { - hi_s32 ret; - hi_char cmd[SYSTEM_CMD_SIZE] = {0}; - - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", - SYSTEM_NETDEV_NAME) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; - } - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s up error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } - - sample_log_print("net device up success\n"); - return HI_SUCCESS; -} - -static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len) { - hi_s32 ret; - hi_char cmd[SYSTEM_CMD_SIZE] = {0}; - - if (len != WIFI_MAC_LEN) { - return HI_FAILURE; - } - - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down", - SYSTEM_NETDEV_NAME) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; - } - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s down error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } - - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, - "ifconfig %s hw ether %x:%x:%x:%x:%x:%x", - /* 2, 3, 4, 5: MACµØÖ·µÄµÚ2, 3, 4, 5 Byte */ - SYSTEM_NETDEV_NAME, mac_addr[0], mac_addr[1], mac_addr[2], - mac_addr[3], mac_addr[4], mac_addr[5]) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; - } - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s set mac error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } - - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", - SYSTEM_NETDEV_NAME) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; - } - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s up error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } - - sample_log_print("net device set mac success\n"); - - return HI_SUCCESS; -} - -static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 len) { - hi_s32 ret; - hi_char cmd[SYSTEM_CMD_SIZE] = {0}; - - sample_unused(len); - if ((ip_addr[0] == 0) && (ip_addr[1] == 0) && (ip_addr[2] == 0) && - (ip_addr[3] == 0)) { /* 1 2 3 ipaddr */ +hi_s32 sample_str_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg) +{ + sample_unused(wdata); + sample_message_s *msg = (sample_message_s *)pmsg; + msg->what = SAMPLE_CMD_IOCTL; + msg->len = len; + (hi_void)memcpy_s(msg->obj, CMD_MAX_LEN, param, len); + msg->obj[CMD_MAX_LEN - 1] = '\0'; return HI_SUCCESS; - } - - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down", - SYSTEM_NETDEV_NAME) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; - } - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s down error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } - - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, - "ifconfig %s %d.%d.%d.%d netmask %d.%d.%d.%d", - SYSTEM_NETDEV_NAME, - /* 2, 3, 4, 5, 6, 7: ·Ö±ðΪIPµØÖ·µÄµÚ2, 3, 4, 5, 6, 7 Byte */ - ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3], ip_addr[4], - ip_addr[5], ip_addr[6], ip_addr[7]) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; - } - - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s set ip error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } - - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", - SYSTEM_NETDEV_NAME) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; - } - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s up error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } - - sample_log_print("net device set ip success\n"); - - return HI_SUCCESS; } -static hi_void set_lo_ipaddr(hi_void) { - hi_s32 results; - hi_char cmd[SYSTEM_CMD_SIZE] = {0}; /* system Temporary variables */ - hi_char *spawn_args[] = {"ifconfig", "lo", "127.0.0.1", HI_NULL}; - - results = sprintf_s( - cmd, sizeof(cmd), "%s %s %s", spawn_args[0], /* spawn_args[0]:ifconfig */ - spawn_args[1], spawn_args[2]); /* spawn_args[1]:lo,spawn_args[2]:ipaddr */ - if (results < EOK) { - sample_log_print("SAMPLE_STA: set lo ipaddr sprintf_s err!\n"); - return; - } - - system(cmd); +hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg) +{ + sample_unused(wdata); + sample_unused(param); + sample_unused(len); + sample_message_s *msg = (sample_message_s *)pmsg; + msg->what = SAMPLE_CMD_HELP; + return HI_SUCCESS; } -static hi_s32 sample_sock_create(hi_void) { - if (g_sample_link == HI_NULL) { - return HI_FAILURE; - } - - g_sample_link->sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (g_sample_link->sockfd == -1) { - sample_log_print("error:%s", strerror(errno)); - return HI_FAILURE; - } - - struct sockaddr_in servaddr; - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(SOCK_PORT); - - if (bind(g_sample_link->sockfd, (const struct sockaddr *)&servaddr, - sizeof(servaddr)) == -1) { - sample_log_print("error:%s", strerror(errno)); - return HI_FAILURE; - } - - return HI_SUCCESS; +static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg) +{ + sample_unused(wdata); + sample_unused(param); + sample_unused(len); + sample_message_s *msg = (sample_message_s *)pmsg; + msg->what = SAMPLE_CMD_EXIT; + return HI_SUCCESS; } -static hi_s32 sample_enqueue(struct squeue *pqueue, - const sample_message_s *element) { - struct snode *pnew = HI_NULL; - - if (pqueue == HI_NULL || element == HI_NULL) { - return -1; - } - /* Create a new node */ - pnew = malloc(sizeof(struct snode)); - if (pnew == HI_NULL) { - return -1; - } - - pnew->message = *element; - pnew->next = HI_NULL; - - if (pqueue->rear == HI_NULL) { - /* queue is empty, set front and rear points to new node */ - pqueue->front = pqueue->rear = pnew; - } else { - /* queue is not empty, set rear points to the new node */ - pqueue->rear = pqueue->rear->next = pnew; - } - - return HI_SUCCESS; -} - -static hi_s32 sample_dequeue(struct squeue *pqueue, sample_message_s *element) { - struct snode *p = HI_NULL; - - if (pqueue == HI_NULL || element == HI_NULL) { - return HI_FAILURE; - } - - if (pqueue->front == HI_NULL) { - return HI_FAILURE; - } - - *element = pqueue->front->message; - p = pqueue->front; - pqueue->front = p->next; - /* if the queue is empty, set rear = NULL */ - if (pqueue->front == HI_NULL) { - pqueue->rear = HI_NULL; - } - - free(p); - return HI_SUCCESS; -} - -static hi_void *sample_sock_thread(hi_void *args) { - hi_char link_buf[SOCK_BUF_MAX]; - ssize_t recvbytes; - sample_message_s message; - struct sockaddr_in clientaddr; - socklen_t addrlen = sizeof(clientaddr); - sample_unused(args); - - while (1) { - /* °²È«±à³Ì¹æÔò6.6ÀýÍâ(1) - * ¶Ô¹Ì¶¨³¤¶ÈµÄÊý×é½øÐгõʼ»¯£¬»ò¶Ô¹Ì¶¨³¤¶ÈµÄ½á¹¹Ìå½øÐÐÄÚ´æ³õʼ»¯ */ - (hi_void) memset_s(link_buf, sizeof(link_buf), 0, sizeof(link_buf)); - /* °²È«±à³Ì¹æÔò6.6ÀýÍâ(1) - * ¶Ô¹Ì¶¨³¤¶ÈµÄÊý×é½øÐгõʼ»¯£¬»ò¶Ô¹Ì¶¨³¤¶ÈµÄ½á¹¹Ìå½øÐÐÄÚ´æ³õʼ»¯ */ - (hi_void) memset_s(&clientaddr, sizeof(struct sockaddr_in), 0, addrlen); - - recvbytes = recvfrom(g_sample_link->sockfd, link_buf, sizeof(link_buf), 0, - (struct sockaddr *)&clientaddr, &addrlen); - if (recvbytes < 0) { - if (errno == EINTR) { - usleep(SLEEP_TIME); - continue; - } else { - sample_log_print("recvfrom error! fd:%d\n", g_sample_link->sockfd); - return HI_NULL; - } +static hi_void sample_cleanup(hi_void) +{ + sample_log_print("sample_cleanup enter\n"); + if (g_sample_link->sock_thread) { + pthread_cancel(g_sample_link->sock_thread); + pthread_join(g_sample_link->sock_thread, HI_NULL); } - if (sample_sock_cmd_entry(g_sample_link, link_buf, recvbytes, - (hi_void *)&message) != HI_SUCCESS) { - sample_log_print("sample_str_cmd_process entry\n"); - sample_str_cmd_process(g_sample_link, link_buf, recvbytes, - (hi_void *)&message); + pthread_mutex_destroy(&g_sample_link->mut); + pthread_cond_destroy(&g_sample_link->cond); + + if (g_sample_link->sockfd != -1) { + close(g_sample_link->sockfd); } - if (sendto(g_sample_link->sockfd, "OK", strlen("OK"), MSG_DONTWAIT, - (const struct sockaddr *)&clientaddr, addrlen) == -1) { - sample_log_print("sendto error!fd:%d\n", g_sample_link->sockfd); + if (g_sample_link != HI_NULL) { + free(g_sample_link); + g_sample_link = HI_NULL; } - - pthread_mutex_lock(&g_sample_link->mut); - if (sample_enqueue(&g_sample_link->cmd_queue, &message) == HI_SUCCESS) { - pthread_cond_signal(&g_sample_link->cond); - } - pthread_mutex_unlock(&g_sample_link->mut); - } } -void sample_link_rec_cb(unsigned char *msg_data, int len) { - hi_s32 ret; - hi_s32 index; - - if ((len == 0) || (msg_data == HI_NULL)) { - return; - } - - index = msg_data[0]; - sample_log_print("hisi_link_rec:%d\n", index); - if (index == HOST_CMD_GET_MAC) { - ret = sample_wlan_init_mac(&msg_data[1], WIFI_MAC_LEN); - if (ret != HI_SUCCESS) { - sample_log_print("sample_wlan_init_mac is fail\n"); - } - } else if (index == HOST_CMD_GET_IP) { - ret = sample_wlan_init_ip(&msg_data[1], len - 1); - if (ret != HI_SUCCESS) { - sample_log_print("sample_wlan_init_ip is fail\n"); - } - } else { - sample_log_print("hisi_link_rec is fail\n"); - } +static hi_void sample_terminate(hi_s32 sig) +{ + sample_unused(sig); + sample_cleanup(); + g_terminate = HI_TRUE; + _exit(0); } -void main_process(void) { - /* main loop */ - while (!g_terminate) { +static hi_void sample_power(hi_s32 sig) +{ + sample_unused(sig); +} + +static hi_s32 sample_wlan_init_up(hi_void) +{ + hi_s32 ret; + hi_char cmd[SYSTEM_CMD_SIZE] = {0}; + + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", SYSTEM_NETDEV_NAME) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s up error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } + + sample_log_print("net device up success\n"); + return HI_SUCCESS; +} + +static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len) +{ + hi_s32 ret; + hi_char cmd[SYSTEM_CMD_SIZE] = {0}; + + if (len != WIFI_MAC_LEN) { + return HI_FAILURE; + } + + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down", SYSTEM_NETDEV_NAME) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s down error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } + + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s hw ether %x:%x:%x:%x:%x:%x", + /* 2, 3, 4, 5: MACµØÖ·µÄµÚ2, 3, 4, 5 Byte */ + SYSTEM_NETDEV_NAME, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s set mac error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } + + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", SYSTEM_NETDEV_NAME) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s up error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } + + sample_log_print("net device set mac success\n"); + + return HI_SUCCESS; +} + +static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 len) +{ + hi_s32 ret; + hi_char cmd[SYSTEM_CMD_SIZE] = {0}; + + sample_unused(len); + if ((ip_addr[0] == 0) && (ip_addr[1] == 0) && (ip_addr[2] == 0) && (ip_addr[3] == 0)) { /* 1 2 3 ipaddr */ + return HI_SUCCESS; + } + + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down", SYSTEM_NETDEV_NAME) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s down error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } + + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, + "ifconfig %s %d.%d.%d.%d netmask %d.%d.%d.%d", + SYSTEM_NETDEV_NAME, + /* 2, 3, 4, 5, 6, 7: ·Ö±ðΪIPµØÖ·µÄµÚ2, 3, 4, 5, 6, 7 Byte */ + ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3], ip_addr[4], ip_addr[5], ip_addr[6], ip_addr[7]) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s set ip error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } + + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", SYSTEM_NETDEV_NAME) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s up error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } + + sample_log_print("net device set ip success\n"); + + return HI_SUCCESS; +} + +static hi_void set_lo_ipaddr(hi_void) +{ + hi_s32 results; + hi_char cmd[SYSTEM_CMD_SIZE] = {0}; /* system Temporary variables */ + hi_char *spawn_args[] = {"ifconfig", "lo", "127.0.0.1", HI_NULL}; + + results = sprintf_s(cmd, sizeof(cmd), "%s %s %s", spawn_args[0], /* spawn_args[0]:ifconfig */ + spawn_args[1], spawn_args[2]); /* spawn_args[1]:lo,spawn_args[2]:ipaddr */ + if (results < EOK) { + sample_log_print("SAMPLE_STA: set lo ipaddr sprintf_s err!\n"); + return; + } + + system(cmd); +} + +static hi_s32 sample_sock_create(hi_void) +{ + if (g_sample_link == HI_NULL) { + return HI_FAILURE; + } + + g_sample_link->sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (g_sample_link->sockfd == -1) { + sample_log_print("error:%s", strerror(errno)); + return HI_FAILURE; + } + + struct sockaddr_in servaddr; + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(SOCK_PORT); + + if (bind(g_sample_link->sockfd, (const struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { + sample_log_print("error:%s", strerror(errno)); + return HI_FAILURE; + } + + return HI_SUCCESS; +} + +static hi_s32 sample_enqueue(struct squeue *pqueue, const sample_message_s *element) +{ + struct snode *pnew = HI_NULL; + + if (pqueue == HI_NULL || element == HI_NULL) { + return -1; + } + /* Create a new node */ + pnew = malloc(sizeof(struct snode)); + if (pnew == HI_NULL) { + return -1; + } + + pnew->message = *element; + pnew->next = HI_NULL; + + if (pqueue->rear == HI_NULL) { + /* queue is empty, set front and rear points to new node */ + pqueue->front = pqueue->rear = pnew; + } else { + /* queue is not empty, set rear points to the new node */ + pqueue->rear = pqueue->rear->next = pnew; + } + + return HI_SUCCESS; +} + +static hi_s32 sample_dequeue(struct squeue *pqueue, sample_message_s *element) +{ + struct snode *p = HI_NULL; + + if (pqueue == HI_NULL || element == HI_NULL) { + return HI_FAILURE; + } + + if (pqueue->front == HI_NULL) { + return HI_FAILURE; + } + + *element = pqueue->front->message; + p = pqueue->front; + pqueue->front = p->next; + /* if the queue is empty, set rear = NULL */ + if (pqueue->front == HI_NULL) { + pqueue->rear = HI_NULL; + } + + free(p); + return HI_SUCCESS; +} + +static hi_void *sample_sock_thread(hi_void *args) +{ + hi_char link_buf[SOCK_BUF_MAX]; + ssize_t recvbytes; sample_message_s message; - pthread_mutex_lock(&g_sample_link->mut); - while (sample_dequeue(&g_sample_link->cmd_queue, &message) != HI_SUCCESS) { - pthread_cond_wait(&g_sample_link->cond, &g_sample_link->mut); - } - pthread_mutex_unlock(&g_sample_link->mut); - sample_log_print("=====SAMPLE LOOP RECIEVE MSG:%d LEN:%d=====\n", - message.what, message.len); - fflush(stdout); + struct sockaddr_in clientaddr; + socklen_t addrlen = sizeof(clientaddr); + sample_unused(args); - switch (message.what) { - case SAMPLE_CMD_HELP: - sample_usage(); - break; - case SAMPLE_CMD_EXIT: - g_terminate = HI_TRUE; - break; - case SAMPLE_CMD_IOCTL: - if (hi_channel_send_to_dev(message.obj, message.len) != HI_SUCCESS) { - sample_log_print("sample_iwpriv_cmd send fail\n"); - } - break; - default: - break; + while (1) { + /* °²È«±à³Ì¹æÔò6.6ÀýÍâ(1) ¶Ô¹Ì¶¨³¤¶ÈµÄÊý×é½øÐгõʼ»¯£¬»ò¶Ô¹Ì¶¨³¤¶ÈµÄ½á¹¹Ìå½øÐÐÄÚ´æ³õʼ»¯ */ + (hi_void)memset_s(link_buf, sizeof(link_buf), 0, sizeof(link_buf)); + /* °²È«±à³Ì¹æÔò6.6ÀýÍâ(1) ¶Ô¹Ì¶¨³¤¶ÈµÄÊý×é½øÐгõʼ»¯£¬»ò¶Ô¹Ì¶¨³¤¶ÈµÄ½á¹¹Ìå½øÐÐÄÚ´æ³õʼ»¯ */ + (hi_void)memset_s(&clientaddr, sizeof(struct sockaddr_in), 0, addrlen); + + recvbytes = recvfrom(g_sample_link->sockfd, link_buf, sizeof(link_buf), 0, + (struct sockaddr *)&clientaddr, &addrlen); + if (recvbytes < 0) { + if (errno == EINTR) { + usleep(SLEEP_TIME); + continue; + } else { + sample_log_print("recvfrom error! fd:%d\n", g_sample_link->sockfd); + return HI_NULL; + } + } + + if (sample_sock_cmd_entry(g_sample_link, link_buf, recvbytes, (hi_void *)&message) != HI_SUCCESS) { + sample_log_print("sample_str_cmd_process entry\n"); + sample_str_cmd_process(g_sample_link, link_buf, recvbytes, (hi_void *)&message); + } + + if (sendto(g_sample_link->sockfd, "OK", strlen("OK"), MSG_DONTWAIT, (const struct sockaddr *)&clientaddr, + addrlen) == -1) { + sample_log_print("sendto error!fd:%d\n", g_sample_link->sockfd); + } + + pthread_mutex_lock(&g_sample_link->mut); + if (sample_enqueue(&g_sample_link->cmd_queue, &message) == HI_SUCCESS) { + pthread_cond_signal(&g_sample_link->cond); + } + pthread_mutex_unlock(&g_sample_link->mut); } - } } -int main(int argc, char *argv[]) { - hi_s32 ret; - sample_unused(argc); - sample_unused(argv); - set_lo_ipaddr(); +void sample_link_rec_cb(unsigned char *msg_data, int len) +{ + hi_s32 ret; + hi_s32 index; - signal(SIGINT, sample_terminate); - signal(SIGTERM, sample_terminate); - signal(SIGPWR, sample_power); + if ((len == 0) || (msg_data == HI_NULL)) { + return; + } - g_sample_link = (sample_link_s *)malloc(sizeof(sample_link_s)); - if (g_sample_link == HI_NULL) { - return -1; - } + index = msg_data[0]; + sample_log_print("hisi_link_rec:%d\n", index); + if (index == HOST_CMD_GET_MAC) { + ret = sample_wlan_init_mac(&msg_data[1], WIFI_MAC_LEN); + if (ret != HI_SUCCESS) { + sample_log_print("sample_wlan_init_mac is fail\n"); + } + } else if (index == HOST_CMD_GET_IP) { + ret = sample_wlan_init_ip(&msg_data[1], len - 1); + if (ret != HI_SUCCESS) { + sample_log_print("sample_wlan_init_ip is fail\n"); + } + } else { + sample_log_print("hisi_link_rec is fail\n"); + } +} - (void)memset_s(g_sample_link, sizeof(sample_link_s), 0, - sizeof(sample_link_s)); - pthread_mutex_init(&g_sample_link->mut, HI_NULL); - pthread_cond_init(&g_sample_link->cond, HI_NULL); +void main_process(void) +{ + /* main loop */ + while (!g_terminate) { + sample_message_s message; + pthread_mutex_lock(&g_sample_link->mut); + while (sample_dequeue(&g_sample_link->cmd_queue, &message) != HI_SUCCESS) { + pthread_cond_wait(&g_sample_link->cond, &g_sample_link->mut); + } + pthread_mutex_unlock(&g_sample_link->mut); + sample_log_print("=====SAMPLE LOOP RECIEVE MSG:%d LEN:%d=====\n", message.what, message.len); + fflush(stdout); - if (sample_wlan_init_up() != HI_SUCCESS) { - sample_log_print("sample_wlan_init_up is fail\n"); - } + switch (message.what) { + case SAMPLE_CMD_HELP: + sample_usage(); + break; + case SAMPLE_CMD_EXIT: + g_terminate = HI_TRUE; + break; + case SAMPLE_CMD_IOCTL: + if (hi_channel_send_to_dev(message.obj, message.len) != HI_SUCCESS) { + sample_log_print("sample_iwpriv_cmd send fail\n"); + } + break; + default: + break; + } + } +} - if (hi_channel_init() != HI_SUCCESS) { - sample_log_print("hi_channel_init is fail\n"); - } +int main(int argc, char *argv[]) +{ + hi_s32 ret; + sample_unused(argc); + sample_unused(argv); + set_lo_ipaddr(); - hi_channel_register_rx_cb(sample_link_rec_cb); - hi_channel_send_to_dev((hi_u8 *)host_cmd[HOST_CMD_GET_MAC], - (hi_s32)strlen(host_cmd[HOST_CMD_GET_MAC])); + signal(SIGINT, sample_terminate); + signal(SIGTERM, sample_terminate); + signal(SIGPWR, sample_power); - if (sample_register_cmd((sample_cmd_entry_stru *)&g_sample_cmd, - SAMPLE_CMD_NUM) != HI_SUCCESS) { - sample_log_print("register wlan cmd is fail\n"); - goto link_out; - } + g_sample_link = (sample_link_s *)malloc(sizeof(sample_link_s)); + if (g_sample_link == HI_NULL) { + return -1; + } - if (sample_sock_create() != HI_SUCCESS) { - sample_log_print("create sock is fail\n"); - goto link_out; - } + (void)memset_s(g_sample_link, sizeof(sample_link_s), 0, sizeof(sample_link_s)); + pthread_mutex_init(&g_sample_link->mut, HI_NULL); + pthread_cond_init(&g_sample_link->cond, HI_NULL); - ret = pthread_create(&g_sample_link->sock_thread, HI_NULL, sample_sock_thread, - HI_NULL); - if (ret != HI_SUCCESS) { - sample_log_print("create sock thread is fail\n"); - goto link_out; - } + if (sample_wlan_init_up() != HI_SUCCESS) { + sample_log_print("sample_wlan_init_up is fail\n"); + } - main_process(); + if (hi_channel_init() != HI_SUCCESS) { + sample_log_print("hi_channel_init is fail\n"); + } + + hi_channel_register_rx_cb(sample_link_rec_cb); + hi_channel_send_to_dev((hi_u8 *)host_cmd[HOST_CMD_GET_MAC], (hi_s32)strlen(host_cmd[HOST_CMD_GET_MAC])); + + if (sample_register_cmd((sample_cmd_entry_stru *)&g_sample_cmd, SAMPLE_CMD_NUM) != HI_SUCCESS) { + sample_log_print("register wlan cmd is fail\n"); + goto link_out; + } + + if (sample_sock_create() != HI_SUCCESS) { + sample_log_print("create sock is fail\n"); + goto link_out; + } + + ret = pthread_create(&g_sample_link->sock_thread, HI_NULL, sample_sock_thread, HI_NULL); + if (ret != HI_SUCCESS) { + sample_log_print("create sock thread is fail\n"); + goto link_out; + } + + main_process(); link_out: - sample_cleanup(); - return 0; + sample_cleanup(); + return 0; } + diff --git a/project/app/wifi_app/hisi_tools/app/vlinktest/cJSON.c b/project/app/wifi_app/hisi_tools/app/vlinktest/cJSON.c old mode 100644 new mode 100755 index 8c282309c..030311ce5 --- a/project/app/wifi_app/hisi_tools/app/vlinktest/cJSON.c +++ b/project/app/wifi_app/hisi_tools/app/vlinktest/cJSON.c @@ -32,25 +32,25 @@ #pragma GCC visibility push(default) #endif #if defined(_MSC_VER) -#pragma warning(push) +#pragma warning (push) /* disable warning about single line comments in system headers */ -#pragma warning(disable : 4001) +#pragma warning (disable : 4001) #endif +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include #ifdef ENABLE_LOCALES #include #endif #if defined(_MSC_VER) -#pragma warning(pop) +#pragma warning (pop) #endif #ifdef __GNUC__ #pragma GCC visibility pop @@ -69,8 +69,7 @@ #endif #define false ((cJSON_bool)0) -/* define isnan and isinf for ANSI C, if in C99 or above, isnan and isinf has - * been defined in math.h */ +/* define isnan and isinf for ANSI C, if in C99 or above, isnan and isinf has been defined in math.h */ #ifndef isinf #define isinf(d) (isnan((d - d)) && !isnan(d)) #endif @@ -82,85 +81,98 @@ #ifdef _WIN32 #define NAN sqrt(-1.0) #else -#define NAN 0.0 / 0.0 +#define NAN 0.0/0.0 #endif #endif typedef struct { - const unsigned char *json; - size_t position; + const unsigned char *json; + size_t position; } error; -static error global_error = {NULL, 0}; +static error global_error = { NULL, 0 }; -CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) { - return (const char *)(global_error.json + global_error.position); +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) +{ + return (const char*) (global_error.json + global_error.position); } -CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item) { - if (!cJSON_IsString(item)) { - return NULL; - } +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item) +{ + if (!cJSON_IsString(item)) + { + return NULL; + } - return item->valuestring; + return item->valuestring; } -CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item) { - if (!cJSON_IsNumber(item)) { - return (double)NAN; - } +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item) +{ + if (!cJSON_IsNumber(item)) + { + return (double) NAN; + } - return item->valuedouble; + return item->valuedouble; } -/* This is a safeguard to prevent copy-pasters from using incompatible C and - * header files */ -#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || \ - (CJSON_VERSION_PATCH != 14) -#error cJSON.h and cJSON.c have different versions. Make sure that both have the same. +/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ +#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 14) + #error cJSON.h and cJSON.c have different versions. Make sure that both have the same. #endif -CJSON_PUBLIC(const char *) cJSON_Version(void) { - static char version[15]; - sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, - CJSON_VERSION_PATCH); +CJSON_PUBLIC(const char*) cJSON_Version(void) +{ + static char version[15]; + sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); - return version; + return version; } -/* Case insensitive string comparison, doesn't consider two NULL pointers equal - * though */ -static int case_insensitive_strcmp(const unsigned char *string1, - const unsigned char *string2) { - if ((string1 == NULL) || (string2 == NULL)) { - return 1; - } - - if (string1 == string2) { - return 0; - } - - for (; tolower(*string1) == tolower(*string2); (void)string1++, string2++) { - if (*string1 == '\0') { - return 0; +/* Case insensitive string comparison, doesn't consider two NULL pointers equal though */ +static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) +{ + if ((string1 == NULL) || (string2 == NULL)) + { + return 1; } - } - return tolower(*string1) - tolower(*string2); + if (string1 == string2) + { + return 0; + } + + for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++) + { + if (*string1 == '\0') + { + return 0; + } + } + + return tolower(*string1) - tolower(*string2); } -typedef struct internal_hooks { - void *(CJSON_CDECL *allocate)(size_t size); - void(CJSON_CDECL *deallocate)(void *pointer); - void *(CJSON_CDECL *reallocate)(void *pointer, size_t size); +typedef struct internal_hooks +{ + void *(CJSON_CDECL *allocate)(size_t size); + void (CJSON_CDECL *deallocate)(void *pointer); + void *(CJSON_CDECL *reallocate)(void *pointer, size_t size); } internal_hooks; #if defined(_MSC_VER) -/* work around MSVC error C2322: '...' address of dllimport '...' is not static - */ -static void *CJSON_CDECL internal_malloc(size_t size) { return malloc(size); } -static void CJSON_CDECL internal_free(void *pointer) { free(pointer); } -static void *CJSON_CDECL internal_realloc(void *pointer, size_t size) { - return realloc(pointer, size); +/* work around MSVC error C2322: '...' address of dllimport '...' is not static */ +static void * CJSON_CDECL internal_malloc(size_t size) +{ + return malloc(size); +} +static void CJSON_CDECL internal_free(void *pointer) +{ + free(pointer); +} +static void * CJSON_CDECL internal_realloc(void *pointer, size_t size) +{ + return realloc(pointer, size); } #else #define internal_malloc malloc @@ -171,2617 +183,2928 @@ static void *CJSON_CDECL internal_realloc(void *pointer, size_t size) { /* strlen of character literals resolved at compile time */ #define static_strlen(string_literal) (sizeof(string_literal) - sizeof("")) -static internal_hooks global_hooks = {internal_malloc, internal_free, - internal_realloc}; +static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc }; -static unsigned char *cJSON_strdup(const unsigned char *string, - const internal_hooks *const hooks) { - size_t length = 0; - unsigned char *copy = NULL; +static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) +{ + size_t length = 0; + unsigned char *copy = NULL; - if (string == NULL) { - return NULL; - } + if (string == NULL) + { + return NULL; + } - length = strlen((const char *)string) + sizeof(""); - copy = (unsigned char *)hooks->allocate(length); - if (copy == NULL) { - return NULL; - } - memcpy(copy, string, length); + length = strlen((const char*)string) + sizeof(""); + copy = (unsigned char*)hooks->allocate(length); + if (copy == NULL) + { + return NULL; + } + memcpy(copy, string, length); - return copy; + return copy; } -CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks) { - if (hooks == NULL) { - /* Reset hooks */ +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) +{ + if (hooks == NULL) + { + /* Reset hooks */ + global_hooks.allocate = malloc; + global_hooks.deallocate = free; + global_hooks.reallocate = realloc; + return; + } + global_hooks.allocate = malloc; + if (hooks->malloc_fn != NULL) + { + global_hooks.allocate = hooks->malloc_fn; + } + global_hooks.deallocate = free; - global_hooks.reallocate = realloc; - return; - } + if (hooks->free_fn != NULL) + { + global_hooks.deallocate = hooks->free_fn; + } - global_hooks.allocate = malloc; - if (hooks->malloc_fn != NULL) { - global_hooks.allocate = hooks->malloc_fn; - } - - global_hooks.deallocate = free; - if (hooks->free_fn != NULL) { - global_hooks.deallocate = hooks->free_fn; - } - - /* use realloc only if both free and malloc are used */ - global_hooks.reallocate = NULL; - if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) { - global_hooks.reallocate = realloc; - } + /* use realloc only if both free and malloc are used */ + global_hooks.reallocate = NULL; + if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) + { + global_hooks.reallocate = realloc; + } } /* Internal constructor. */ -static cJSON *cJSON_New_Item(const internal_hooks *const hooks) { - cJSON *node = (cJSON *)hooks->allocate(sizeof(cJSON)); - if (node) { - memset(node, '\0', sizeof(cJSON)); - } +static cJSON *cJSON_New_Item(const internal_hooks * const hooks) +{ + cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); + if (node) + { + memset(node, '\0', sizeof(cJSON)); + } - return node; + return node; } /* Delete a cJSON structure. */ -CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) { - cJSON *next = NULL; - while (item != NULL) { - next = item->next; - if (!(item->type & cJSON_IsReference) && (item->child != NULL)) { - cJSON_Delete(item->child); +CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) +{ + cJSON *next = NULL; + while (item != NULL) + { + next = item->next; + if (!(item->type & cJSON_IsReference) && (item->child != NULL)) + { + cJSON_Delete(item->child); + } + if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) + { + global_hooks.deallocate(item->valuestring); + } + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + global_hooks.deallocate(item->string); + } + global_hooks.deallocate(item); + item = next; } - if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) { - global_hooks.deallocate(item->valuestring); - } - if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) { - global_hooks.deallocate(item->string); - } - global_hooks.deallocate(item); - item = next; - } } /* get the decimal point character of the current locale */ -static unsigned char get_decimal_point(void) { +static unsigned char get_decimal_point(void) +{ #ifdef ENABLE_LOCALES - struct lconv *lconv = localeconv(); - return (unsigned char)lconv->decimal_point[0]; + struct lconv *lconv = localeconv(); + return (unsigned char) lconv->decimal_point[0]; #else - return '.'; + return '.'; #endif } -typedef struct { - const unsigned char *content; - size_t length; - size_t offset; - size_t depth; /* How deeply nested (in arrays/objects) is the input at the - current offset. */ - internal_hooks hooks; +typedef struct +{ + const unsigned char *content; + size_t length; + size_t offset; + size_t depth; /* How deeply nested (in arrays/objects) is the input at the current offset. */ + internal_hooks hooks; } parse_buffer; -/* check if the given size is left to read in a given parse buffer (starting - * with 1) */ -#define can_read(buffer, size) \ - ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) +/* check if the given size is left to read in a given parse buffer (starting with 1) */ +#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) /* check if the buffer can be accessed at the given index (starting with 0) */ -#define can_access_at_index(buffer, index) \ - ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) -#define cannot_access_at_index(buffer, index) \ - (!can_access_at_index(buffer, index)) +#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) +#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index)) /* get a pointer to the buffer at the position */ #define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) -/* Parse the input text to generate a number, and populate the result into item. - */ -static cJSON_bool parse_number(cJSON *const item, - parse_buffer *const input_buffer) { - double number = 0; - unsigned char *after_end = NULL; - unsigned char number_c_string[64]; - unsigned char decimal_point = get_decimal_point(); - size_t i = 0; +/* Parse the input text to generate a number, and populate the result into item. */ +static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) +{ + double number = 0; + unsigned char *after_end = NULL; + unsigned char number_c_string[64]; + unsigned char decimal_point = get_decimal_point(); + size_t i = 0; - if ((input_buffer == NULL) || (input_buffer->content == NULL)) { - return false; - } - - /* copy the number into a temporary buffer and replace '.' with the decimal - * point of the current locale (for strtod) This also takes care of '\0' not - * necessarily being available for marking the end of the input */ - for (i = 0; (i < (sizeof(number_c_string) - 1)) && - can_access_at_index(input_buffer, i); - i++) { - switch (buffer_at_offset(input_buffer)[i]) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '+': - case '-': - case 'e': - case 'E': - number_c_string[i] = buffer_at_offset(input_buffer)[i]; - break; - - case '.': - number_c_string[i] = decimal_point; - break; - - default: - goto loop_end; + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; + } + + /* copy the number into a temporary buffer and replace '.' with the decimal point + * of the current locale (for strtod) + * This also takes care of '\0' not necessarily being available for marking the end of the input */ + for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) + { + switch (buffer_at_offset(input_buffer)[i]) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '+': + case '-': + case 'e': + case 'E': + number_c_string[i] = buffer_at_offset(input_buffer)[i]; + break; + + case '.': + number_c_string[i] = decimal_point; + break; + + default: + goto loop_end; + } } - } loop_end: - number_c_string[i] = '\0'; + number_c_string[i] = '\0'; - number = strtod((const char *)number_c_string, (char **)&after_end); - if (number_c_string == after_end) { - return false; /* parse_error */ - } + number = strtod((const char*)number_c_string, (char**)&after_end); + if (number_c_string == after_end) + { + return false; /* parse_error */ + } - item->valuedouble = number; + item->valuedouble = number; - /* use saturation in case of overflow */ - if (number >= INT_MAX) { - item->valueint = INT_MAX; - } else if (number <= (double)INT_MIN) { - item->valueint = INT_MIN; - } else { - item->valueint = (int)number; - } + /* use saturation in case of overflow */ + if (number >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (number <= (double)INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)number; + } - item->type = cJSON_Number; + item->type = cJSON_Number; - input_buffer->offset += (size_t)(after_end - number_c_string); - return true; + input_buffer->offset += (size_t)(after_end - number_c_string); + return true; } -/* don't ask me, but the original cJSON_SetNumberValue returns an integer or - * double */ -CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) { - if (number >= INT_MAX) { - object->valueint = INT_MAX; - } else if (number <= (double)INT_MIN) { - object->valueint = INT_MIN; - } else { - object->valueint = (int)number; - } +/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) +{ + if (number >= INT_MAX) + { + object->valueint = INT_MAX; + } + else if (number <= (double)INT_MIN) + { + object->valueint = INT_MIN; + } + else + { + object->valueint = (int)number; + } - return object->valuedouble = number; + return object->valuedouble = number; } -CJSON_PUBLIC(char *) -cJSON_SetValuestring(cJSON *object, const char *valuestring) { - char *copy = NULL; - /* if object's type is not cJSON_String or is cJSON_IsReference, it should not - * set valuestring */ - if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) { - return NULL; - } - if (strlen(valuestring) <= strlen(object->valuestring)) { - strcpy(object->valuestring, valuestring); - return object->valuestring; - } - copy = - (char *)cJSON_strdup((const unsigned char *)valuestring, &global_hooks); - if (copy == NULL) { - return NULL; - } - if (object->valuestring != NULL) { - cJSON_free(object->valuestring); - } - object->valuestring = copy; +CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring) +{ + char *copy = NULL; + /* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */ + if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) + { + return NULL; + } + if (strlen(valuestring) <= strlen(object->valuestring)) + { + strcpy(object->valuestring, valuestring); + return object->valuestring; + } + copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks); + if (copy == NULL) + { + return NULL; + } + if (object->valuestring != NULL) + { + cJSON_free(object->valuestring); + } + object->valuestring = copy; - return copy; + return copy; } -typedef struct { - unsigned char *buffer; - size_t length; - size_t offset; - size_t depth; /* current nesting depth (for formatted printing) */ - cJSON_bool noalloc; - cJSON_bool format; /* is this print a formatted print */ - internal_hooks hooks; +typedef struct +{ + unsigned char *buffer; + size_t length; + size_t offset; + size_t depth; /* current nesting depth (for formatted printing) */ + cJSON_bool noalloc; + cJSON_bool format; /* is this print a formatted print */ + internal_hooks hooks; } printbuffer; /* realloc printbuffer if necessary to have at least "needed" bytes more */ -static unsigned char *ensure(printbuffer *const p, size_t needed) { - unsigned char *newbuffer = NULL; - size_t newsize = 0; +static unsigned char* ensure(printbuffer * const p, size_t needed) +{ + unsigned char *newbuffer = NULL; + size_t newsize = 0; - if ((p == NULL) || (p->buffer == NULL)) { - return NULL; - } - - if ((p->length > 0) && (p->offset >= p->length)) { - /* make sure that offset is valid */ - return NULL; - } - - if (needed > INT_MAX) { - /* sizes bigger than INT_MAX are currently not supported */ - return NULL; - } - - needed += p->offset + 1; - if (needed <= p->length) { - return p->buffer + p->offset; - } - - if (p->noalloc) { - return NULL; - } - - /* calculate new buffer size */ - if (needed > (INT_MAX / 2)) { - /* overflow of int, use INT_MAX if possible */ - if (needed <= INT_MAX) { - newsize = INT_MAX; - } else { - return NULL; - } - } else { - newsize = needed * 2; - } - - if (p->hooks.reallocate != NULL) { - /* reallocate with realloc if available */ - newbuffer = (unsigned char *)p->hooks.reallocate(p->buffer, newsize); - if (newbuffer == NULL) { - p->hooks.deallocate(p->buffer); - p->length = 0; - p->buffer = NULL; - - return NULL; - } - } else { - /* otherwise reallocate manually */ - newbuffer = (unsigned char *)p->hooks.allocate(newsize); - if (!newbuffer) { - p->hooks.deallocate(p->buffer); - p->length = 0; - p->buffer = NULL; - - return NULL; + if ((p == NULL) || (p->buffer == NULL)) + { + return NULL; } - memcpy(newbuffer, p->buffer, p->offset + 1); - p->hooks.deallocate(p->buffer); - } - p->length = newsize; - p->buffer = newbuffer; + if ((p->length > 0) && (p->offset >= p->length)) + { + /* make sure that offset is valid */ + return NULL; + } - return newbuffer + p->offset; + if (needed > INT_MAX) + { + /* sizes bigger than INT_MAX are currently not supported */ + return NULL; + } + + needed += p->offset + 1; + if (needed <= p->length) + { + return p->buffer + p->offset; + } + + if (p->noalloc) { + return NULL; + } + + /* calculate new buffer size */ + if (needed > (INT_MAX / 2)) + { + /* overflow of int, use INT_MAX if possible */ + if (needed <= INT_MAX) + { + newsize = INT_MAX; + } + else + { + return NULL; + } + } + else + { + newsize = needed * 2; + } + + if (p->hooks.reallocate != NULL) + { + /* reallocate with realloc if available */ + newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); + if (newbuffer == NULL) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + } + else + { + /* otherwise reallocate manually */ + newbuffer = (unsigned char*)p->hooks.allocate(newsize); + if (!newbuffer) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + + memcpy(newbuffer, p->buffer, p->offset + 1); + p->hooks.deallocate(p->buffer); + } + p->length = newsize; + p->buffer = newbuffer; + + return newbuffer + p->offset; } -/* calculate the new length of the string in a printbuffer and update the offset - */ -static void update_offset(printbuffer *const buffer) { - const unsigned char *buffer_pointer = NULL; - if ((buffer == NULL) || (buffer->buffer == NULL)) { - return; - } - buffer_pointer = buffer->buffer + buffer->offset; +/* calculate the new length of the string in a printbuffer and update the offset */ +static void update_offset(printbuffer * const buffer) +{ + const unsigned char *buffer_pointer = NULL; + if ((buffer == NULL) || (buffer->buffer == NULL)) + { + return; + } + buffer_pointer = buffer->buffer + buffer->offset; - buffer->offset += strlen((const char *)buffer_pointer); + buffer->offset += strlen((const char*)buffer_pointer); } /* securely comparison of floating-point variables */ -static cJSON_bool compare_double(double a, double b) { - double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b); - return (fabs(a - b) <= maxVal * DBL_EPSILON); +static cJSON_bool compare_double(double a, double b) +{ + double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b); + return (fabs(a - b) <= maxVal * DBL_EPSILON); } /* Render the number nicely from the given item into a string. */ -static cJSON_bool print_number(const cJSON *const item, - printbuffer *const output_buffer) { - unsigned char *output_pointer = NULL; - double d = item->valuedouble; - int length = 0; - size_t i = 0; - unsigned char number_buffer[26] = { - 0}; /* temporary buffer to print the number into */ - unsigned char decimal_point = get_decimal_point(); - double test = 0.0; +static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + double d = item->valuedouble; + int length = 0; + size_t i = 0; + unsigned char number_buffer[26] = {0}; /* temporary buffer to print the number into */ + unsigned char decimal_point = get_decimal_point(); + double test = 0.0; - if (output_buffer == NULL) { - return false; - } - - /* This checks for NaN and Infinity */ - if (isnan(d) || isinf(d)) { - length = sprintf((char *)number_buffer, "null"); - } else { - /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits - */ - length = sprintf((char *)number_buffer, "%1.15g", d); - - /* Check whether the original double can be recovered */ - if ((sscanf((char *)number_buffer, "%lg", &test) != 1) || - !compare_double((double)test, d)) { - /* If not, print with 17 decimal places of precision */ - length = sprintf((char *)number_buffer, "%1.17g", d); - } - } - - /* sprintf failed or buffer overrun occurred */ - if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) { - return false; - } - - /* reserve appropriate space in the output */ - output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); - if (output_pointer == NULL) { - return false; - } - - /* copy the printed number to the output and replace locale - * dependent decimal point with '.' */ - for (i = 0; i < ((size_t)length); i++) { - if (number_buffer[i] == decimal_point) { - output_pointer[i] = '.'; - continue; + if (output_buffer == NULL) + { + return false; } - output_pointer[i] = number_buffer[i]; - } - output_pointer[i] = '\0'; + /* This checks for NaN and Infinity */ + if (isnan(d) || isinf(d)) + { + length = sprintf((char*)number_buffer, "null"); + } + else + { + /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */ + length = sprintf((char*)number_buffer, "%1.15g", d); - output_buffer->offset += (size_t)length; + /* Check whether the original double can be recovered */ + if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d)) + { + /* If not, print with 17 decimal places of precision */ + length = sprintf((char*)number_buffer, "%1.17g", d); + } + } - return true; + /* sprintf failed or buffer overrun occurred */ + if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) + { + return false; + } + + /* reserve appropriate space in the output */ + output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); + if (output_pointer == NULL) + { + return false; + } + + /* copy the printed number to the output and replace locale + * dependent decimal point with '.' */ + for (i = 0; i < ((size_t)length); i++) + { + if (number_buffer[i] == decimal_point) + { + output_pointer[i] = '.'; + continue; + } + + output_pointer[i] = number_buffer[i]; + } + output_pointer[i] = '\0'; + + output_buffer->offset += (size_t)length; + + return true; } /* parse 4 digit hexadecimal number */ -static unsigned parse_hex4(const unsigned char *const input) { - unsigned int h = 0; - size_t i = 0; +static unsigned parse_hex4(const unsigned char * const input) +{ + unsigned int h = 0; + size_t i = 0; - for (i = 0; i < 4; i++) { - /* parse digit */ - if ((input[i] >= '0') && (input[i] <= '9')) { - h += (unsigned int)input[i] - '0'; - } else if ((input[i] >= 'A') && (input[i] <= 'F')) { - h += (unsigned int)10 + input[i] - 'A'; - } else if ((input[i] >= 'a') && (input[i] <= 'f')) { - h += (unsigned int)10 + input[i] - 'a'; - } else /* invalid */ + for (i = 0; i < 4; i++) { - return 0; + /* parse digit */ + if ((input[i] >= '0') && (input[i] <= '9')) + { + h += (unsigned int) input[i] - '0'; + } + else if ((input[i] >= 'A') && (input[i] <= 'F')) + { + h += (unsigned int) 10 + input[i] - 'A'; + } + else if ((input[i] >= 'a') && (input[i] <= 'f')) + { + h += (unsigned int) 10 + input[i] - 'a'; + } + else /* invalid */ + { + return 0; + } + + if (i < 3) + { + /* shift left to make place for the next nibble */ + h = h << 4; + } } - if (i < 3) { - /* shift left to make place for the next nibble */ - h = h << 4; - } - } - - return h; + return h; } /* converts a UTF-16 literal to UTF-8 * A literal can be one or two sequences of the form \uXXXX */ -static unsigned char -utf16_literal_to_utf8(const unsigned char *const input_pointer, - const unsigned char *const input_end, - unsigned char **output_pointer) { - long unsigned int codepoint = 0; - unsigned int first_code = 0; - const unsigned char *first_sequence = input_pointer; - unsigned char utf8_length = 0; - unsigned char utf8_position = 0; - unsigned char sequence_length = 0; - unsigned char first_byte_mark = 0; +static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer) +{ + long unsigned int codepoint = 0; + unsigned int first_code = 0; + const unsigned char *first_sequence = input_pointer; + unsigned char utf8_length = 0; + unsigned char utf8_position = 0; + unsigned char sequence_length = 0; + unsigned char first_byte_mark = 0; - if ((input_end - first_sequence) < 6) { - /* input ends unexpectedly */ - goto fail; - } - - /* get the first utf16 sequence */ - first_code = parse_hex4(first_sequence + 2); - - /* check that the code is valid */ - if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) { - goto fail; - } - - /* UTF16 surrogate pair */ - if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) { - const unsigned char *second_sequence = first_sequence + 6; - unsigned int second_code = 0; - sequence_length = 12; /* \uXXXX\uXXXX */ - - if ((input_end - second_sequence) < 6) { - /* input ends unexpectedly */ - goto fail; + if ((input_end - first_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; } - if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) { - /* missing second half of the surrogate pair */ - goto fail; - } + /* get the first utf16 sequence */ + first_code = parse_hex4(first_sequence + 2); - /* get the second utf16 sequence */ - second_code = parse_hex4(second_sequence + 2); /* check that the code is valid */ - if ((second_code < 0xDC00) || (second_code > 0xDFFF)) { - /* invalid second half of the surrogate pair */ - goto fail; + if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) + { + goto fail; } - /* calculate the unicode codepoint from the surrogate pair */ - codepoint = - 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); - } else { - sequence_length = 6; /* \uXXXX */ - codepoint = first_code; - } + /* UTF16 surrogate pair */ + if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) + { + const unsigned char *second_sequence = first_sequence + 6; + unsigned int second_code = 0; + sequence_length = 12; /* \uXXXX\uXXXX */ - /* encode as UTF-8 - * takes at maximum 4 bytes to encode: - * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ - if (codepoint < 0x80) { - /* normal ascii, encoding 0xxxxxxx */ - utf8_length = 1; - } else if (codepoint < 0x800) { - /* two bytes, encoding 110xxxxx 10xxxxxx */ - utf8_length = 2; - first_byte_mark = 0xC0; /* 11000000 */ - } else if (codepoint < 0x10000) { - /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ - utf8_length = 3; - first_byte_mark = 0xE0; /* 11100000 */ - } else if (codepoint <= 0x10FFFF) { - /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ - utf8_length = 4; - first_byte_mark = 0xF0; /* 11110000 */ - } else { - /* invalid unicode codepoint */ - goto fail; - } + if ((input_end - second_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; + } - /* encode as utf8 */ - for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; - utf8_position--) { - /* 10xxxxxx */ - (*output_pointer)[utf8_position] = - (unsigned char)((codepoint | 0x80) & 0xBF); - codepoint >>= 6; - } - /* encode first byte */ - if (utf8_length > 1) { - (*output_pointer)[0] = - (unsigned char)((codepoint | first_byte_mark) & 0xFF); - } else { - (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); - } + if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) + { + /* missing second half of the surrogate pair */ + goto fail; + } - *output_pointer += utf8_length; + /* get the second utf16 sequence */ + second_code = parse_hex4(second_sequence + 2); + /* check that the code is valid */ + if ((second_code < 0xDC00) || (second_code > 0xDFFF)) + { + /* invalid second half of the surrogate pair */ + goto fail; + } - return sequence_length; + + /* calculate the unicode codepoint from the surrogate pair */ + codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); + } + else + { + sequence_length = 6; /* \uXXXX */ + codepoint = first_code; + } + + /* encode as UTF-8 + * takes at maximum 4 bytes to encode: + * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + if (codepoint < 0x80) + { + /* normal ascii, encoding 0xxxxxxx */ + utf8_length = 1; + } + else if (codepoint < 0x800) + { + /* two bytes, encoding 110xxxxx 10xxxxxx */ + utf8_length = 2; + first_byte_mark = 0xC0; /* 11000000 */ + } + else if (codepoint < 0x10000) + { + /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ + utf8_length = 3; + first_byte_mark = 0xE0; /* 11100000 */ + } + else if (codepoint <= 0x10FFFF) + { + /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + utf8_length = 4; + first_byte_mark = 0xF0; /* 11110000 */ + } + else + { + /* invalid unicode codepoint */ + goto fail; + } + + /* encode as utf8 */ + for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) + { + /* 10xxxxxx */ + (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF); + codepoint >>= 6; + } + /* encode first byte */ + if (utf8_length > 1) + { + (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF); + } + else + { + (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); + } + + *output_pointer += utf8_length; + + return sequence_length; fail: - return 0; + return 0; } /* Parse the input text into an unescaped cinput, and populate item. */ -static cJSON_bool parse_string(cJSON *const item, - parse_buffer *const input_buffer) { - const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; - const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; - unsigned char *output_pointer = NULL; - unsigned char *output = NULL; +static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) +{ + const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; + const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; + unsigned char *output_pointer = NULL; + unsigned char *output = NULL; - /* not a string */ - if (buffer_at_offset(input_buffer)[0] != '\"') { - goto fail; - } - - { - /* calculate approximate size of the output (overestimate) */ - size_t allocation_length = 0; - size_t skipped_bytes = 0; - while ( - ((size_t)(input_end - input_buffer->content) < input_buffer->length) && - (*input_end != '\"')) { - /* is escape sequence */ - if (input_end[0] == '\\') { - if ((size_t)(input_end + 1 - input_buffer->content) >= - input_buffer->length) { - /* prevent buffer overflow when last input character is a backslash */ - goto fail; - } - skipped_bytes++; - input_end++; - } - input_end++; - } - if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || - (*input_end != '\"')) { - goto fail; /* string ended unexpectedly */ - } - - /* This is at most how much we need for the output */ - allocation_length = - (size_t)(input_end - buffer_at_offset(input_buffer)) - skipped_bytes; - output = (unsigned char *)input_buffer->hooks.allocate(allocation_length + - sizeof("")); - if (output == NULL) { - goto fail; /* allocation failure */ - } - } - - output_pointer = output; - /* loop through the string literal */ - while (input_pointer < input_end) { - if (*input_pointer != '\\') { - *output_pointer++ = *input_pointer++; - } - /* escape sequence */ - else { - unsigned char sequence_length = 2; - if ((input_end - input_pointer) < 1) { + /* not a string */ + if (buffer_at_offset(input_buffer)[0] != '\"') + { goto fail; - } - - switch (input_pointer[1]) { - case 'b': - *output_pointer++ = '\b'; - break; - case 'f': - *output_pointer++ = '\f'; - break; - case 'n': - *output_pointer++ = '\n'; - break; - case 'r': - *output_pointer++ = '\r'; - break; - case 't': - *output_pointer++ = '\t'; - break; - case '\"': - case '\\': - case '/': - *output_pointer++ = input_pointer[1]; - break; - - /* UTF-16 literal */ - case 'u': - sequence_length = - utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); - if (sequence_length == 0) { - /* failed to convert UTF16-literal to UTF-8 */ - goto fail; - } - break; - - default: - goto fail; - } - input_pointer += sequence_length; } - } - /* zero terminate the output */ - *output_pointer = '\0'; + { + /* calculate approximate size of the output (overestimate) */ + size_t allocation_length = 0; + size_t skipped_bytes = 0; + while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) + { + /* is escape sequence */ + if (input_end[0] == '\\') + { + if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) + { + /* prevent buffer overflow when last input character is a backslash */ + goto fail; + } + skipped_bytes++; + input_end++; + } + input_end++; + } + if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) + { + goto fail; /* string ended unexpectedly */ + } - item->type = cJSON_String; - item->valuestring = (char *)output; + /* This is at most how much we need for the output */ + allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes; + output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof("")); + if (output == NULL) + { + goto fail; /* allocation failure */ + } + } - input_buffer->offset = (size_t)(input_end - input_buffer->content); - input_buffer->offset++; + output_pointer = output; + /* loop through the string literal */ + while (input_pointer < input_end) + { + if (*input_pointer != '\\') + { + *output_pointer++ = *input_pointer++; + } + /* escape sequence */ + else + { + unsigned char sequence_length = 2; + if ((input_end - input_pointer) < 1) + { + goto fail; + } - return true; + switch (input_pointer[1]) + { + case 'b': + *output_pointer++ = '\b'; + break; + case 'f': + *output_pointer++ = '\f'; + break; + case 'n': + *output_pointer++ = '\n'; + break; + case 'r': + *output_pointer++ = '\r'; + break; + case 't': + *output_pointer++ = '\t'; + break; + case '\"': + case '\\': + case '/': + *output_pointer++ = input_pointer[1]; + break; + + /* UTF-16 literal */ + case 'u': + sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); + if (sequence_length == 0) + { + /* failed to convert UTF16-literal to UTF-8 */ + goto fail; + } + break; + + default: + goto fail; + } + input_pointer += sequence_length; + } + } + + /* zero terminate the output */ + *output_pointer = '\0'; + + item->type = cJSON_String; + item->valuestring = (char*)output; + + input_buffer->offset = (size_t) (input_end - input_buffer->content); + input_buffer->offset++; + + return true; fail: - if (output != NULL) { - input_buffer->hooks.deallocate(output); - } + if (output != NULL) + { + input_buffer->hooks.deallocate(output); + } - if (input_pointer != NULL) { - input_buffer->offset = (size_t)(input_pointer - input_buffer->content); - } + if (input_pointer != NULL) + { + input_buffer->offset = (size_t)(input_pointer - input_buffer->content); + } - return false; + return false; } /* Render the cstring provided to an escaped version that can be printed. */ -static cJSON_bool print_string_ptr(const unsigned char *const input, - printbuffer *const output_buffer) { - const unsigned char *input_pointer = NULL; - unsigned char *output = NULL; - unsigned char *output_pointer = NULL; - size_t output_length = 0; - /* numbers of additional characters needed for escaping */ - size_t escape_characters = 0; +static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer) +{ + const unsigned char *input_pointer = NULL; + unsigned char *output = NULL; + unsigned char *output_pointer = NULL; + size_t output_length = 0; + /* numbers of additional characters needed for escaping */ + size_t escape_characters = 0; - if (output_buffer == NULL) { - return false; - } - - /* empty string */ - if (input == NULL) { - output = ensure(output_buffer, sizeof("\"\"")); - if (output == NULL) { - return false; + if (output_buffer == NULL) + { + return false; } - strcpy((char *)output, "\"\""); - return true; - } + /* empty string */ + if (input == NULL) + { + output = ensure(output_buffer, sizeof("\"\"")); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "\"\""); - /* set "flag" to 1 if something needs to be escaped */ - for (input_pointer = input; *input_pointer; input_pointer++) { - switch (*input_pointer) { - case '\"': - case '\\': - case '\b': - case '\f': - case '\n': - case '\r': - case '\t': - /* one character escape sequence */ - escape_characters++; - break; - default: - if (*input_pointer < 32) { - /* UTF-16 escape sequence uXXXX */ - escape_characters += 5; - } - break; + return true; } - } - output_length = (size_t)(input_pointer - input) + escape_characters; - output = ensure(output_buffer, output_length + sizeof("\"\"")); - if (output == NULL) { - return false; - } + /* set "flag" to 1 if something needs to be escaped */ + for (input_pointer = input; *input_pointer; input_pointer++) + { + switch (*input_pointer) + { + case '\"': + case '\\': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + /* one character escape sequence */ + escape_characters++; + break; + default: + if (*input_pointer < 32) + { + /* UTF-16 escape sequence uXXXX */ + escape_characters += 5; + } + break; + } + } + output_length = (size_t)(input_pointer - input) + escape_characters; + + output = ensure(output_buffer, output_length + sizeof("\"\"")); + if (output == NULL) + { + return false; + } + + /* no characters have to be escaped */ + if (escape_characters == 0) + { + output[0] = '\"'; + memcpy(output + 1, input, output_length); + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; + } - /* no characters have to be escaped */ - if (escape_characters == 0) { output[0] = '\"'; - memcpy(output + 1, input, output_length); + output_pointer = output + 1; + /* copy the string */ + for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) + { + if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) + { + /* normal character, copy */ + *output_pointer = *input_pointer; + } + else + { + /* character needs to be escaped */ + *output_pointer++ = '\\'; + switch (*input_pointer) + { + case '\\': + *output_pointer = '\\'; + break; + case '\"': + *output_pointer = '\"'; + break; + case '\b': + *output_pointer = 'b'; + break; + case '\f': + *output_pointer = 'f'; + break; + case '\n': + *output_pointer = 'n'; + break; + case '\r': + *output_pointer = 'r'; + break; + case '\t': + *output_pointer = 't'; + break; + default: + /* escape and print as unicode codepoint */ + sprintf((char*)output_pointer, "u%04x", *input_pointer); + output_pointer += 4; + break; + } + } + } output[output_length + 1] = '\"'; output[output_length + 2] = '\0'; return true; - } - - output[0] = '\"'; - output_pointer = output + 1; - /* copy the string */ - for (input_pointer = input; *input_pointer != '\0'; - (void)input_pointer++, output_pointer++) { - if ((*input_pointer > 31) && (*input_pointer != '\"') && - (*input_pointer != '\\')) { - /* normal character, copy */ - *output_pointer = *input_pointer; - } else { - /* character needs to be escaped */ - *output_pointer++ = '\\'; - switch (*input_pointer) { - case '\\': - *output_pointer = '\\'; - break; - case '\"': - *output_pointer = '\"'; - break; - case '\b': - *output_pointer = 'b'; - break; - case '\f': - *output_pointer = 'f'; - break; - case '\n': - *output_pointer = 'n'; - break; - case '\r': - *output_pointer = 'r'; - break; - case '\t': - *output_pointer = 't'; - break; - default: - /* escape and print as unicode codepoint */ - sprintf((char *)output_pointer, "u%04x", *input_pointer); - output_pointer += 4; - break; - } - } - } - output[output_length + 1] = '\"'; - output[output_length + 2] = '\0'; - - return true; } /* Invoke print_string_ptr (which is useful) on an item. */ -static cJSON_bool print_string(const cJSON *const item, printbuffer *const p) { - return print_string_ptr((unsigned char *)item->valuestring, p); +static cJSON_bool print_string(const cJSON * const item, printbuffer * const p) +{ + return print_string_ptr((unsigned char*)item->valuestring, p); } /* Predeclare these prototypes. */ -static cJSON_bool parse_value(cJSON *const item, - parse_buffer *const input_buffer); -static cJSON_bool print_value(const cJSON *const item, - printbuffer *const output_buffer); -static cJSON_bool parse_array(cJSON *const item, - parse_buffer *const input_buffer); -static cJSON_bool print_array(const cJSON *const item, - printbuffer *const output_buffer); -static cJSON_bool parse_object(cJSON *const item, - parse_buffer *const input_buffer); -static cJSON_bool print_object(const cJSON *const item, - printbuffer *const output_buffer); +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer); /* Utility to jump whitespace and cr/lf */ -static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) { - if ((buffer == NULL) || (buffer->content == NULL)) { - return NULL; - } +static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL)) + { + return NULL; + } + + if (cannot_access_at_index(buffer, 0)) + { + return buffer; + } + + while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) + { + buffer->offset++; + } + + if (buffer->offset == buffer->length) + { + buffer->offset--; + } - if (cannot_access_at_index(buffer, 0)) { return buffer; - } - - while (can_access_at_index(buffer, 0) && - (buffer_at_offset(buffer)[0] <= 32)) { - buffer->offset++; - } - - if (buffer->offset == buffer->length) { - buffer->offset--; - } - - return buffer; } /* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */ -static parse_buffer *skip_utf8_bom(parse_buffer *const buffer) { - if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) { - return NULL; - } +static parse_buffer *skip_utf8_bom(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) + { + return NULL; + } - if (can_access_at_index(buffer, 4) && - (strncmp((const char *)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == - 0)) { - buffer->offset += 3; - } + if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) + { + buffer->offset += 3; + } - return buffer; + return buffer; } -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithOpts(const char *value, const char **return_parse_end, - cJSON_bool require_null_terminated) { - size_t buffer_length; +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) +{ + size_t buffer_length; - if (NULL == value) { - return NULL; - } + if (NULL == value) + { + return NULL; + } - /* Adding null character size due to require_null_terminated. */ - buffer_length = strlen(value) + sizeof(""); + /* Adding null character size due to require_null_terminated. */ + buffer_length = strlen(value) + sizeof(""); - return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, - require_null_terminated); + return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, require_null_terminated); } /* Parse an object - create a new root, and populate. */ -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, - const char **return_parse_end, - cJSON_bool require_null_terminated) { - parse_buffer buffer = {0, 0, 0, 0, {0, 0, 0}}; - cJSON *item = NULL; +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated) +{ + parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; + cJSON *item = NULL; - /* reset error position */ - global_error.json = NULL; - global_error.position = 0; + /* reset error position */ + global_error.json = NULL; + global_error.position = 0; - if (value == NULL || 0 == buffer_length) { - goto fail; - } - - buffer.content = (const unsigned char *)value; - buffer.length = buffer_length; - buffer.offset = 0; - buffer.hooks = global_hooks; - - item = cJSON_New_Item(&global_hooks); - if (item == NULL) /* memory fail */ - { - goto fail; - } - - if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) { - /* parse failure. ep is set. */ - goto fail; - } - - /* if we require null-terminated JSON without appended garbage, skip and then - * check for a null terminator */ - if (require_null_terminated) { - buffer_skip_whitespace(&buffer); - if ((buffer.offset >= buffer.length) || - buffer_at_offset(&buffer)[0] != '\0') { - goto fail; + if (value == NULL || 0 == buffer_length) + { + goto fail; } - } - if (return_parse_end) { - *return_parse_end = (const char *)buffer_at_offset(&buffer); - } - return item; + buffer.content = (const unsigned char*)value; + buffer.length = buffer_length; + buffer.offset = 0; + buffer.hooks = global_hooks; + + item = cJSON_New_Item(&global_hooks); + if (item == NULL) /* memory fail */ + { + goto fail; + } + + if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) + { + /* parse failure. ep is set. */ + goto fail; + } + + /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ + if (require_null_terminated) + { + buffer_skip_whitespace(&buffer); + if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') + { + goto fail; + } + } + if (return_parse_end) + { + *return_parse_end = (const char*)buffer_at_offset(&buffer); + } + + return item; fail: - if (item != NULL) { - cJSON_Delete(item); - } - - if (value != NULL) { - error local_error; - local_error.json = (const unsigned char *)value; - local_error.position = 0; - - if (buffer.offset < buffer.length) { - local_error.position = buffer.offset; - } else if (buffer.length > 0) { - local_error.position = buffer.length - 1; + if (item != NULL) + { + cJSON_Delete(item); } - if (return_parse_end != NULL) { - *return_parse_end = (const char *)local_error.json + local_error.position; + if (value != NULL) + { + error local_error; + local_error.json = (const unsigned char*)value; + local_error.position = 0; + + if (buffer.offset < buffer.length) + { + local_error.position = buffer.offset; + } + else if (buffer.length > 0) + { + local_error.position = buffer.length - 1; + } + + if (return_parse_end != NULL) + { + *return_parse_end = (const char*)local_error.json + local_error.position; + } + + global_error = local_error; } - global_error = local_error; - } - - return NULL; + return NULL; } /* Default options for cJSON_Parse */ -CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) { - return cJSON_ParseWithOpts(value, 0, 0); +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) +{ + return cJSON_ParseWithOpts(value, 0, 0); } -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithLength(const char *value, size_t buffer_length) { - return cJSON_ParseWithLengthOpts(value, buffer_length, 0, 0); +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length) +{ + return cJSON_ParseWithLengthOpts(value, buffer_length, 0, 0); } #define cjson_min(a, b) (((a) < (b)) ? (a) : (b)) -static unsigned char *print(const cJSON *const item, cJSON_bool format, - const internal_hooks *const hooks) { - static const size_t default_buffer_size = 256; - printbuffer buffer[1]; - unsigned char *printed = NULL; +static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) +{ + static const size_t default_buffer_size = 256; + printbuffer buffer[1]; + unsigned char *printed = NULL; - memset(buffer, 0, sizeof(buffer)); + memset(buffer, 0, sizeof(buffer)); - /* create buffer */ - buffer->buffer = (unsigned char *)hooks->allocate(default_buffer_size); - buffer->length = default_buffer_size; - buffer->format = format; - buffer->hooks = *hooks; - if (buffer->buffer == NULL) { - goto fail; - } - - /* print the value */ - if (!print_value(item, buffer)) { - goto fail; - } - update_offset(buffer); - - /* check if reallocate is available */ - if (hooks->reallocate != NULL) { - printed = - (unsigned char *)hooks->reallocate(buffer->buffer, buffer->offset + 1); - if (printed == NULL) { - goto fail; + /* create buffer */ + buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size); + buffer->length = default_buffer_size; + buffer->format = format; + buffer->hooks = *hooks; + if (buffer->buffer == NULL) + { + goto fail; } - buffer->buffer = NULL; - } else /* otherwise copy the JSON over to a new buffer */ - { - printed = (unsigned char *)hooks->allocate(buffer->offset + 1); - if (printed == NULL) { - goto fail; + + /* print the value */ + if (!print_value(item, buffer)) + { + goto fail; } - memcpy(printed, buffer->buffer, - cjson_min(buffer->length, buffer->offset + 1)); - printed[buffer->offset] = '\0'; /* just to be sure */ + update_offset(buffer); - /* free the buffer */ - hooks->deallocate(buffer->buffer); - } + /* check if reallocate is available */ + if (hooks->reallocate != NULL) + { + printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); + if (printed == NULL) { + goto fail; + } + buffer->buffer = NULL; + } + else /* otherwise copy the JSON over to a new buffer */ + { + printed = (unsigned char*) hooks->allocate(buffer->offset + 1); + if (printed == NULL) + { + goto fail; + } + memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); + printed[buffer->offset] = '\0'; /* just to be sure */ - return printed; + /* free the buffer */ + hooks->deallocate(buffer->buffer); + } + + return printed; fail: - if (buffer->buffer != NULL) { - hooks->deallocate(buffer->buffer); - } + if (buffer->buffer != NULL) + { + hooks->deallocate(buffer->buffer); + } - if (printed != NULL) { - hooks->deallocate(printed); - } + if (printed != NULL) + { + hooks->deallocate(printed); + } - return NULL; + return NULL; } /* Render a cJSON item/entity/structure to text. */ -CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) { - return (char *)print(item, true, &global_hooks); +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) +{ + return (char*)print(item, true, &global_hooks); } -CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) { - return (char *)print(item, false, &global_hooks); +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) +{ + return (char*)print(item, false, &global_hooks); } -CJSON_PUBLIC(char *) -cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) { - printbuffer p = {0, 0, 0, 0, 0, 0, {0, 0, 0}}; +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; - if (prebuffer < 0) { - return NULL; - } + if (prebuffer < 0) + { + return NULL; + } - p.buffer = (unsigned char *)global_hooks.allocate((size_t)prebuffer); - if (!p.buffer) { - return NULL; - } + p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); + if (!p.buffer) + { + return NULL; + } - p.length = (size_t)prebuffer; - p.offset = 0; - p.noalloc = false; - p.format = fmt; - p.hooks = global_hooks; + p.length = (size_t)prebuffer; + p.offset = 0; + p.noalloc = false; + p.format = fmt; + p.hooks = global_hooks; - if (!print_value(item, &p)) { - global_hooks.deallocate(p.buffer); - return NULL; - } + if (!print_value(item, &p)) + { + global_hooks.deallocate(p.buffer); + return NULL; + } - return (char *)p.buffer; + return (char*)p.buffer; } -CJSON_PUBLIC(cJSON_bool) -cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, - const cJSON_bool format) { - printbuffer p = {0, 0, 0, 0, 0, 0, {0, 0, 0}}; +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; - if ((length < 0) || (buffer == NULL)) { - return false; - } + if ((length < 0) || (buffer == NULL)) + { + return false; + } - p.buffer = (unsigned char *)buffer; - p.length = (size_t)length; - p.offset = 0; - p.noalloc = true; - p.format = format; - p.hooks = global_hooks; + p.buffer = (unsigned char*)buffer; + p.length = (size_t)length; + p.offset = 0; + p.noalloc = true; + p.format = format; + p.hooks = global_hooks; - return print_value(item, &p); + return print_value(item, &p); } /* Parser core - when encountering text, process appropriately. */ -static cJSON_bool parse_value(cJSON *const item, - parse_buffer *const input_buffer) { - if ((input_buffer == NULL) || (input_buffer->content == NULL)) { - return false; /* no input */ - } +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer) +{ + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; /* no input */ + } - /* parse the different types of values */ - /* null */ - if (can_read(input_buffer, 4) && - (strncmp((const char *)buffer_at_offset(input_buffer), "null", 4) == 0)) { - item->type = cJSON_NULL; - input_buffer->offset += 4; - return true; - } - /* false */ - if (can_read(input_buffer, 5) && - (strncmp((const char *)buffer_at_offset(input_buffer), "false", 5) == - 0)) { - item->type = cJSON_False; - input_buffer->offset += 5; - return true; - } - /* true */ - if (can_read(input_buffer, 4) && - (strncmp((const char *)buffer_at_offset(input_buffer), "true", 4) == 0)) { - item->type = cJSON_True; - item->valueint = 1; - input_buffer->offset += 4; - return true; - } - /* string */ - if (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == '\"')) { - return parse_string(item, input_buffer); - } - /* number */ - if (can_access_at_index(input_buffer, 0) && - ((buffer_at_offset(input_buffer)[0] == '-') || - ((buffer_at_offset(input_buffer)[0] >= '0') && - (buffer_at_offset(input_buffer)[0] <= '9')))) { - return parse_number(item, input_buffer); - } - /* array */ - if (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == '[')) { - return parse_array(item, input_buffer); - } - /* object */ - if (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == '{')) { - return parse_object(item, input_buffer); - } + /* parse the different types of values */ + /* null */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0)) + { + item->type = cJSON_NULL; + input_buffer->offset += 4; + return true; + } + /* false */ + if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0)) + { + item->type = cJSON_False; + input_buffer->offset += 5; + return true; + } + /* true */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "true", 4) == 0)) + { + item->type = cJSON_True; + item->valueint = 1; + input_buffer->offset += 4; + return true; + } + /* string */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) + { + return parse_string(item, input_buffer); + } + /* number */ + if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) + { + return parse_number(item, input_buffer); + } + /* array */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) + { + return parse_array(item, input_buffer); + } + /* object */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) + { + return parse_object(item, input_buffer); + } - return false; + return false; } /* Render a value to text. */ -static cJSON_bool print_value(const cJSON *const item, - printbuffer *const output_buffer) { - unsigned char *output = NULL; +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output = NULL; - if ((item == NULL) || (output_buffer == NULL)) { - return false; - } - - switch ((item->type) & 0xFF) { - case cJSON_NULL: - output = ensure(output_buffer, 5); - if (output == NULL) { - return false; - } - strcpy((char *)output, "null"); - return true; - - case cJSON_False: - output = ensure(output_buffer, 6); - if (output == NULL) { - return false; - } - strcpy((char *)output, "false"); - return true; - - case cJSON_True: - output = ensure(output_buffer, 5); - if (output == NULL) { - return false; - } - strcpy((char *)output, "true"); - return true; - - case cJSON_Number: - return print_number(item, output_buffer); - - case cJSON_Raw: { - size_t raw_length = 0; - if (item->valuestring == NULL) { - return false; + if ((item == NULL) || (output_buffer == NULL)) + { + return false; } - raw_length = strlen(item->valuestring) + sizeof(""); - output = ensure(output_buffer, raw_length); - if (output == NULL) { - return false; + switch ((item->type) & 0xFF) + { + case cJSON_NULL: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "null"); + return true; + + case cJSON_False: + output = ensure(output_buffer, 6); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "false"); + return true; + + case cJSON_True: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "true"); + return true; + + case cJSON_Number: + return print_number(item, output_buffer); + + case cJSON_Raw: + { + size_t raw_length = 0; + if (item->valuestring == NULL) + { + return false; + } + + raw_length = strlen(item->valuestring) + sizeof(""); + output = ensure(output_buffer, raw_length); + if (output == NULL) + { + return false; + } + memcpy(output, item->valuestring, raw_length); + return true; + } + + case cJSON_String: + return print_string(item, output_buffer); + + case cJSON_Array: + return print_array(item, output_buffer); + + case cJSON_Object: + return print_object(item, output_buffer); + + default: + return false; } - memcpy(output, item->valuestring, raw_length); - return true; - } - - case cJSON_String: - return print_string(item, output_buffer); - - case cJSON_Array: - return print_array(item, output_buffer); - - case cJSON_Object: - return print_object(item, output_buffer); - - default: - return false; - } } /* Build an array from input text. */ -static cJSON_bool parse_array(cJSON *const item, - parse_buffer *const input_buffer) { - cJSON *head = NULL; /* head of the linked list */ - cJSON *current_item = NULL; +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) +{ + cJSON *head = NULL; /* head of the linked list */ + cJSON *current_item = NULL; - if (input_buffer->depth >= CJSON_NESTING_LIMIT) { - return false; /* to deeply nested */ - } - input_buffer->depth++; + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; - if (buffer_at_offset(input_buffer)[0] != '[') { - /* not an array */ - goto fail; - } - - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == ']')) { - /* empty array */ - goto success; - } - - /* check if we skipped to the end of the buffer */ - if (cannot_access_at_index(input_buffer, 0)) { - input_buffer->offset--; - goto fail; - } - - /* step back to character in front of the first element */ - input_buffer->offset--; - /* loop through the comma separated array elements */ - do { - /* allocate next item */ - cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); - if (new_item == NULL) { - goto fail; /* allocation failure */ + if (buffer_at_offset(input_buffer)[0] != '[') + { + /* not an array */ + goto fail; } - /* attach next item to list */ - if (head == NULL) { - /* start the linked list */ - current_item = head = new_item; - } else { - /* add to the end and advance */ - current_item->next = new_item; - new_item->prev = current_item; - current_item = new_item; - } - - /* parse next value */ input_buffer->offset++; buffer_skip_whitespace(input_buffer); - if (!parse_value(current_item, input_buffer)) { - goto fail; /* failed to parse value */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) + { + /* empty array */ + goto success; } - buffer_skip_whitespace(input_buffer); - } while (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == ',')); - if (cannot_access_at_index(input_buffer, 0) || - buffer_at_offset(input_buffer)[0] != ']') { - goto fail; /* expected end of array */ - } + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ + input_buffer->offset--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse next value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); + } + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + + if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') + { + goto fail; /* expected end of array */ + } success: - input_buffer->depth--; + input_buffer->depth--; - if (head != NULL) { - head->prev = current_item; - } + if (head != NULL) { + head->prev = current_item; + } - item->type = cJSON_Array; - item->child = head; + item->type = cJSON_Array; + item->child = head; - input_buffer->offset++; + input_buffer->offset++; - return true; + return true; fail: - if (head != NULL) { - cJSON_Delete(head); - } + if (head != NULL) + { + cJSON_Delete(head); + } - return false; + return false; } /* Render an array to text */ -static cJSON_bool print_array(const cJSON *const item, - printbuffer *const output_buffer) { - unsigned char *output_pointer = NULL; - size_t length = 0; - cJSON *current_element = item->child; +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_element = item->child; - if (output_buffer == NULL) { - return false; - } - - /* Compose the output array. */ - /* opening square bracket */ - output_pointer = ensure(output_buffer, 1); - if (output_pointer == NULL) { - return false; - } - - *output_pointer = '['; - output_buffer->offset++; - output_buffer->depth++; - - while (current_element != NULL) { - if (!print_value(current_element, output_buffer)) { - return false; - } - update_offset(output_buffer); - if (current_element->next) { - length = (size_t)(output_buffer->format ? 2 : 1); - output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) { + if (output_buffer == NULL) + { return false; - } - *output_pointer++ = ','; - if (output_buffer->format) { - *output_pointer++ = ' '; - } - *output_pointer = '\0'; - output_buffer->offset += length; } - current_element = current_element->next; - } - output_pointer = ensure(output_buffer, 2); - if (output_pointer == NULL) { - return false; - } - *output_pointer++ = ']'; - *output_pointer = '\0'; - output_buffer->depth--; + /* Compose the output array. */ + /* opening square bracket */ + output_pointer = ensure(output_buffer, 1); + if (output_pointer == NULL) + { + return false; + } - return true; + *output_pointer = '['; + output_buffer->offset++; + output_buffer->depth++; + + while (current_element != NULL) + { + if (!print_value(current_element, output_buffer)) + { + return false; + } + update_offset(output_buffer); + if (current_element->next) + { + length = (size_t) (output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ','; + if(output_buffer->format) + { + *output_pointer++ = ' '; + } + *output_pointer = '\0'; + output_buffer->offset += length; + } + current_element = current_element->next; + } + + output_pointer = ensure(output_buffer, 2); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ']'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; } /* Build an object from the text. */ -static cJSON_bool parse_object(cJSON *const item, - parse_buffer *const input_buffer) { - cJSON *head = NULL; /* linked list head */ - cJSON *current_item = NULL; +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) +{ + cJSON *head = NULL; /* linked list head */ + cJSON *current_item = NULL; - if (input_buffer->depth >= CJSON_NESTING_LIMIT) { - return false; /* to deeply nested */ - } - input_buffer->depth++; + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; - if (cannot_access_at_index(input_buffer, 0) || - (buffer_at_offset(input_buffer)[0] != '{')) { - goto fail; /* not an object */ - } + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) + { + goto fail; /* not an object */ + } - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == '}')) { - goto success; /* empty object */ - } + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) + { + goto success; /* empty object */ + } - /* check if we skipped to the end of the buffer */ - if (cannot_access_at_index(input_buffer, 0)) { + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ input_buffer->offset--; - goto fail; - } + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } - /* step back to character in front of the first element */ - input_buffer->offset--; - /* loop through the comma separated array elements */ - do { - /* allocate next item */ - cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); - if (new_item == NULL) { - goto fail; /* allocation failure */ + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse the name of the child */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_string(current_item, input_buffer)) + { + goto fail; /* failed to parse name */ + } + buffer_skip_whitespace(input_buffer); + + /* swap valuestring and string, because we parsed the name */ + current_item->string = current_item->valuestring; + current_item->valuestring = NULL; + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) + { + goto fail; /* invalid object */ + } + + /* parse the value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); } + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); - /* attach next item to list */ - if (head == NULL) { - /* start the linked list */ - current_item = head = new_item; - } else { - /* add to the end and advance */ - current_item->next = new_item; - new_item->prev = current_item; - current_item = new_item; + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) + { + goto fail; /* expected end of object */ } - /* parse the name of the child */ - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (!parse_string(current_item, input_buffer)) { - goto fail; /* failed to parse name */ - } - buffer_skip_whitespace(input_buffer); - - /* swap valuestring and string, because we parsed the name */ - current_item->string = current_item->valuestring; - current_item->valuestring = NULL; - - if (cannot_access_at_index(input_buffer, 0) || - (buffer_at_offset(input_buffer)[0] != ':')) { - goto fail; /* invalid object */ - } - - /* parse the value */ - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (!parse_value(current_item, input_buffer)) { - goto fail; /* failed to parse value */ - } - buffer_skip_whitespace(input_buffer); - } while (can_access_at_index(input_buffer, 0) && - (buffer_at_offset(input_buffer)[0] == ',')); - - if (cannot_access_at_index(input_buffer, 0) || - (buffer_at_offset(input_buffer)[0] != '}')) { - goto fail; /* expected end of object */ - } - success: - input_buffer->depth--; + input_buffer->depth--; - if (head != NULL) { - head->prev = current_item; - } + if (head != NULL) { + head->prev = current_item; + } - item->type = cJSON_Object; - item->child = head; + item->type = cJSON_Object; + item->child = head; - input_buffer->offset++; - return true; + input_buffer->offset++; + return true; fail: - if (head != NULL) { - cJSON_Delete(head); - } + if (head != NULL) + { + cJSON_Delete(head); + } - return false; + return false; } /* Render an object to text. */ -static cJSON_bool print_object(const cJSON *const item, - printbuffer *const output_buffer) { - unsigned char *output_pointer = NULL; - size_t length = 0; - cJSON *current_item = item->child; +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_item = item->child; - if (output_buffer == NULL) { - return false; - } - - /* Compose the output: */ - length = (size_t)(output_buffer->format ? 2 : 1); /* fmt: {\n */ - output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) { - return false; - } - - *output_pointer++ = '{'; - output_buffer->depth++; - if (output_buffer->format) { - *output_pointer++ = '\n'; - } - output_buffer->offset += length; - - while (current_item) { - if (output_buffer->format) { - size_t i; - output_pointer = ensure(output_buffer, output_buffer->depth); - if (output_pointer == NULL) { + if (output_buffer == NULL) + { return false; - } - for (i = 0; i < output_buffer->depth; i++) { - *output_pointer++ = '\t'; - } - output_buffer->offset += output_buffer->depth; } - /* print key */ - if (!print_string_ptr((unsigned char *)current_item->string, - output_buffer)) { - return false; - } - update_offset(output_buffer); - - length = (size_t)(output_buffer->format ? 2 : 1); - output_pointer = ensure(output_buffer, length); - if (output_pointer == NULL) { - return false; - } - *output_pointer++ = ':'; - if (output_buffer->format) { - *output_pointer++ = '\t'; - } - output_buffer->offset += length; - - /* print value */ - if (!print_value(current_item, output_buffer)) { - return false; - } - update_offset(output_buffer); - - /* print comma if not last */ - length = ((size_t)(output_buffer->format ? 1 : 0) + - (size_t)(current_item->next ? 1 : 0)); + /* Compose the output: */ + length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) { - return false; - } - if (current_item->next) { - *output_pointer++ = ','; + if (output_pointer == NULL) + { + return false; } - if (output_buffer->format) { - *output_pointer++ = '\n'; + *output_pointer++ = '{'; + output_buffer->depth++; + if (output_buffer->format) + { + *output_pointer++ = '\n'; } - *output_pointer = '\0'; output_buffer->offset += length; - current_item = current_item->next; - } + while (current_item) + { + if (output_buffer->format) + { + size_t i; + output_pointer = ensure(output_buffer, output_buffer->depth); + if (output_pointer == NULL) + { + return false; + } + for (i = 0; i < output_buffer->depth; i++) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += output_buffer->depth; + } - output_pointer = ensure( - output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); - if (output_pointer == NULL) { - return false; - } - if (output_buffer->format) { - size_t i; - for (i = 0; i < (output_buffer->depth - 1); i++) { - *output_pointer++ = '\t'; + /* print key */ + if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + length = (size_t) (output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ':'; + if (output_buffer->format) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += length; + + /* print value */ + if (!print_value(current_item, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + /* print comma if not last */ + length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)(current_item->next ? 1 : 0)); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + if (current_item->next) + { + *output_pointer++ = ','; + } + + if (output_buffer->format) + { + *output_pointer++ = '\n'; + } + *output_pointer = '\0'; + output_buffer->offset += length; + + current_item = current_item->next; } - } - *output_pointer++ = '}'; - *output_pointer = '\0'; - output_buffer->depth--; - return true; + output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); + if (output_pointer == NULL) + { + return false; + } + if (output_buffer->format) + { + size_t i; + for (i = 0; i < (output_buffer->depth - 1); i++) + { + *output_pointer++ = '\t'; + } + } + *output_pointer++ = '}'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; } /* Get Array size/item / object item. */ -CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) { - cJSON *child = NULL; - size_t size = 0; +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) +{ + cJSON *child = NULL; + size_t size = 0; - if (array == NULL) { - return 0; - } - - child = array->child; - - while (child != NULL) { - size++; - child = child->next; - } - - /* FIXME: Can overflow here. Cannot be fixed without breaking the API */ - - return (int)size; -} - -static cJSON *get_array_item(const cJSON *array, size_t index) { - cJSON *current_child = NULL; - - if (array == NULL) { - return NULL; - } - - current_child = array->child; - while ((current_child != NULL) && (index > 0)) { - index--; - current_child = current_child->next; - } - - return current_child; -} - -CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) { - if (index < 0) { - return NULL; - } - - return get_array_item(array, (size_t)index); -} - -static cJSON *get_object_item(const cJSON *const object, const char *const name, - const cJSON_bool case_sensitive) { - cJSON *current_element = NULL; - - if ((object == NULL) || (name == NULL)) { - return NULL; - } - - current_element = object->child; - if (case_sensitive) { - while ((current_element != NULL) && (current_element->string != NULL) && - (strcmp(name, current_element->string) != 0)) { - current_element = current_element->next; + if (array == NULL) + { + return 0; } - } else { - while ((current_element != NULL) && - (case_insensitive_strcmp( - (const unsigned char *)name, - (const unsigned char *)(current_element->string)) != 0)) { - current_element = current_element->next; + + child = array->child; + + while(child != NULL) + { + size++; + child = child->next; } - } - if ((current_element == NULL) || (current_element->string == NULL)) { - return NULL; - } + /* FIXME: Can overflow here. Cannot be fixed without breaking the API */ - return current_element; + return (int)size; } -CJSON_PUBLIC(cJSON *) -cJSON_GetObjectItem(const cJSON *const object, const char *const string) { - return get_object_item(object, string, false); +static cJSON* get_array_item(const cJSON *array, size_t index) +{ + cJSON *current_child = NULL; + + if (array == NULL) + { + return NULL; + } + + current_child = array->child; + while ((current_child != NULL) && (index > 0)) + { + index--; + current_child = current_child->next; + } + + return current_child; } -CJSON_PUBLIC(cJSON *) -cJSON_GetObjectItemCaseSensitive(const cJSON *const object, - const char *const string) { - return get_object_item(object, string, true); +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) +{ + if (index < 0) + { + return NULL; + } + + return get_array_item(array, (size_t)index); } -CJSON_PUBLIC(cJSON_bool) -cJSON_HasObjectItem(const cJSON *object, const char *string) { - return cJSON_GetObjectItem(object, string) ? 1 : 0; +static cJSON *get_object_item(const cJSON * const object, const char * const name, const cJSON_bool case_sensitive) +{ + cJSON *current_element = NULL; + + if ((object == NULL) || (name == NULL)) + { + return NULL; + } + + current_element = object->child; + if (case_sensitive) + { + while ((current_element != NULL) && (current_element->string != NULL) && (strcmp(name, current_element->string) != 0)) + { + current_element = current_element->next; + } + } + else + { + while ((current_element != NULL) && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) + { + current_element = current_element->next; + } + } + + if ((current_element == NULL) || (current_element->string == NULL)) { + return NULL; + } + + return current_element; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, false); +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, true); +} + +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) +{ + return cJSON_GetObjectItem(object, string) ? 1 : 0; } /* Utility for array list handling. */ -static void suffix_object(cJSON *prev, cJSON *item) { - prev->next = item; - item->prev = prev; +static void suffix_object(cJSON *prev, cJSON *item) +{ + prev->next = item; + item->prev = prev; } /* Utility for handling references. */ -static cJSON *create_reference(const cJSON *item, - const internal_hooks *const hooks) { - cJSON *reference = NULL; - if (item == NULL) { - return NULL; - } +static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) +{ + cJSON *reference = NULL; + if (item == NULL) + { + return NULL; + } - reference = cJSON_New_Item(hooks); - if (reference == NULL) { - return NULL; - } + reference = cJSON_New_Item(hooks); + if (reference == NULL) + { + return NULL; + } - memcpy(reference, item, sizeof(cJSON)); - reference->string = NULL; - reference->type |= cJSON_IsReference; - reference->next = reference->prev = NULL; - return reference; + memcpy(reference, item, sizeof(cJSON)); + reference->string = NULL; + reference->type |= cJSON_IsReference; + reference->next = reference->prev = NULL; + return reference; } -static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) { - cJSON *child = NULL; +static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) +{ + cJSON *child = NULL; - if ((item == NULL) || (array == NULL) || (array == item)) { - return false; - } - - child = array->child; - /* - * To find the last item in array quickly, we use prev in array - */ - if (child == NULL) { - /* list is empty, start new one */ - array->child = item; - item->prev = item; - item->next = NULL; - } else { - /* append to the end */ - if (child->prev) { - suffix_object(child->prev, item); - array->child->prev = item; + if ((item == NULL) || (array == NULL) || (array == item)) + { + return false; } - } - return true; + child = array->child; + /* + * To find the last item in array quickly, we use prev in array + */ + if (child == NULL) + { + /* list is empty, start new one */ + array->child = item; + item->prev = item; + item->next = NULL; + } + else + { + /* append to the end */ + if (child->prev) + { + suffix_object(child->prev, item); + array->child->prev = item; + } + } + + return true; } /* Add item to array/object. */ -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) { - return add_item_to_array(array, item); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) +{ + return add_item_to_array(array, item); } -#if defined(__clang__) || \ - (defined(__GNUC__) && \ - ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) -#pragma GCC diagnostic push +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) + #pragma GCC diagnostic push #endif #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wcast-qual" #endif /* helper function to cast away const */ -static void *cast_away_const(const void *string) { return (void *)string; } -#if defined(__clang__) || \ - (defined(__GNUC__) && \ - ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) -#pragma GCC diagnostic pop +static void* cast_away_const(const void* string) +{ + return (void*)string; +} +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) + #pragma GCC diagnostic pop #endif -static cJSON_bool add_item_to_object(cJSON *const object, - const char *const string, - cJSON *const item, - const internal_hooks *const hooks, - const cJSON_bool constant_key) { - char *new_key = NULL; - int new_type = cJSON_Invalid; - if ((object == NULL) || (string == NULL) || (item == NULL) || - (object == item)) { - return false; - } +static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key) +{ + char *new_key = NULL; + int new_type = cJSON_Invalid; - if (constant_key) { - new_key = (char *)cast_away_const(string); - new_type = item->type | cJSON_StringIsConst; - } else { - new_key = (char *)cJSON_strdup((const unsigned char *)string, hooks); - if (new_key == NULL) { - return false; + if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item)) + { + return false; } - new_type = item->type & ~cJSON_StringIsConst; - } + if (constant_key) + { + new_key = (char*)cast_away_const(string); + new_type = item->type | cJSON_StringIsConst; + } + else + { + new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); + if (new_key == NULL) + { + return false; + } - if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) { - hooks->deallocate(item->string); - } + new_type = item->type & ~cJSON_StringIsConst; + } - item->string = new_key; - item->type = new_type; + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + hooks->deallocate(item->string); + } - return add_item_to_array(object, item); + item->string = new_key; + item->type = new_type; + + return add_item_to_array(object, item); } -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) { - return add_item_to_object(object, string, item, &global_hooks, false); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) +{ + return add_item_to_object(object, string, item, &global_hooks, false); } /* Add an item to an object with constant string as key */ -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) { - return add_item_to_object(object, string, item, &global_hooks, true); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) +{ + return add_item_to_object(object, string, item, &global_hooks, true); } -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) { - if (array == NULL) { - return false; - } +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) +{ + if (array == NULL) + { + return false; + } - return add_item_to_array(array, create_reference(item, &global_hooks)); + return add_item_to_array(array, create_reference(item, &global_hooks)); } -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) { - if ((object == NULL) || (string == NULL)) { - return false; - } +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) +{ + if ((object == NULL) || (string == NULL)) + { + return false; + } - return add_item_to_object(object, string, - create_reference(item, &global_hooks), - &global_hooks, false); + return add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); } -CJSON_PUBLIC(cJSON *) -cJSON_AddNullToObject(cJSON *const object, const char *const name) { - cJSON *null = cJSON_CreateNull(); - if (add_item_to_object(object, name, null, &global_hooks, false)) { - return null; - } +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name) +{ + cJSON *null = cJSON_CreateNull(); + if (add_item_to_object(object, name, null, &global_hooks, false)) + { + return null; + } - cJSON_Delete(null); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddTrueToObject(cJSON *const object, const char *const name) { - cJSON *true_item = cJSON_CreateTrue(); - if (add_item_to_object(object, name, true_item, &global_hooks, false)) { - return true_item; - } - - cJSON_Delete(true_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddFalseToObject(cJSON *const object, const char *const name) { - cJSON *false_item = cJSON_CreateFalse(); - if (add_item_to_object(object, name, false_item, &global_hooks, false)) { - return false_item; - } - - cJSON_Delete(false_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddBoolToObject(cJSON *const object, const char *const name, - const cJSON_bool boolean) { - cJSON *bool_item = cJSON_CreateBool(boolean); - if (add_item_to_object(object, name, bool_item, &global_hooks, false)) { - return bool_item; - } - - cJSON_Delete(bool_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddNumberToObject(cJSON *const object, const char *const name, - const double number) { - cJSON *number_item = cJSON_CreateNumber(number); - if (add_item_to_object(object, name, number_item, &global_hooks, false)) { - return number_item; - } - - cJSON_Delete(number_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddStringToObject(cJSON *const object, const char *const name, - const char *const string) { - cJSON *string_item = cJSON_CreateString(string); - if (add_item_to_object(object, name, string_item, &global_hooks, false)) { - return string_item; - } - - cJSON_Delete(string_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddRawToObject(cJSON *const object, const char *const name, - const char *const raw) { - cJSON *raw_item = cJSON_CreateRaw(raw); - if (add_item_to_object(object, name, raw_item, &global_hooks, false)) { - return raw_item; - } - - cJSON_Delete(raw_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddObjectToObject(cJSON *const object, const char *const name) { - cJSON *object_item = cJSON_CreateObject(); - if (add_item_to_object(object, name, object_item, &global_hooks, false)) { - return object_item; - } - - cJSON_Delete(object_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddArrayToObject(cJSON *const object, const char *const name) { - cJSON *array = cJSON_CreateArray(); - if (add_item_to_object(object, name, array, &global_hooks, false)) { - return array; - } - - cJSON_Delete(array); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item) { - if ((parent == NULL) || (item == NULL)) { + cJSON_Delete(null); return NULL; - } - - if (item != parent->child) { - /* not the first element */ - item->prev->next = item->next; - } - if (item->next != NULL) { - /* not the last element */ - item->next->prev = item->prev; - } - - if (item == parent->child) { - /* first element */ - parent->child = item->next; - } else if (item->next == NULL) { - /* last element */ - parent->child->prev = item->prev; - } - - /* make sure the detached item doesn't point anywhere anymore */ - item->prev = NULL; - item->next = NULL; - - return item; } -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) { - if (which < 0) { +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name) +{ + cJSON *true_item = cJSON_CreateTrue(); + if (add_item_to_object(object, name, true_item, &global_hooks, false)) + { + return true_item; + } + + cJSON_Delete(true_item); return NULL; - } - - return cJSON_DetachItemViaPointer(array, - get_array_item(array, (size_t)which)); } -CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) { - cJSON_Delete(cJSON_DetachItemFromArray(array, which)); +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name) +{ + cJSON *false_item = cJSON_CreateFalse(); + if (add_item_to_object(object, name, false_item, &global_hooks, false)) + { + return false_item; + } + + cJSON_Delete(false_item); + return NULL; } -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemFromObject(cJSON *object, const char *string) { - cJSON *to_detach = cJSON_GetObjectItem(object, string); +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean) +{ + cJSON *bool_item = cJSON_CreateBool(boolean); + if (add_item_to_object(object, name, bool_item, &global_hooks, false)) + { + return bool_item; + } - return cJSON_DetachItemViaPointer(object, to_detach); + cJSON_Delete(bool_item); + return NULL; } -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) { - cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number) +{ + cJSON *number_item = cJSON_CreateNumber(number); + if (add_item_to_object(object, name, number_item, &global_hooks, false)) + { + return number_item; + } - return cJSON_DetachItemViaPointer(object, to_detach); + cJSON_Delete(number_item); + return NULL; } -CJSON_PUBLIC(void) -cJSON_DeleteItemFromObject(cJSON *object, const char *string) { - cJSON_Delete(cJSON_DetachItemFromObject(object, string)); +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string) +{ + cJSON *string_item = cJSON_CreateString(string); + if (add_item_to_object(object, name, string_item, &global_hooks, false)) + { + return string_item; + } + + cJSON_Delete(string_item); + return NULL; } -CJSON_PUBLIC(void) -cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) { - cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw) +{ + cJSON *raw_item = cJSON_CreateRaw(raw); + if (add_item_to_object(object, name, raw_item, &global_hooks, false)) + { + return raw_item; + } + + cJSON_Delete(raw_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name) +{ + cJSON *object_item = cJSON_CreateObject(); + if (add_item_to_object(object, name, object_item, &global_hooks, false)) + { + return object_item; + } + + cJSON_Delete(object_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name) +{ + cJSON *array = cJSON_CreateArray(); + if (add_item_to_object(object, name, array, &global_hooks, false)) + { + return array; + } + + cJSON_Delete(array); + return NULL; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item) +{ + if ((parent == NULL) || (item == NULL)) + { + return NULL; + } + + if (item != parent->child) + { + /* not the first element */ + item->prev->next = item->next; + } + if (item->next != NULL) + { + /* not the last element */ + item->next->prev = item->prev; + } + + if (item == parent->child) + { + /* first element */ + parent->child = item->next; + } + else if (item->next == NULL) + { + /* last element */ + parent->child->prev = item->prev; + } + + /* make sure the detached item doesn't point anywhere anymore */ + item->prev = NULL; + item->next = NULL; + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) +{ + if (which < 0) + { + return NULL; + } + + return cJSON_DetachItemViaPointer(array, get_array_item(array, (size_t)which)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) +{ + cJSON_Delete(cJSON_DetachItemFromArray(array, which)); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItem(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObject(object, string)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); } /* Replace array/object items with new ones. */ -CJSON_PUBLIC(cJSON_bool) -cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) { - cJSON *after_inserted = NULL; +CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) +{ + cJSON *after_inserted = NULL; - if (which < 0) { - return false; - } + if (which < 0) + { + return false; + } - after_inserted = get_array_item(array, (size_t)which); - if (after_inserted == NULL) { - return add_item_to_array(array, newitem); - } + after_inserted = get_array_item(array, (size_t)which); + if (after_inserted == NULL) + { + return add_item_to_array(array, newitem); + } - newitem->next = after_inserted; - newitem->prev = after_inserted->prev; - after_inserted->prev = newitem; - if (after_inserted == array->child) { - array->child = newitem; - } else { - newitem->prev->next = newitem; - } - return true; -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, - cJSON *replacement) { - if ((parent == NULL) || (replacement == NULL) || (item == NULL)) { - return false; - } - - if (replacement == item) { + newitem->next = after_inserted; + newitem->prev = after_inserted->prev; + after_inserted->prev = newitem; + if (after_inserted == array->child) + { + array->child = newitem; + } + else + { + newitem->prev->next = newitem; + } return true; - } +} - replacement->next = item->next; - replacement->prev = item->prev; - - if (replacement->next != NULL) { - replacement->next->prev = replacement; - } - if (parent->child == item) { - if (parent->child->prev == parent->child) { - replacement->prev = replacement; +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) +{ + if ((parent == NULL) || (replacement == NULL) || (item == NULL)) + { + return false; } - parent->child = replacement; - } else { /* - * To find the last item in array quickly, we use prev in array. - * We can't modify the last item's next pointer where this item was - * the parent's child - */ - if (replacement->prev != NULL) { - replacement->prev->next = replacement; + + if (replacement == item) + { + return true; } - if (replacement->next == NULL) { - parent->child->prev = replacement; + + replacement->next = item->next; + replacement->prev = item->prev; + + if (replacement->next != NULL) + { + replacement->next->prev = replacement; + } + if (parent->child == item) + { + if (parent->child->prev == parent->child) + { + replacement->prev = replacement; + } + parent->child = replacement; + } + else + { /* + * To find the last item in array quickly, we use prev in array. + * We can't modify the last item's next pointer where this item was the parent's child + */ + if (replacement->prev != NULL) + { + replacement->prev->next = replacement; + } + if (replacement->next == NULL) + { + parent->child->prev = replacement; + } } - } - item->next = NULL; - item->prev = NULL; - cJSON_Delete(item); + item->next = NULL; + item->prev = NULL; + cJSON_Delete(item); - return true; + return true; } -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) { - if (which < 0) { - return false; - } +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) +{ + if (which < 0) + { + return false; + } - return cJSON_ReplaceItemViaPointer( - array, get_array_item(array, (size_t)which), newitem); + return cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem); } -static cJSON_bool replace_item_in_object(cJSON *object, const char *string, - cJSON *replacement, - cJSON_bool case_sensitive) { - if ((replacement == NULL) || (string == NULL)) { - return false; - } +static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive) +{ + if ((replacement == NULL) || (string == NULL)) + { + return false; + } - /* replace the name in the replacement */ - if (!(replacement->type & cJSON_StringIsConst) && - (replacement->string != NULL)) { - cJSON_free(replacement->string); - } - replacement->string = - (char *)cJSON_strdup((const unsigned char *)string, &global_hooks); - replacement->type &= ~cJSON_StringIsConst; + /* replace the name in the replacement */ + if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != NULL)) + { + cJSON_free(replacement->string); + } + replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + replacement->type &= ~cJSON_StringIsConst; - return cJSON_ReplaceItemViaPointer( - object, get_object_item(object, string, case_sensitive), replacement); + return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); } -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) { - return replace_item_in_object(object, string, newitem, false); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) +{ + return replace_item_in_object(object, string, newitem, false); } -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, - cJSON *newitem) { - return replace_item_in_object(object, string, newitem, true); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) +{ + return replace_item_in_object(object, string, newitem, true); } /* Create basic types: */ -CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_NULL; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_True; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_False; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = boolean ? cJSON_True : cJSON_False; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_Number; - item->valuedouble = num; - - /* use saturation in case of overflow */ - if (num >= INT_MAX) { - item->valueint = INT_MAX; - } else if (num <= (double)INT_MIN) { - item->valueint = INT_MIN; - } else { - item->valueint = (int)num; +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_NULL; } - } - return item; + return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_String; - item->valuestring = - (char *)cJSON_strdup((const unsigned char *)string, &global_hooks); - if (!item->valuestring) { - cJSON_Delete(item); - return NULL; +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_True; } - } - return item; + return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { - item->type = cJSON_String | cJSON_IsReference; - item->valuestring = (char *)cast_away_const(string); - } +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_False; + } - return item; + return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { - item->type = cJSON_Object | cJSON_IsReference; - item->child = (cJSON *)cast_away_const(child); - } +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = boolean ? cJSON_True : cJSON_False; + } - return item; + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Number; + item->valuedouble = num; + + /* use saturation in case of overflow */ + if (num >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (num <= (double)INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)num; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_String; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) + { + item->type = cJSON_String | cJSON_IsReference; + item->valuestring = (char*)cast_away_const(string); + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { + item->type = cJSON_Object | cJSON_IsReference; + item->child = (cJSON*)cast_away_const(child); + } + + return item; } CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { - item->type = cJSON_Array | cJSON_IsReference; - item->child = (cJSON *)cast_away_const(child); - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_Raw; - item->valuestring = - (char *)cJSON_strdup((const unsigned char *)raw, &global_hooks); - if (!item->valuestring) { - cJSON_Delete(item); - return NULL; + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { + item->type = cJSON_Array | cJSON_IsReference; + item->child = (cJSON*)cast_away_const(child); } - } - return item; + return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_Array; - } +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Raw; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } - return item; + return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_Object; - } +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type=cJSON_Array; + } - return item; + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_Object; + } + + return item; } /* Create Arrays: */ -CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) { - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; - if ((count < 0) || (numbers == NULL)) { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateNumber(numbers[i]); - if (!n) { - cJSON_Delete(a); - return NULL; + if ((count < 0) || (numbers == NULL)) + { + return NULL; } - if (!i) { - a->child = n; - } else { - suffix_object(p, n); + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if (!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; } - p = n; - } - if (a && a->child) { - a->child->prev = n; - } + if (a && a->child) { + a->child->prev = n; + } - return a; + return a; } -CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) { - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; - if ((count < 0) || (numbers == NULL)) { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateNumber((double)numbers[i]); - if (!n) { - cJSON_Delete(a); - return NULL; + if ((count < 0) || (numbers == NULL)) + { + return NULL; } - if (!i) { - a->child = n; - } else { - suffix_object(p, n); + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber((double)numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; } - p = n; - } - if (a && a->child) { - a->child->prev = n; - } + if (a && a->child) { + a->child->prev = n; + } - return a; + return a; } -CJSON_PUBLIC(cJSON *) -cJSON_CreateDoubleArray(const double *numbers, int count) { - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; - if ((count < 0) || (numbers == NULL)) { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateNumber(numbers[i]); - if (!n) { - cJSON_Delete(a); - return NULL; + if ((count < 0) || (numbers == NULL)) + { + return NULL; } - if (!i) { - a->child = n; - } else { - suffix_object(p, n); + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; } - p = n; - } - if (a && a->child) { - a->child->prev = n; - } + if (a && a->child) { + a->child->prev = n; + } - return a; + return a; } -CJSON_PUBLIC(cJSON *) -cJSON_CreateStringArray(const char *const *strings, int count) { - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; - if ((count < 0) || (strings == NULL)) { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateString(strings[i]); - if (!n) { - cJSON_Delete(a); - return NULL; + if ((count < 0) || (strings == NULL)) + { + return NULL; } - if (!i) { - a->child = n; - } else { - suffix_object(p, n); + + a = cJSON_CreateArray(); + + for (i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateString(strings[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p,n); + } + p = n; } - p = n; - } - if (a && a->child) { - a->child->prev = n; - } - - return a; + if (a && a->child) { + a->child->prev = n; + } + + return a; } /* Duplication */ -CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) { - cJSON *newitem = NULL; - cJSON *child = NULL; - cJSON *next = NULL; - cJSON *newchild = NULL; +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) +{ + cJSON *newitem = NULL; + cJSON *child = NULL; + cJSON *next = NULL; + cJSON *newchild = NULL; - /* Bail on bad ptr */ - if (!item) { - goto fail; - } - /* Create new item */ - newitem = cJSON_New_Item(&global_hooks); - if (!newitem) { - goto fail; - } - /* Copy over all vars */ - newitem->type = item->type & (~cJSON_IsReference); - newitem->valueint = item->valueint; - newitem->valuedouble = item->valuedouble; - if (item->valuestring) { - newitem->valuestring = - (char *)cJSON_strdup((unsigned char *)item->valuestring, &global_hooks); - if (!newitem->valuestring) { - goto fail; + /* Bail on bad ptr */ + if (!item) + { + goto fail; } - } - if (item->string) { - newitem->string = (item->type & cJSON_StringIsConst) - ? item->string - : (char *)cJSON_strdup((unsigned char *)item->string, - &global_hooks); - if (!newitem->string) { - goto fail; + /* Create new item */ + newitem = cJSON_New_Item(&global_hooks); + if (!newitem) + { + goto fail; } - } - /* If non-recursive, then we're done! */ - if (!recurse) { + /* Copy over all vars */ + newitem->type = item->type & (~cJSON_IsReference); + newitem->valueint = item->valueint; + newitem->valuedouble = item->valuedouble; + if (item->valuestring) + { + newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); + if (!newitem->valuestring) + { + goto fail; + } + } + if (item->string) + { + newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); + if (!newitem->string) + { + goto fail; + } + } + /* If non-recursive, then we're done! */ + if (!recurse) + { + return newitem; + } + /* Walk the ->next chain for the child. */ + child = item->child; + while (child != NULL) + { + newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */ + if (!newchild) + { + goto fail; + } + if (next != NULL) + { + /* If newitem->child already set, then crosswire ->prev and ->next and move on */ + next->next = newchild; + newchild->prev = next; + next = newchild; + } + else + { + /* Set newitem->child and move to it */ + newitem->child = newchild; + next = newchild; + } + child = child->next; + } + if (newitem && newitem->child) + { + newitem->child->prev = newchild; + } + return newitem; - } - /* Walk the ->next chain for the child. */ - child = item->child; - while (child != NULL) { - newchild = cJSON_Duplicate( - child, - true); /* Duplicate (with recurse) each item in the ->next chain */ - if (!newchild) { - goto fail; - } - if (next != NULL) { - /* If newitem->child already set, then crosswire ->prev and ->next and - * move on */ - next->next = newchild; - newchild->prev = next; - next = newchild; - } else { - /* Set newitem->child and move to it */ - newitem->child = newchild; - next = newchild; - } - child = child->next; - } - if (newitem && newitem->child) { - newitem->child->prev = newchild; - } - - return newitem; fail: - if (newitem != NULL) { - cJSON_Delete(newitem); - } + if (newitem != NULL) + { + cJSON_Delete(newitem); + } - return NULL; + return NULL; } -static void skip_oneline_comment(char **input) { - *input += static_strlen("//"); +static void skip_oneline_comment(char **input) +{ + *input += static_strlen("//"); - for (; (*input)[0] != '\0'; ++(*input)) { - if ((*input)[0] == '\n') { - *input += static_strlen("\n"); - return; + for (; (*input)[0] != '\0'; ++(*input)) + { + if ((*input)[0] == '\n') { + *input += static_strlen("\n"); + return; + } } - } } -static void skip_multiline_comment(char **input) { - *input += static_strlen("/*"); +static void skip_multiline_comment(char **input) +{ + *input += static_strlen("/*"); - for (; (*input)[0] != '\0'; ++(*input)) { - if (((*input)[0] == '*') && ((*input)[1] == '/')) { - *input += static_strlen("*/"); - return; + for (; (*input)[0] != '\0'; ++(*input)) + { + if (((*input)[0] == '*') && ((*input)[1] == '/')) + { + *input += static_strlen("*/"); + return; + } } - } } static void minify_string(char **input, char **output) { - (*output)[0] = (*input)[0]; - *input += static_strlen("\""); - *output += static_strlen("\""); - - for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) { (*output)[0] = (*input)[0]; + *input += static_strlen("\""); + *output += static_strlen("\""); - if ((*input)[0] == '\"') { - (*output)[0] = '\"'; - *input += static_strlen("\""); - *output += static_strlen("\""); - return; - } else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) { - (*output)[1] = (*input)[1]; - *input += static_strlen("\""); - *output += static_strlen("\""); + + for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) { + (*output)[0] = (*input)[0]; + + if ((*input)[0] == '\"') { + (*output)[0] = '\"'; + *input += static_strlen("\""); + *output += static_strlen("\""); + return; + } else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) { + (*output)[1] = (*input)[1]; + *input += static_strlen("\""); + *output += static_strlen("\""); + } } - } } -CJSON_PUBLIC(void) cJSON_Minify(char *json) { - char *into = json; +CJSON_PUBLIC(void) cJSON_Minify(char *json) +{ + char *into = json; - if (json == NULL) { - return; - } - - while (json[0] != '\0') { - switch (json[0]) { - case ' ': - case '\t': - case '\r': - case '\n': - json++; - break; - - case '/': - if (json[1] == '/') { - skip_oneline_comment(&json); - } else if (json[1] == '*') { - skip_multiline_comment(&json); - } else { - json++; - } - break; - - case '\"': - minify_string(&json, (char **)&into); - break; - - default: - into[0] = json[0]; - json++; - into++; - } - } - - /* and null-terminate. */ - *into = '\0'; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Invalid; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_False; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xff) == cJSON_True; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & (cJSON_True | cJSON_False)) != 0; -} -CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_NULL; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Number; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_String; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Array; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Object; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item) { - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Raw; -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_Compare(const cJSON *const a, const cJSON *const b, - const cJSON_bool case_sensitive) { - if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || - cJSON_IsInvalid(a)) { - return false; - } - - /* check if type is valid */ - switch (a->type & 0xFF) { - case cJSON_False: - case cJSON_True: - case cJSON_NULL: - case cJSON_Number: - case cJSON_String: - case cJSON_Raw: - case cJSON_Array: - case cJSON_Object: - break; - - default: - return false; - } - - /* identical objects are equal */ - if (a == b) { - return true; - } - - switch (a->type & 0xFF) { - /* in these cases and equal type is enough */ - case cJSON_False: - case cJSON_True: - case cJSON_NULL: - return true; - - case cJSON_Number: - if (compare_double(a->valuedouble, b->valuedouble)) { - return true; - } - return false; - - case cJSON_String: - case cJSON_Raw: - if ((a->valuestring == NULL) || (b->valuestring == NULL)) { - return false; - } - if (strcmp(a->valuestring, b->valuestring) == 0) { - return true; + if (json == NULL) + { + return; } - return false; + while (json[0] != '\0') + { + switch (json[0]) + { + case ' ': + case '\t': + case '\r': + case '\n': + json++; + break; - case cJSON_Array: { - cJSON *a_element = a->child; - cJSON *b_element = b->child; + case '/': + if (json[1] == '/') + { + skip_oneline_comment(&json); + } + else if (json[1] == '*') + { + skip_multiline_comment(&json); + } else { + json++; + } + break; - for (; (a_element != NULL) && (b_element != NULL);) { - if (!cJSON_Compare(a_element, b_element, case_sensitive)) { + case '\"': + minify_string(&json, (char**)&into); + break; + + default: + into[0] = json[0]; + json++; + into++; + } + } + + /* and null-terminate. */ + *into = '\0'; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) +{ + if (item == NULL) + { return false; - } - - a_element = a_element->next; - b_element = b_element->next; } - /* one of the arrays is longer than the other */ - if (a_element != b_element) { - return false; - } - - return true; - } - - case cJSON_Object: { - cJSON *a_element = NULL; - cJSON *b_element = NULL; - cJSON_ArrayForEach(a_element, a) { - /* TODO This has O(n^2) runtime, which is horrible! */ - b_element = get_object_item(b, a_element->string, case_sensitive); - if (b_element == NULL) { - return false; - } - - if (!cJSON_Compare(a_element, b_element, case_sensitive)) { - return false; - } - } - - /* doing this twice, once on a and b to prevent true comparison if a subset - * of b - * TODO: Do this the proper way, this is just a fix for now */ - cJSON_ArrayForEach(b_element, b) { - a_element = get_object_item(a, b_element->string, case_sensitive); - if (a_element == NULL) { - return false; - } - - if (!cJSON_Compare(b_element, a_element, case_sensitive)) { - return false; - } - } - - return true; - } - - default: - return false; - } + return (item->type & 0xFF) == cJSON_Invalid; } -CJSON_PUBLIC(void *) cJSON_malloc(size_t size) { - return global_hooks.allocate(size); +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_False; } -CJSON_PUBLIC(void) cJSON_free(void *object) { global_hooks.deallocate(object); } +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xff) == cJSON_True; +} + + +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & (cJSON_True | cJSON_False)) != 0; +} +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_NULL; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Number; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_String; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Array; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Object; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Raw; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) +{ + if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a)) + { + return false; + } + + /* check if type is valid */ + switch (a->type & 0xFF) + { + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + case cJSON_Number: + case cJSON_String: + case cJSON_Raw: + case cJSON_Array: + case cJSON_Object: + break; + + default: + return false; + } + + /* identical objects are equal */ + if (a == b) + { + return true; + } + + switch (a->type & 0xFF) + { + /* in these cases and equal type is enough */ + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + return true; + + case cJSON_Number: + if (compare_double(a->valuedouble, b->valuedouble)) + { + return true; + } + return false; + + case cJSON_String: + case cJSON_Raw: + if ((a->valuestring == NULL) || (b->valuestring == NULL)) + { + return false; + } + if (strcmp(a->valuestring, b->valuestring) == 0) + { + return true; + } + + return false; + + case cJSON_Array: + { + cJSON *a_element = a->child; + cJSON *b_element = b->child; + + for (; (a_element != NULL) && (b_element != NULL);) + { + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + + a_element = a_element->next; + b_element = b_element->next; + } + + /* one of the arrays is longer than the other */ + if (a_element != b_element) { + return false; + } + + return true; + } + + case cJSON_Object: + { + cJSON *a_element = NULL; + cJSON *b_element = NULL; + cJSON_ArrayForEach(a_element, a) + { + /* TODO This has O(n^2) runtime, which is horrible! */ + b_element = get_object_item(b, a_element->string, case_sensitive); + if (b_element == NULL) + { + return false; + } + + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + } + + /* doing this twice, once on a and b to prevent true comparison if a subset of b + * TODO: Do this the proper way, this is just a fix for now */ + cJSON_ArrayForEach(b_element, b) + { + a_element = get_object_item(a, b_element->string, case_sensitive); + if (a_element == NULL) + { + return false; + } + + if (!cJSON_Compare(b_element, a_element, case_sensitive)) + { + return false; + } + } + + return true; + } + + default: + return false; + } +} + +CJSON_PUBLIC(void *) cJSON_malloc(size_t size) +{ + return global_hooks.allocate(size); +} + +CJSON_PUBLIC(void) cJSON_free(void *object) +{ + global_hooks.deallocate(object); +} diff --git a/project/app/wifi_app/hisi_tools/app/vlinktest/cJSON.h b/project/app/wifi_app/hisi_tools/app/vlinktest/cJSON.h old mode 100644 new mode 100755 index 0916f8f30..e97e5f4cd --- a/project/app/wifi_app/hisi_tools/app/vlinktest/cJSON.h +++ b/project/app/wifi_app/hisi_tools/app/vlinktest/cJSON.h @@ -24,27 +24,23 @@ #define cJSON__h #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -#if !defined(__WINDOWS__) && \ - (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) +#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) #define __WINDOWS__ #endif #ifdef __WINDOWS__ -/* When compiling for windows, we specify a specific calling convention to avoid -issues where we are being called from a project with a different default calling -convention. For windows you have 3 define options: +/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options: -CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever -dllexport symbols CJSON_EXPORT_SYMBOLS - Define this on library build when you -want to dllexport symbols (default) CJSON_IMPORT_SYMBOLS - Define this if you -want to dllimport symbol +CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols +CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default) +CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol -For *nix builds that support visibility attribute, you can define similar -behavior by +For *nix builds that support visibility attribute, you can define similar behavior by setting default visibility to hidden by adding -fvisibility=hidden (for gcc) @@ -52,35 +48,31 @@ or -xldscope=hidden (for sun cc) to CFLAGS -then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way -CJSON_EXPORT_SYMBOLS does +then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does */ #define CJSON_CDECL __cdecl #define CJSON_STDCALL __stdcall -/* export symbols by default, this is necessary for copy pasting the C and - * header file */ -#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && \ - !defined(CJSON_EXPORT_SYMBOLS) +/* export symbols by default, this is necessary for copy pasting the C and header file */ +#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS) #define CJSON_EXPORT_SYMBOLS #endif #if defined(CJSON_HIDE_SYMBOLS) -#define CJSON_PUBLIC(type) type CJSON_STDCALL +#define CJSON_PUBLIC(type) type CJSON_STDCALL #elif defined(CJSON_EXPORT_SYMBOLS) -#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL +#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL #elif defined(CJSON_IMPORT_SYMBOLS) -#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL +#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL #endif #else /* !__WINDOWS__ */ #define CJSON_CDECL #define CJSON_STDCALL -#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && \ - defined(CJSON_API_VISIBILITY) -#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) +#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type #else #define CJSON_PUBLIC(type) type #endif @@ -95,140 +87,109 @@ CJSON_EXPORT_SYMBOLS does /* cJSON Types: */ #define cJSON_Invalid (0) -#define cJSON_False (1 << 0) -#define cJSON_True (1 << 1) -#define cJSON_NULL (1 << 2) +#define cJSON_False (1 << 0) +#define cJSON_True (1 << 1) +#define cJSON_NULL (1 << 2) #define cJSON_Number (1 << 3) #define cJSON_String (1 << 4) -#define cJSON_Array (1 << 5) +#define cJSON_Array (1 << 5) #define cJSON_Object (1 << 6) -#define cJSON_Raw (1 << 7) /* raw json */ +#define cJSON_Raw (1 << 7) /* raw json */ #define cJSON_IsReference 256 #define cJSON_StringIsConst 512 /* The cJSON structure: */ -typedef struct cJSON { - /* next/prev allow you to walk array/object chains. Alternatively, use - * GetArraySize/GetArrayItem/GetObjectItem */ - struct cJSON *next; - struct cJSON *prev; - /* An array or object item will have a child pointer pointing to a chain of - * the items in the array/object. */ - struct cJSON *child; +typedef struct cJSON +{ + /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON *next; + struct cJSON *prev; + /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + struct cJSON *child; - /* The type of the item, as above. */ - int type; + /* The type of the item, as above. */ + int type; - /* The item's string, if type==cJSON_String and type == cJSON_Raw */ - char *valuestring; - /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ - int valueint; - /* The item's number, if type==cJSON_Number */ - double valuedouble; + /* The item's string, if type==cJSON_String and type == cJSON_Raw */ + char *valuestring; + /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ + int valueint; + /* The item's number, if type==cJSON_Number */ + double valuedouble; - /* The item's name string, if this item is the child of, or is in the list of - * subitems of an object. */ - char *string; + /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + char *string; } cJSON; -typedef struct cJSON_Hooks { - /* malloc/free are CDECL on Windows regardless of the default calling - * convention of the compiler, so ensure the hooks allow passing those - * functions directly. */ - void *(CJSON_CDECL *malloc_fn)(size_t sz); - void(CJSON_CDECL *free_fn)(void *ptr); +typedef struct cJSON_Hooks +{ + /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ + void *(CJSON_CDECL *malloc_fn)(size_t sz); + void (CJSON_CDECL *free_fn)(void *ptr); } cJSON_Hooks; typedef int cJSON_bool; -/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse - * them. This is to prevent stack overflows. */ +/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. + * This is to prevent stack overflows. */ #ifndef CJSON_NESTING_LIMIT #define CJSON_NESTING_LIMIT 1000 #endif /* returns the version of cJSON as a string */ -CJSON_PUBLIC(const char *) cJSON_Version(void); +CJSON_PUBLIC(const char*) cJSON_Version(void); /* Supply malloc, realloc and free functions to cJSON */ -CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks); +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); -/* Memory Management: the caller is always responsible to free the results from - * all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib - * free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is - * cJSON_PrintPreallocated, where the caller has full responsibility of the - * buffer. */ -/* Supply a block of JSON, and this returns a cJSON object you can interrogate. - */ +/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ +/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithLength(const char *value, size_t buffer_length); -/* ParseWithOpts allows you to require (and check) that the JSON is null - * terminated, and to retrieve the pointer to the final byte parsed. */ -/* If you supply a ptr in return_parse_end and parsing fails, then - * return_parse_end will contain a pointer to the error so will match - * cJSON_GetErrorPtr(). */ -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithOpts(const char *value, const char **return_parse_end, - cJSON_bool require_null_terminated); -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, - const char **return_parse_end, - cJSON_bool require_null_terminated); +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length); +/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ +/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated); /* Render a cJSON entity to text for transfer/storage. */ CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); /* Render a cJSON entity to text for transfer/storage without any formatting. */ CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); -/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess - * at the final size. guessing well reduces reallocation. fmt=0 gives - * unformatted, =1 gives formatted */ -CJSON_PUBLIC(char *) -cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); -/* Render a cJSON entity to text using a buffer already allocated in memory with - * given length. Returns 1 on success and 0 on failure. */ -/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will - * use, so to be safe allocate 5 bytes more than you actually need */ -CJSON_PUBLIC(cJSON_bool) -cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, - const cJSON_bool format); +/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); +/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ +/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); /* Delete a cJSON entity and all subentities. */ CJSON_PUBLIC(void) cJSON_Delete(cJSON *item); /* Returns the number of items in an array (or object). */ CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); -/* Retrieve item number "index" from array "array". Returns NULL if - * unsuccessful. */ +/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */ CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); /* Get item "string" from object. Case insensitive. */ -CJSON_PUBLIC(cJSON *) -cJSON_GetObjectItem(const cJSON *const object, const char *const string); -CJSON_PUBLIC(cJSON *) -cJSON_GetObjectItemCaseSensitive(const cJSON *const object, - const char *const string); -CJSON_PUBLIC(cJSON_bool) -cJSON_HasObjectItem(const cJSON *object, const char *string); -/* For analysing failed parses. This returns a pointer to the parse error. - * You'll probably need to look a few chars back to make sense of it. Defined - * when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); +/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); /* Check item type and return its value */ -CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item); -CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item); +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item); +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item); /* These functions check the type of an item */ -CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); /* These calls create a cJSON item of the appropriate type. */ CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); @@ -251,126 +212,77 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); /* These utilities create an Array of count items. - * The parameter count cannot be greater than the number of elements in the - * number array, otherwise array access will be out of bounds.*/ + * The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); -CJSON_PUBLIC(cJSON *) -cJSON_CreateStringArray(const char *const *strings, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count); /* Append item to the specified array/object. */ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item); -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); -/* Use this when string is definitely const (i.e. a literal, or as good as), and - * will definitely survive the cJSON object. WARNING: When this function was - * used, make sure to always check that (item->type & cJSON_StringIsConst) is - * zero before writing to `item->string` */ -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); -/* Append reference to item to the specified array/object. Use this when you - * want to add an existing cJSON to a new cJSON, but don't want to corrupt your - * existing cJSON. */ -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); +/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. + * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before + * writing to `item->string` */ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); +/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); /* Remove/Detach items from Arrays/Objects. */ -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemFromObject(cJSON *object, const char *string); -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); -CJSON_PUBLIC(void) -cJSON_DeleteItemFromObject(cJSON *object, const char *string); -CJSON_PUBLIC(void) -cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); /* Update array items. */ -CJSON_PUBLIC(cJSON_bool) -cJSON_InsertItemInArray( - cJSON *array, int which, - cJSON *newitem); /* Shifts pre-existing items to the right. */ -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, - cJSON *replacement); -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem); -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, - cJSON *newitem); +CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); /* Duplicate a cJSON item */ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); -/* Duplicate will create a new, identical cJSON item to the one you pass, in new - * memory that will need to be released. With recurse!=0, it will duplicate any - * children connected to the item. The item->next and ->prev pointers are always - * zero on return from Duplicate. */ -/* Recursively compare two cJSON items for equality. If either a or b is NULL or - * invalid, they will be considered unequal. case_sensitive determines if object - * keys are treated case sensitive (1) or case insensitive (0) */ -CJSON_PUBLIC(cJSON_bool) -cJSON_Compare(const cJSON *const a, const cJSON *const b, - const cJSON_bool case_sensitive); +/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will + * need to be released. With recurse!=0, it will duplicate any children connected to the item. + * The item->next and ->prev pointers are always zero on return from Duplicate. */ +/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. + * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); -/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from - * strings. The input pointer json cannot point to a read-only address area, - * such as a string constant, but should point to a readable and writable adress - * area. */ +/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. + * The input pointer json cannot point to a read-only address area, such as a string constant, + * but should point to a readable and writable adress area. */ CJSON_PUBLIC(void) cJSON_Minify(char *json); /* Helper functions for creating and adding items to an object at the same time. * They return the added item or NULL on failure. */ -CJSON_PUBLIC(cJSON *) -cJSON_AddNullToObject(cJSON *const object, const char *const name); -CJSON_PUBLIC(cJSON *) -cJSON_AddTrueToObject(cJSON *const object, const char *const name); -CJSON_PUBLIC(cJSON *) -cJSON_AddFalseToObject(cJSON *const object, const char *const name); -CJSON_PUBLIC(cJSON *) -cJSON_AddBoolToObject(cJSON *const object, const char *const name, - const cJSON_bool boolean); -CJSON_PUBLIC(cJSON *) -cJSON_AddNumberToObject(cJSON *const object, const char *const name, - const double number); -CJSON_PUBLIC(cJSON *) -cJSON_AddStringToObject(cJSON *const object, const char *const name, - const char *const string); -CJSON_PUBLIC(cJSON *) -cJSON_AddRawToObject(cJSON *const object, const char *const name, - const char *const raw); -CJSON_PUBLIC(cJSON *) -cJSON_AddObjectToObject(cJSON *const object, const char *const name); -CJSON_PUBLIC(cJSON *) -cJSON_AddArrayToObject(cJSON *const object, const char *const name); +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean); +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number); +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string); +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw); +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name); -/* When assigning an integer value, it needs to be propagated to valuedouble - * too. */ -#define cJSON_SetIntValue(object, number) \ - ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) +/* When assigning an integer value, it needs to be propagated to valuedouble too. */ +#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) /* helper for the cJSON_SetNumberValue macro */ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); -#define cJSON_SetNumberValue(object, number) \ - ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) -/* Change the valuestring of a cJSON_String object, only takes effect when type - * of object is cJSON_String */ -CJSON_PUBLIC(char *) -cJSON_SetValuestring(cJSON *object, const char *valuestring); +#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) +/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */ +CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring); /* Macro for iterating over an array or object */ -#define cJSON_ArrayForEach(element, array) \ - for (element = (array != NULL) ? (array)->child : NULL; element != NULL; \ - element = element->next) +#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) -/* malloc/free objects using the malloc/free functions that have been set with - * cJSON_InitHooks */ +/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ CJSON_PUBLIC(void *) cJSON_malloc(size_t size); CJSON_PUBLIC(void) cJSON_free(void *object); diff --git a/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host.c b/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host.c old mode 100644 new mode 100755 index 350f32168..4a3c405ed --- a/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host.c +++ b/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host.c @@ -1,207 +1,211 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights - * reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: sample cli file. + * Author: Hisilicon + * Create: 2020-09-09 */ /***************************************************************************** 1 Í·Îļþ°üº¬ *****************************************************************************/ +#include +#include #include +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include -#include +#include "securec.h" #include "hi_base.h" #include "hichannel_host.h" -#include "securec.h" /***************************************************************************** 2 ºê¶¨Ò塢ȫ¾Ö±äÁ¿ *****************************************************************************/ -#define NETLINK_SOCKET_PORT_ID 1100 -#define NETLINK_CHANNEL_MODEID 28 +#define NETLINK_SOCKET_PORT_ID 1100 +#define NETLINK_CHANNEL_MODEID 28 #undef NLMSG_ALIGNTO -#define NLMSG_ALIGNTO 1 -#define USLEEP_TIMES 10 +#define NLMSG_ALIGNTO 1 +#define USLEEP_TIMES 10 typedef struct { - hi_s32 skfd; - pthread_t channel_thread; - hi_channel_rx_func rx_func; + hi_s32 skfd; + pthread_t channel_thread; + hi_channel_rx_func rx_func; } netlink_monitor_s; /***************************************************************************** 3 ö¾Ù¡¢½á¹¹Ì嶨Òå *****************************************************************************/ -static hi_bool g_channel_terminate = HI_FALSE; +static hi_bool g_channel_terminate = HI_FALSE; static netlink_monitor_s *g_channel_monitor = HI_NULL; /***************************************************************************** 4 º¯ÊýʵÏÖ *****************************************************************************/ -static hi_void *hi_channel_host_thread(hi_void *args) { - hi_s32 rev_len; - hi_s32 payload_len; - hi_char msg[SYSTEM_CMD_SIZE]; - struct nlmsghdr *nlh = HI_NULL; - struct sockaddr_nl daddr; - socklen_t len = sizeof(struct sockaddr_nl); - sample_unused(args); +static hi_void *hi_channel_host_thread(hi_void *args) +{ + hi_s32 rev_len; + hi_s32 payload_len; + hi_char msg[SYSTEM_CMD_SIZE]; + struct nlmsghdr *nlh = HI_NULL; + struct sockaddr_nl daddr; + socklen_t len = sizeof(struct sockaddr_nl); + sample_unused(args); - while (!g_channel_terminate) { - (hi_void) memset_s(&msg[0], sizeof(msg), 0, sizeof(msg)); - rev_len = recvfrom(g_channel_monitor->skfd, &msg[0], sizeof(msg), - MSG_WAITALL, (struct sockaddr *)&daddr, &len); - if (rev_len == -1) { - if (errno == EINTR) { - usleep(USLEEP_TIMES); - continue; - } else { - sample_log_print("recvfrom error! fd:%d\n", g_channel_monitor->skfd); - return HI_NULL; - } + while (!g_channel_terminate) { + (hi_void)memset_s(&msg[0], sizeof(msg), 0, sizeof(msg)); + rev_len = recvfrom(g_channel_monitor->skfd, &msg[0], sizeof(msg), + MSG_WAITALL, (struct sockaddr *)&daddr, &len); + if (rev_len == -1) { + if (errno == EINTR) { + usleep(USLEEP_TIMES); + continue; + } else { + sample_log_print("recvfrom error! fd:%d\n", g_channel_monitor->skfd); + return HI_NULL; + } + } + + if (rev_len <= NLMSG_HDRLEN) { + usleep(USLEEP_TIMES); + continue; + } + + nlh = (struct nlmsghdr *)msg; + payload_len = rev_len - NLMSG_HDRLEN; + sample_log_print("hi_channel_host_thread:%x,%d,%d,%d\n", nlh->nlmsg_type, payload_len, rev_len, NLMSG_HDRLEN); + if (g_channel_monitor->rx_func != HI_NULL) { + g_channel_monitor->rx_func((hi_u8 *)NLMSG_DATA(nlh), payload_len); + } } - if (rev_len <= NLMSG_HDRLEN) { - usleep(USLEEP_TIMES); - continue; - } - - nlh = (struct nlmsghdr *)msg; - payload_len = rev_len - NLMSG_HDRLEN; - sample_log_print("hi_channel_host_thread:%x,%d,%d,%d\n", nlh->nlmsg_type, - payload_len, rev_len, NLMSG_HDRLEN); - if (g_channel_monitor->rx_func != HI_NULL) { - g_channel_monitor->rx_func((hi_u8 *)NLMSG_DATA(nlh), payload_len); - } - } - - return HI_NULL; + return HI_NULL; } -hi_s32 hi_channel_register_rx_cb(hi_channel_rx_func rx_func) { - if ((g_channel_monitor == HI_NULL) || (rx_func == HI_NULL)) { - sample_log_print("hi_channel_register_rx_cb is fail\n"); - return HI_FAILURE; - } +hi_s32 hi_channel_register_rx_cb(hi_channel_rx_func rx_func) +{ + if ((g_channel_monitor == HI_NULL) || (rx_func == HI_NULL)) { + sample_log_print("hi_channel_register_rx_cb is fail\n"); + return HI_FAILURE; + } - g_channel_monitor->rx_func = rx_func; - return HI_SUCCESS; + g_channel_monitor->rx_func = rx_func; + return HI_SUCCESS; } -hi_s32 hi_channel_send_to_dev(unsigned char *buf, int len) { - int ret; - struct nlmsghdr *nlh = HI_NULL; - struct sockaddr_nl daddr; +hi_s32 hi_channel_send_to_dev(unsigned char *buf, int len) +{ + int ret; + struct nlmsghdr *nlh = HI_NULL; + struct sockaddr_nl daddr; - if ((buf == HI_NULL) || (len <= 0) || (len > MAX_SEND_DATA_SIZE)) { - sample_log_print("sendto sata len:%d\n", len); - return HI_FAILURE; - } + if ((buf == HI_NULL) || (len <= 0) || (len > MAX_SEND_DATA_SIZE)) { + sample_log_print("sendto sata len:%d\n", len); + return HI_FAILURE; + } - (hi_void) memset_s(&daddr, sizeof(daddr), 0, sizeof(daddr)); - daddr.nl_family = AF_NETLINK; /* netlink id */ - nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(len)); - if (nlh == HI_NULL) { - sample_log_print("malloc mem is fail\n"); - return HI_FAILURE; - } + (hi_void)memset_s(&daddr, sizeof(daddr), 0, sizeof(daddr)); + daddr.nl_family = AF_NETLINK; /* netlink id */ + nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(len)); + if (nlh == HI_NULL) { + sample_log_print("malloc mem is fail\n"); + return HI_FAILURE; + } + + (hi_void)memset_s(nlh, sizeof(nlh), 0x00, sizeof(nlh)); + nlh->nlmsg_len = NLMSG_SPACE(len); + nlh->nlmsg_pid = NETLINK_SOCKET_PORT_ID; + (hi_void)memcpy_s(NLMSG_DATA(nlh), NLMSG_SPACE(len), buf, len); + ret = sendto(g_channel_monitor->skfd, nlh, nlh->nlmsg_len, 0, + (struct sockaddr *)&daddr, sizeof(struct sockaddr_nl)); + if (ret == -1) { + sample_log_print("sendto error:%s\n", strerror(errno)); + free(nlh); + return HI_FAILURE; + } - (hi_void) memset_s(nlh, sizeof(nlh), 0x00, sizeof(nlh)); - nlh->nlmsg_len = NLMSG_SPACE(len); - nlh->nlmsg_pid = NETLINK_SOCKET_PORT_ID; - (hi_void) memcpy_s(NLMSG_DATA(nlh), NLMSG_SPACE(len), buf, len); - ret = sendto(g_channel_monitor->skfd, nlh, nlh->nlmsg_len, 0, - (struct sockaddr *)&daddr, sizeof(struct sockaddr_nl)); - if (ret == -1) { - sample_log_print("sendto error:%s\n", strerror(errno)); free(nlh); - return HI_FAILURE; - } - - free(nlh); - return 0; + return 0; } -hi_s32 hi_channel_init(hi_void) { - hi_s32 ret; - struct sockaddr_nl saddr = {0}; +hi_s32 hi_channel_init(hi_void) +{ + hi_s32 ret; + struct sockaddr_nl saddr = {0}; - if (g_channel_monitor != HI_NULL) { - sample_log_print("hi_channel_init is fail\n"); - return HI_FAILURE; - } + if (g_channel_monitor != HI_NULL) { + sample_log_print("hi_channel_init is fail\n"); + return HI_FAILURE; + } - g_channel_monitor = (netlink_monitor_s *)malloc(sizeof(netlink_monitor_s)); - if (g_channel_monitor == HI_NULL) { - return HI_FAILURE; - } + g_channel_monitor = (netlink_monitor_s *)malloc(sizeof(netlink_monitor_s)); + if (g_channel_monitor == HI_NULL) { + return HI_FAILURE; + } - g_channel_terminate = HI_FALSE; - (hi_void) memset_s(g_channel_monitor, sizeof(netlink_monitor_s), 0, - sizeof(netlink_monitor_s)); - g_channel_monitor->skfd = -1; - g_channel_monitor->skfd = - socket(AF_NETLINK, SOCK_RAW, NETLINK_CHANNEL_MODEID); - if (g_channel_monitor->skfd == -1) { - sample_log_print("create is fail:%s\n", strerror(errno)); - goto deinit; - } + g_channel_terminate = HI_FALSE; + (hi_void)memset_s(g_channel_monitor, sizeof(netlink_monitor_s), 0, sizeof(netlink_monitor_s)); + g_channel_monitor->skfd = -1; + g_channel_monitor->skfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_CHANNEL_MODEID); + if (g_channel_monitor->skfd == -1) { + sample_log_print("create is fail:%s\n", strerror(errno)); + goto deinit; + } - (hi_void) memset_s(&saddr, sizeof(saddr), 0x00, sizeof(saddr)); - saddr.nl_family = AF_NETLINK; /* netlink id */ - saddr.nl_pid = NETLINK_SOCKET_PORT_ID; /* self pid */ + (hi_void)memset_s(&saddr, sizeof(saddr), 0x00, sizeof(saddr)); + saddr.nl_family = AF_NETLINK; /* netlink id */ + saddr.nl_pid = NETLINK_SOCKET_PORT_ID; /* self pid */ - ret = bind(g_channel_monitor->skfd, (struct sockaddr *)&saddr, sizeof(saddr)); - if (ret != 0) { - goto deinit; - } + ret = bind(g_channel_monitor->skfd, (struct sockaddr *)&saddr, sizeof(saddr)); + if (ret != 0) { + goto deinit; + } - ret = pthread_create(&g_channel_monitor->channel_thread, HI_NULL, - hi_channel_host_thread, HI_NULL); - if (ret != HI_SUCCESS) { - goto deinit; - } + ret = pthread_create(&g_channel_monitor->channel_thread, HI_NULL, hi_channel_host_thread, HI_NULL); + if (ret != HI_SUCCESS) { + goto deinit; + } - return HI_SUCCESS; + return HI_SUCCESS; deinit: - if (g_channel_monitor->skfd != -1) { - close(g_channel_monitor->skfd); - g_channel_monitor->skfd = -1; - } + if (g_channel_monitor->skfd != -1) { + close(g_channel_monitor->skfd); + g_channel_monitor->skfd = -1; + } - if (g_channel_monitor != HI_NULL) { - free(g_channel_monitor); - g_channel_monitor = HI_NULL; - } - return HI_FAILURE; -} - -hi_s32 hi_channel_deinit(hi_void) { - if (g_channel_monitor == HI_NULL) { - sample_log_print("hi_channel_deinit is fail\n"); + if (g_channel_monitor != HI_NULL) { + free(g_channel_monitor); + g_channel_monitor = HI_NULL; + } return HI_FAILURE; - } - - g_channel_terminate = HI_TRUE; - - if (g_channel_monitor->channel_thread) { - pthread_cancel(g_channel_monitor->channel_thread); - pthread_join(g_channel_monitor->channel_thread, HI_NULL); - } - - if (g_channel_monitor->skfd != -1) { - close(g_channel_monitor->skfd); - g_channel_monitor->skfd = -1; - } - - if (g_channel_monitor != HI_NULL) { - free(g_channel_monitor); - g_channel_monitor = HI_NULL; - } - - return HI_SUCCESS; } + +hi_s32 hi_channel_deinit(hi_void) +{ + if (g_channel_monitor == HI_NULL) { + sample_log_print("hi_channel_deinit is fail\n"); + return HI_FAILURE; + } + + g_channel_terminate = HI_TRUE; + + if (g_channel_monitor->channel_thread) { + pthread_cancel(g_channel_monitor->channel_thread); + pthread_join(g_channel_monitor->channel_thread, HI_NULL); + } + + if (g_channel_monitor->skfd != -1) { + close(g_channel_monitor->skfd); + g_channel_monitor->skfd = -1; + } + + if (g_channel_monitor != HI_NULL) { + free(g_channel_monitor); + g_channel_monitor = HI_NULL; + } + + return HI_SUCCESS; +} + diff --git a/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host.h b/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host.h old mode 100644 new mode 100755 index 0a95ac15c..826ca682b --- a/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host.h +++ b/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host.h @@ -1,6 +1,8 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights - * reserved. Description: sample link file. Author: Hisilicon Create: 2020-09-09 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: sample link file. + * Author: Hisilicon + * Create: 2020-09-09 */ #ifndef HISI_LINK_H @@ -13,9 +15,9 @@ extern "C" { /***************************************************************************** 1 ºê¶¨Òå *****************************************************************************/ -#define SYSTEM_CMD_SIZE 384 /* СÓÚÕâ¸öÖµµÄÊý¾Ý±¨ÎÄͨ¹ý¸ßÓÅÏȼ¶Í¨µÀ´«Êä */ -#define MAX_SEND_DATA_SIZE 1500 /* СÓÚÕâ¸öÖµµÄÊý¾Ý±¨ÎÄͨ¹ýµÍÓÅÏȼ¶Í¨µÀ´«Êä */ -#define SYSTEM_NETDEV_NAME "wlan0" +#define SYSTEM_CMD_SIZE 384 /* СÓÚÕâ¸öÖµµÄÊý¾Ý±¨ÎÄͨ¹ý¸ßÓÅÏȼ¶Í¨µÀ´«Êä */ +#define MAX_SEND_DATA_SIZE 1500 /* СÓÚÕâ¸öÖµµÄÊý¾Ý±¨ÎÄͨ¹ýµÍÓÅÏȼ¶Í¨µÀ´«Êä */ +#define SYSTEM_NETDEV_NAME "wlan0" typedef void (*hi_channel_rx_func)(unsigned char *msg_data, int len); /***************************************************************************** diff --git a/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host_comm.c b/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host_comm.c old mode 100644 new mode 100755 index 1b09ee62a..1e5eaa64c --- a/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host_comm.c +++ b/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host_comm.c @@ -1,20 +1,21 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights - * reserved. Description: sample common file. Author: Hisilicon Create: - * 2018-08-04 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: sample common file. + * Author: Hisilicon + * Create: 2018-08-04 */ /***************************************************************************** 1 Í·Îļþ°üº¬ *****************************************************************************/ +#include +#include +#include +#include +#include +#include "securec.h" #include "hichannel_host_comm.h" #include "hi_base.h" -#include "securec.h" -#include -#include -#include -#include -#include /***************************************************************************** 2 ºê¶¨Ò塢ȫ¾Ö±äÁ¿ @@ -24,119 +25,117 @@ static sample_cmd_common g_cmd_com = {0}; /***************************************************************************** 4 º¯ÊýʵÏÖ *****************************************************************************/ -hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg, - hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset) { - const hi_char *pc_cmd_copy = HI_NULL; - hi_u32 pos = 0; +hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg, hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset) +{ + const hi_char *pc_cmd_copy = HI_NULL; + hi_u32 pos = 0; - if ((pc_cmd == HI_NULL) || (pc_arg == HI_NULL) || - (pul_cmd_offset == HI_NULL)) { - sample_log_print( - "pc_cmd/pc_arg/pul_cmd_offset null ptr error %pK, %pK, %pK!\n", pc_cmd, - pc_arg, pul_cmd_offset); - return HI_FAILURE; - } - - pc_cmd_copy = pc_cmd; - - while (*pc_cmd_copy != '\0' && - !((*(pc_cmd_copy) == ',') && (*(pc_cmd_copy - 1) != '\\'))) { - if ((*(pc_cmd_copy + 1) == ',') && (*(pc_cmd_copy) == '\\')) { - ++pc_cmd_copy; - continue; - } - pc_arg[pos] = *pc_cmd_copy; - ++pos; - ++pc_cmd_copy; - - if (pos >= pc_arg_len) { - sample_log_print("ul_pos >= WLAN_CMD_NAME_MAX_LEN, ul_pos %d!\n", pos); - return HI_FAILURE; - } - } - - pc_arg[pos] = '\0'; - - /* ×Ö·û´®µ½½á⣬·µ»Ø´íÎóÂë */ - if (pos == 0) { - sample_log_print("return param pc_arg is null!}\r\n"); - return HI_FAILURE; - } - *pul_cmd_offset = (hi_u32)(pc_cmd_copy - pc_cmd); - - return HI_SUCCESS; -} - -hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len, - hi_void *msg) { - hi_u8 cmd_id; - hi_u32 off_set = 0; - hi_char wlan_name[SAMPLE_CMD_MAX_LEN] = {0}; - - if (cmd == HI_NULL) { - return HI_FAILURE; - } - - if (sample_get_cmd_one_arg(cmd, wlan_name, SAMPLE_CMD_MAX_LEN, &off_set) != - HI_SUCCESS) { - return HI_FAILURE; - } - cmd += (off_set + 1); - - for (cmd_id = 0; cmd_id < g_cmd_com.count; cmd_id++) { - if (strcmp(g_cmd_com.cmd_tbl[cmd_id].cmd_name, wlan_name) == 0) { - if (g_cmd_com.cmd_tbl[cmd_id].func(wdata, cmd, len, msg) != HI_SUCCESS) { - sample_log_print("cmd exec fail!\n"); + if ((pc_cmd == HI_NULL) || (pc_arg == HI_NULL) || (pul_cmd_offset == HI_NULL)) { + sample_log_print("pc_cmd/pc_arg/pul_cmd_offset null ptr error %pK, %pK, %pK!\n", \ + pc_cmd, pc_arg, pul_cmd_offset); return HI_FAILURE; - } - return HI_SUCCESS; } - } - return HI_FAILURE; + pc_cmd_copy = pc_cmd; + + while (*pc_cmd_copy != '\0' && !((*(pc_cmd_copy) == ',') && (*(pc_cmd_copy - 1) != '\\'))) { + if ((*(pc_cmd_copy + 1) == ',') && (*(pc_cmd_copy) == '\\')) { + ++pc_cmd_copy; + continue; + } + pc_arg[pos] = *pc_cmd_copy; + ++pos; + ++pc_cmd_copy; + + if (pos >= pc_arg_len) { + sample_log_print("ul_pos >= WLAN_CMD_NAME_MAX_LEN, ul_pos %d!\n", pos); + return HI_FAILURE; + } + } + + pc_arg[pos] = '\0'; + + /* ×Ö·û´®µ½½á⣬·µ»Ø´íÎóÂë */ + if (pos == 0) { + sample_log_print("return param pc_arg is null!}\r\n"); + return HI_FAILURE; + } + *pul_cmd_offset = (hi_u32)(pc_cmd_copy - pc_cmd); + + return HI_SUCCESS; } -hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len, - hi_void *msg) { - hi_char *pcmd = HI_NULL; - hi_char *pcmd_tmp = HI_NULL; - if (len > SAMPLE_CMD_MAX_LEN) { - sample_log_print("command len > %d!\n", SAMPLE_CMD_MAX_LEN); - return HI_FAILURE; - } - pcmd = malloc(SAMPLE_CMD_MAX_LEN); - if (pcmd == HI_NULL) { - return HI_FAILURE; - } - if (cmd != HI_NULL) { - if (memcpy_s(pcmd, len, cmd, len) != EOK) { - sample_log_print("command memcpy_s failed!\n"); - free(pcmd); - return HI_FAILURE; - } - } +hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len, hi_void *msg) +{ + hi_u8 cmd_id; + hi_u32 off_set = 0; + hi_char wlan_name[SAMPLE_CMD_MAX_LEN] = {0}; - pcmd[len] = '\0'; - pcmd_tmp = pcmd; - if (sample_parse_cmd(wdata, pcmd_tmp, len, msg) != HI_SUCCESS) { + if (cmd == HI_NULL) { + return HI_FAILURE; + } + + if (sample_get_cmd_one_arg(cmd, wlan_name, SAMPLE_CMD_MAX_LEN, &off_set) != HI_SUCCESS) { + return HI_FAILURE; + } + cmd += (off_set + 1); + + for (cmd_id = 0; cmd_id < g_cmd_com.count; cmd_id++) { + if (strcmp(g_cmd_com.cmd_tbl[cmd_id].cmd_name, wlan_name) == 0) { + if (g_cmd_com.cmd_tbl[cmd_id].func(wdata, cmd, len, msg) != HI_SUCCESS) { + sample_log_print("cmd exec fail!\n"); + return HI_FAILURE; + } + return HI_SUCCESS; + } + } + + return HI_FAILURE; +} + +hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len, hi_void *msg) +{ + hi_char *pcmd = HI_NULL; + hi_char *pcmd_tmp = HI_NULL; + if (len > SAMPLE_CMD_MAX_LEN) { + sample_log_print("command len > %d!\n", SAMPLE_CMD_MAX_LEN); + return HI_FAILURE; + } + pcmd = malloc(SAMPLE_CMD_MAX_LEN); + if (pcmd == HI_NULL) { + return HI_FAILURE; + } + if (cmd != HI_NULL) { + if (memcpy_s(pcmd, len, cmd, len) != EOK) { + sample_log_print("command memcpy_s failed!\n"); + free(pcmd); + return HI_FAILURE; + } + } + + pcmd[len] = '\0'; + pcmd_tmp = pcmd; + if (sample_parse_cmd(wdata, pcmd_tmp, len, msg) != HI_SUCCESS) { + free(pcmd); + return HI_FAILURE; + } free(pcmd); - return HI_FAILURE; - } - free(pcmd); - return HI_SUCCESS; + return HI_SUCCESS; } -hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num) { - hi_u32 i; - sample_cmd_common *tmp_list = HI_NULL; - tmp_list = (sample_cmd_common *)&g_cmd_com; - for (i = 0; i < num; i++) { - if (cmd_tbl[i].cmd_name == HI_NULL || cmd_tbl[i].func == HI_NULL) { - sample_log_print("SAMPLE_COMMON: register cmd table failed!\n"); - return HI_FAILURE; +hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num) +{ + hi_u32 i; + sample_cmd_common *tmp_list = HI_NULL; + tmp_list = (sample_cmd_common *)&g_cmd_com; + for (i = 0; i < num; i++) { + if (cmd_tbl[i].cmd_name == HI_NULL || cmd_tbl[i].func == HI_NULL) { + sample_log_print("SAMPLE_COMMON: register cmd table failed!\n"); + return HI_FAILURE; + } } - } - tmp_list->cmd_tbl = cmd_tbl; - tmp_list->count = num; - return HI_SUCCESS; + tmp_list->cmd_tbl = cmd_tbl; + tmp_list->count = num; + return HI_SUCCESS; } + diff --git a/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host_comm.h b/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host_comm.h old mode 100644 new mode 100755 index e468db0f2..f6da9099b --- a/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host_comm.h +++ b/project/app/wifi_app/hisi_tools/app/vlinktest/hichannel_host_comm.h @@ -1,7 +1,8 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights - * reserved. Description: sample common file. Author: Hisilicon Create: - * 2018-08-04 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: sample common file. + * Author: Hisilicon + * Create: 2018-08-04 */ #ifndef __SAMPLE_COMMON_H__ @@ -19,53 +20,50 @@ /***************************************************************************** 3 ö¾Ù¡¢½á¹¹Ì嶨Òå *****************************************************************************/ -typedef hi_s32 (*sample_cmd_func)(hi_void *wdata, hi_char *param, hi_u32 len, - hi_void *pmsg); +typedef hi_s32(*sample_cmd_func)(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg); typedef struct { - hi_char *cmd_name; /* ÃüÁî×Ö·û´® */ - sample_cmd_func func; /* ÃüÁî¶ÔÓ¦´¦Àíº¯Êý */ + hi_char *cmd_name; /* ÃüÁî×Ö·û´® */ + sample_cmd_func func; /* ÃüÁî¶ÔÓ¦´¦Àíº¯Êý */ } sample_cmd_entry_stru; typedef struct { - sample_cmd_entry_stru *cmd_tbl; /* ÃüÁî±í */ - hi_u32 count; /* ÃüÁî×ÜÊý */ + sample_cmd_entry_stru *cmd_tbl; /* ÃüÁî±í */ + hi_u32 count; /* ÃüÁî×ÜÊý */ } sample_cmd_common; -#define CMD_SENDMSG_NETCFG 0x01 -#define CMD_SENDMSG_GETMAC 0x02 -#define CMD_SENDMSG_GETIP 0x03 -#define CMD_SENDMSG_SETFILTER 0x04 -#define CMD_SENDMSG_KEEPLIVE 0x05 -#define CMD_SENDMSG_STANDBY 0x06 -#define CMD_SENDMSG_DEEPSLEEP 0x07 -#define CMD_SENDMSG_STARTAP 0x08 -#define CMD_SENDMSG_STARTOTA 0x09 -#define CMD_SENDMSG_OTADATA 0x0a -#define CMD_SENDMSG_OTAWRITERET 0x0b -#define CMD_SENDMSG_OTARET 0x0c -#define CMD_SENDMSG_GET_RSSI 0x0d -#define CMD_SENDMSG_GET_VERSION 0x0e -#define CMD_SENDMSG_GET_WAKECODE 0x0f +#define CMD_SENDMSG_NETCFG 0x01 +#define CMD_SENDMSG_GETMAC 0x02 +#define CMD_SENDMSG_GETIP 0x03 +#define CMD_SENDMSG_SETFILTER 0x04 +#define CMD_SENDMSG_KEEPLIVE 0x05 +#define CMD_SENDMSG_STANDBY 0x06 +#define CMD_SENDMSG_DEEPSLEEP 0x07 +#define CMD_SENDMSG_STARTAP 0x08 +#define CMD_SENDMSG_STARTOTA 0x09 +#define CMD_SENDMSG_OTADATA 0x0a +#define CMD_SENDMSG_OTAWRITERET 0x0b +#define CMD_SENDMSG_OTARET 0x0c +#define CMD_SENDMSG_GET_RSSI 0x0d +#define CMD_SENDMSG_GET_VERSION 0x0e +#define CMD_SENDMSG_GET_WAKECODE 0x0f -#define CMD_SENDMSG_FACTORY_RESET 0x10 -#define CMD_SENDMSG_PIR_SET 0x11 -#define CMD_SENDMSG_PIR_GET 0x12 -#define CMD_SENDMSG_TUYA_SET 0x13 -#define CMD_SENDMSG_GETALL 0x14 -#define CMD_SENDMSG_PIR_CLR 0x17 +#define CMD_SENDMSG_FACTORY_RESET 0x10 +#define CMD_SENDMSG_PIR_SET 0x11 +#define CMD_SENDMSG_PIR_GET 0x12 +#define CMD_SENDMSG_TUYA_SET 0x13 +#define CMD_SENDMSG_GETALL 0x14 +#define CMD_SENDMSG_PIR_CLR 0x17 /***************************************************************************** 4 º¯ÊýÉùÃ÷ *****************************************************************************/ -hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg, - hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset); +hi_s32 sample_get_cmd_one_arg(const hi_char *pc_cmd, hi_char *pc_arg, hi_u32 pc_arg_len, hi_u32 *pul_cmd_offset); -hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len, - hi_void *msg); +hi_s32 sample_parse_cmd(hi_void *wdata, hi_char *cmd, ssize_t len, hi_void *msg); -hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len, - hi_void *msg); +hi_s32 sample_sock_cmd_entry(hi_void *wdata, const char *cmd, ssize_t len, hi_void *msg); hi_s32 sample_register_cmd(sample_cmd_entry_stru *cmd_tbl, hi_u32 num); #endif + diff --git a/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_hichannel_cmd.c b/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_hichannel_cmd.c old mode 100644 new mode 100755 index e43f7dbb3..a28acbeae --- a/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_hichannel_cmd.c +++ b/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_hichannel_cmd.c @@ -1,600 +1,578 @@ -#include -#include -#include -#include -#include +#include #include -#include +#include #include #include -#include +#include +#include +#include +#include +#include +#include "securec.h" #include "hi_base.h" #include "hichannel_host.h" #include "hichannel_host_comm.h" -#include "securec.h" #include "cJSON.h" -#define VLINK_SEND_MSG_MAX_LEN (SYSTEM_CMD_SIZE - 4) -#define VLINK_SEND_MSG_HEAD_LEN 3 +#define VLINK_SEND_MSG_MAX_LEN (SYSTEM_CMD_SIZE - 4) +#define VLINK_SEND_MSG_HEAD_LEN 3 + +hi_u32 vlink_hi_channel_cmd_netcfg_info(hi_char* ssid, hi_char* key, hi_char* sendmsg, hi_u32 *sendmsg_len) +{ + cJSON * pJsonRoot = NULL; + cJSON *pJson = NULL; + hi_u32 datalen = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; -hi_u32 vlink_hi_channel_cmd_netcfg_info(hi_char *ssid, hi_char *key, - hi_char *sendmsg, hi_u32 *sendmsg_len) { - cJSON *pJsonRoot = NULL; - cJSON *pJson = NULL; - hi_u32 datalen = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; + pJsonRoot = cJSON_CreateObject(); - pJsonRoot = cJSON_CreateObject(); + //cJSON_AddStringToObject(pJsonRoot, "cmd", CMD_SENDMSG_NETCFG); + cJSON_AddStringToObject(pJsonRoot, "ssid", ssid); + cJSON_AddStringToObject(pJsonRoot, "key", key); - // cJSON_AddStringToObject(pJsonRoot, "cmd", CMD_SENDMSG_NETCFG); - cJSON_AddStringToObject(pJsonRoot, "ssid", ssid); - cJSON_AddStringToObject(pJsonRoot, "key", key); + pJson = cJSON_Print(pJsonRoot); - pJson = cJSON_Print(pJsonRoot); + sample_log_print("vlink_hi_channel_netcfg_info-----------pJson[%s]-len[%d]--\n", pJson, strlen(pJson)); + datalen = strlen(pJson); - sample_log_print( - "vlink_hi_channel_netcfg_info-----------pJson[%s]-len[%d]--\n", pJson, - strlen(pJson)); - datalen = strlen(pJson); + *sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - *sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + sendcmdbuf[0] = CMD_SENDMSG_NETCFG; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sendcmdbuf[0] = CMD_SENDMSG_NETCFG; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + sample_log_print("vlink_hi_channel_netcfg_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - sample_log_print( - "vlink_hi_channel_netcfg_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen); + free(pJson); + cJSON_Delete(pJsonRoot); - memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen); - free(pJson); - cJSON_Delete(pJsonRoot); + memcpy_s(sendmsg, *sendmsg_len, sendcmdbuf, *sendmsg_len); - memcpy_s(sendmsg, *sendmsg_len, sendcmdbuf, *sendmsg_len); - - return 0; + return 0; } -hi_u32 vlink_hi_channel_cmd_getmac_info(hi_void) { - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; +hi_u32 vlink_hi_channel_cmd_getmac_info(hi_void) +{ + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - sendcmdbuf[0] = CMD_SENDMSG_GETMAC; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + sendcmdbuf[0] = CMD_SENDMSG_GETMAC; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - sample_log_print("vlink_hi_channel_cmd_getmac_info-------sendcmdbuf-[%02X]-[%" - "02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_getmac_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_getmac_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_getmac_info--send ok\n"); - } + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_getmac_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_getmac_info--send ok\n"); + } - return 0; + return 0; } -hi_u32 vlink_hi_channel_cmd_getip_info(hi_void) { - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; +hi_u32 vlink_hi_channel_cmd_getip_info(hi_void) +{ + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - sendcmdbuf[0] = CMD_SENDMSG_GETIP; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + sendcmdbuf[0] = CMD_SENDMSG_GETIP; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - sample_log_print("vlink_hi_channel_cmd_getip_info-------sendcmdbuf-[%02X]-[%" - "02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_getip_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_getip_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_getip_info--send ok\n"); - } + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_getip_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_getip_info--send ok\n"); + } - return 0; + return 0; } -hi_u32 vlink_hi_channel_cmd_setfilter_info(hi_char *device) { - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - cJSON *pJsonRoot = NULL; - cJSON *pJson = NULL; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; +hi_u32 vlink_hi_channel_cmd_setfilter_info(hi_char* device) +{ + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + cJSON * pJsonRoot = NULL; + cJSON *pJson = NULL; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - pJsonRoot = cJSON_CreateObject(); + pJsonRoot = cJSON_CreateObject(); - cJSON_AddStringToObject(pJsonRoot, "device", device); - pJson = cJSON_Print(pJsonRoot); + cJSON_AddStringToObject(pJsonRoot, "device", device); + pJson = cJSON_Print(pJsonRoot); - sample_log_print("vlink_hi_channel_cmd_setfilter_info-------pJson[%s]---\n", - pJson); + sample_log_print("vlink_hi_channel_cmd_setfilter_info-------pJson[%s]---\n", pJson); - datalen = strlen(pJson); + datalen = strlen(pJson); - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - sendcmdbuf[0] = CMD_SENDMSG_SETFILTER; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + sendcmdbuf[0] = CMD_SENDMSG_SETFILTER; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sample_log_print("vlink_hi_channel_cmd_setfilter_info-------sendcmdbuf-[%02X]" - "-[%02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_setfilter_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen); - free(pJson); - cJSON_Delete(pJsonRoot); + memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen); + free(pJson); + cJSON_Delete(pJsonRoot); - // memcpy_s(sendmsg, sendmsg_len, sendcmdbuf, sendmsg_len); + //memcpy_s(sendmsg, sendmsg_len, sendcmdbuf, sendmsg_len); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_setfilter_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_setfilter_info--send ok\n"); - } - return 0; + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_setfilter_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_setfilter_info--send ok\n"); + } + return 0; } -hi_u32 vlink_hi_channel_cmd_keeplive_info(hi_char *serverip, hi_char *port, - hi_char *expire) { - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - cJSON *pJsonRoot = NULL; - cJSON *pJson = NULL; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; +hi_u32 vlink_hi_channel_cmd_keeplive_info(hi_char* serverip, hi_char* port, hi_char* expire) +{ + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + cJSON * pJsonRoot = NULL; + cJSON *pJson = NULL; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - pJsonRoot = cJSON_CreateObject(); + pJsonRoot = cJSON_CreateObject(); - cJSON_AddStringToObject(pJsonRoot, "ip", serverip); - cJSON_AddStringToObject(pJsonRoot, "port", port); - cJSON_AddStringToObject(pJsonRoot, "expire", expire); - pJson = cJSON_Print(pJsonRoot); + cJSON_AddStringToObject(pJsonRoot, "ip", serverip); + cJSON_AddStringToObject(pJsonRoot, "port", port); + cJSON_AddStringToObject(pJsonRoot, "expire", expire); + pJson = cJSON_Print(pJsonRoot); - sample_log_print("vlink_hi_channel_cmd_keeplive_info-------pJson[%s]---\n", - pJson); + sample_log_print("vlink_hi_channel_cmd_keeplive_info-------pJson[%s]---\n", pJson); - datalen = strlen(pJson); + datalen = strlen(pJson); - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - sendcmdbuf[0] = CMD_SENDMSG_KEEPLIVE; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + sendcmdbuf[0] = CMD_SENDMSG_KEEPLIVE; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sample_log_print("vlink_hi_channel_cmd_keeplive_info-------sendcmdbuf-[%02X]-" - "[%02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_keeplive_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen); - free(pJson); - cJSON_Delete(pJsonRoot); + memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen); + free(pJson); + cJSON_Delete(pJsonRoot); - // memcpy_s(sendmsg, sendmsg_len, sendcmdbuf, sendmsg_len); + //memcpy_s(sendmsg, sendmsg_len, sendcmdbuf, sendmsg_len); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_keeplive_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_keeplive_info--send ok\n"); - } + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_keeplive_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_keeplive_info--send ok\n"); + } - return 0; + return 0; } -hi_u32 vlink_hi_channel_cmd_deepsleep_info(hi_void) { - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); +hi_u32 vlink_hi_channel_cmd_deepsleep_info(hi_void) +{ + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - sendcmdbuf[0] = CMD_SENDMSG_DEEPSLEEP; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - sample_log_print("vlink_hi_channel_cmd_deepsleep_info-------sendcmdbuf-[%02X]" - "-[%02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sendcmdbuf[0] = CMD_SENDMSG_DEEPSLEEP; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_deepsleep_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_deepsleep_info--send ok\n"); - } + sample_log_print("vlink_hi_channel_cmd_deepsleep_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - return 0; + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_deepsleep_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_deepsleep_info--send ok\n"); + } + + return 0; } -hi_u32 vlink_hi_channel_cmd_startap_info(hi_void) { - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; +hi_u32 vlink_hi_channel_cmd_startap_info(hi_void) +{ + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - sendcmdbuf[0] = CMD_SENDMSG_STARTAP; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendcmdbuf[0] = CMD_SENDMSG_STARTAP; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - sample_log_print("vlink_hi_channel_cmd_startap_info-------sendcmdbuf-[%02X]-[" - "%02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_startap_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_startap_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_startap_info--send ok\n"); - } + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_startap_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_startap_info--send ok\n"); + } - return 0; + return 0; } -hi_u32 vlink_hi_channel_cmd_startota(hi_void) { - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; +hi_u32 vlink_hi_channel_cmd_startota(hi_void) +{ + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - vlink_wifi_ota_start_info(); + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + vlink_wifi_ota_start_info(); - sendcmdbuf[0] = CMD_SENDMSG_STARTOTA; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendcmdbuf[0] = CMD_SENDMSG_STARTOTA; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - sample_log_print( - "vlink_hi_channel_cmd_startota-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_startota-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - sleep(2); + sleep(2); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_startota--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_startota--send ok\n"); - } + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_startota--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_startota--send ok\n"); + } - return 0; + return 0; } -hi_u32 vlink_hi_channel_cmd_getrssi_info(hi_void) { - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; +hi_u32 vlink_hi_channel_cmd_getrssi_info(hi_void) +{ - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - sendcmdbuf[0] = CMD_SENDMSG_GET_RSSI; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendcmdbuf[0] = CMD_SENDMSG_GET_RSSI; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sample_log_print("vlink_hi_channel_cmd_getrssi_info-------sendcmdbuf-[%02X]-[" - "%02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_getrssi_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_getrssi_info--send ok\n"); - } - return 0; + sample_log_print("vlink_hi_channel_cmd_getrssi_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_getrssi_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_getrssi_info--send ok\n"); + } + return 0; } -hi_u32 vlink_hi_channel_cmd_getversion_info(hi_void) { +hi_u32 vlink_hi_channel_cmd_getversion_info(hi_void) +{ - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - sendcmdbuf[0] = CMD_SENDMSG_GET_VERSION; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + sendcmdbuf[0] = CMD_SENDMSG_GET_VERSION; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - sample_log_print("vlink_hi_channel_cmd_getversion_info-------sendcmdbuf-[%" - "02X]-[%02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_getversion_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_getversion_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_getversion_info--send ok\n"); - } - return 0; + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_getversion_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_getversion_info--send ok\n"); + } + return 0; } -hi_u32 vlink_hi_channel_cmd_getwakecode_info(hi_void) { +hi_u32 vlink_hi_channel_cmd_getwakecode_info(hi_void) +{ - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - sendcmdbuf[0] = CMD_SENDMSG_GET_WAKECODE; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + sendcmdbuf[0] = CMD_SENDMSG_GET_WAKECODE; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - sample_log_print("vlink_hi_channel_cmd_getwakecode_info-------sendcmdbuf-[%" - "02X]-[%02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_getwakecode_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_getwakecode_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_getwakecode_info--send ok\n"); - } - return 0; + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_getwakecode_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_getwakecode_info--send ok\n"); + } + return 0; } -hi_u32 vlink_hi_channel_cmd_factoryreset_info(hi_void) { +hi_u32 vlink_hi_channel_cmd_factoryreset_info(hi_void) +{ - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - sendcmdbuf[0] = CMD_SENDMSG_FACTORY_RESET; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + sendcmdbuf[0] = CMD_SENDMSG_FACTORY_RESET; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - sample_log_print("vlink_hi_channel_cmd_factoryreset_info-------sendcmdbuf-[%" - "02X]-[%02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_factoryreset_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_factoryreset_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_factoryreset_info--send ok\n"); - } - return 0; + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_factoryreset_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_factoryreset_info--send ok\n"); + } + return 0; } -hi_u32 vlink_hi_channel_cmd_getpir_info(hi_void) { +hi_u32 vlink_hi_channel_cmd_getpir_info(hi_void) +{ - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - sendcmdbuf[0] = CMD_SENDMSG_PIR_GET; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + sendcmdbuf[0] = CMD_SENDMSG_PIR_GET; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - sample_log_print("vlink_hi_channel_cmd_getpir_info-------sendcmdbuf-[%02X]-[%" - "02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_getpir_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_getpir_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_getpir_info--send ok\n"); - } - return 0; + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_getpir_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_getpir_info--send ok\n"); + } + return 0; } -hi_u32 vlink_hi_channel_cmd_setpir_info(hi_u8 enable) { +hi_u32 vlink_hi_channel_cmd_setpir_info(hi_u8 enable) +{ - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - cJSON *pJsonRoot = NULL; - cJSON *pJson = NULL; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + cJSON * pJsonRoot = NULL; + cJSON *pJson = NULL; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - pJsonRoot = cJSON_CreateObject(); + pJsonRoot = cJSON_CreateObject(); - if (enable == 1) { - cJSON_AddNumberToObject(pJsonRoot, "enable", 1); - cJSON_AddNumberToObject(pJsonRoot, "time", 15); - cJSON_AddNumberToObject(pJsonRoot, "length", 0); - } else { - cJSON_AddNumberToObject(pJsonRoot, "enable", 0); - } + if (enable == 1) { + cJSON_AddNumberToObject(pJsonRoot, "enable", 1); + cJSON_AddNumberToObject(pJsonRoot, "time", 15); + cJSON_AddNumberToObject(pJsonRoot, "length", 0); + } else { + cJSON_AddNumberToObject(pJsonRoot, "enable", 0); + } - pJson = cJSON_Print(pJsonRoot); + pJson = cJSON_Print(pJsonRoot); - sample_log_print("vlink_hi_channel_cmd_setpir_info-------pJson[%s]---\n", - pJson); + sample_log_print("vlink_hi_channel_cmd_setpir_info-------pJson[%s]---\n", pJson); - datalen = strlen(pJson); + datalen = strlen(pJson); - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - sendcmdbuf[0] = CMD_SENDMSG_PIR_SET; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + sendcmdbuf[0] = CMD_SENDMSG_PIR_SET; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sample_log_print("vlink_hi_channel_cmd_setpir_info-------sendcmdbuf-[%02X]-[%" - "02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_setpir_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen); - free(pJson); - cJSON_Delete(pJsonRoot); + memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen); + free(pJson); + cJSON_Delete(pJsonRoot); - // memcpy_s(sendmsg, sendmsg_len, sendcmdbuf, sendmsg_len); + //memcpy_s(sendmsg, sendmsg_len, sendcmdbuf, sendmsg_len); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_setpir_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_setpir_info--send ok\n"); - } - return 0; + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_setpir_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_setpir_info--send ok\n"); + } + return 0; } -hi_u32 vlink_hi_channel_cmd_settuya_info(hi_void) { -#define TUYA_IP "42.192.35.108" -#define TUYA_PORT 443 -#define TUYA_DID "6c1d4426c02c8f4753umwk" -#define TUYA_KEY "19d72549f0a336ce" +hi_u32 vlink_hi_channel_cmd_settuya_info(hi_void) +{ +#define TUYA_IP "42.192.35.108" +#define TUYA_PORT 443 - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - cJSON *pJsonRoot = NULL; - cJSON *pJson = NULL; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; +#define TUYA_DID "6c1d4426c02c8f4753umwk" +#define TUYA_KEY "19d72549f0a336ce" - pJsonRoot = cJSON_CreateObject(); + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + cJSON * pJsonRoot = NULL; + cJSON *pJson = NULL; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - cJSON_AddStringToObject(pJsonRoot, "tyip", TUYA_IP); - cJSON_AddNumberToObject(pJsonRoot, "typort", TUYA_PORT); - cJSON_AddStringToObject(pJsonRoot, "tydid", TUYA_DID); - cJSON_AddStringToObject(pJsonRoot, "tykey", TUYA_KEY); + pJsonRoot = cJSON_CreateObject(); - pJson = cJSON_Print(pJsonRoot); + cJSON_AddStringToObject(pJsonRoot, "tyip", TUYA_IP); + cJSON_AddNumberToObject(pJsonRoot, "typort", TUYA_PORT); + cJSON_AddStringToObject(pJsonRoot, "tydid", TUYA_DID); + cJSON_AddStringToObject(pJsonRoot, "tykey", TUYA_KEY); - sample_log_print("vlink_hi_channel_cmd_setpir_info-------pJson[%s]---\n", - pJson); + pJson = cJSON_Print(pJsonRoot); - datalen = strlen(pJson); + sample_log_print("vlink_hi_channel_cmd_setpir_info-------pJson[%s]---\n", pJson); - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + datalen = strlen(pJson); - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - sendcmdbuf[0] = CMD_SENDMSG_TUYA_SET; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - sample_log_print("vlink_hi_channel_cmd_setpir_info-------sendcmdbuf-[%02X]-[%" - "02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sendcmdbuf[0] = CMD_SENDMSG_TUYA_SET; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen); - free(pJson); - cJSON_Delete(pJsonRoot); + sample_log_print("vlink_hi_channel_cmd_setpir_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_setpir_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_setpir_info--send ok\n"); - } - return 0; + memcpy_s(&sendcmdbuf[VLINK_SEND_MSG_HEAD_LEN], datalen, pJson, datalen); + free(pJson); + cJSON_Delete(pJsonRoot); + + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_setpir_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_setpir_info--send ok\n"); + } + return 0; } -hi_u32 vlink_hi_channel_cmd_getall_info(hi_void) { - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; +hi_u32 vlink_hi_channel_cmd_getall_info(hi_void) +{ + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - sendcmdbuf[0] = CMD_SENDMSG_GETALL; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + sendcmdbuf[0] = CMD_SENDMSG_GETALL; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - sample_log_print("vlink_hi_channel_cmd_getall_info-------sendcmdbuf-[%02X]-[%" - "02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_getall_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_getall_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_getall_info--send ok\n"); - } + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_getall_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_getall_info--send ok\n"); + } - return 0; + return 0; } -hi_u32 vlink_hi_channel_cmd_clrpir_info(hi_void) { - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; +hi_u32 vlink_hi_channel_cmd_clrpir_info(hi_void) +{ + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - sendcmdbuf[0] = CMD_SENDMSG_PIR_CLR; - sendcmdbuf[1] = (datalen >> 8) & 0xFF; - sendcmdbuf[2] = datalen & 0xFF; + sendcmdbuf[0] = CMD_SENDMSG_PIR_CLR; + sendcmdbuf[1] = (datalen >> 8) & 0xFF; + sendcmdbuf[2] = datalen & 0xFF; - sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; + sendmsg_len = datalen + VLINK_SEND_MSG_HEAD_LEN; - sample_log_print("vlink_hi_channel_cmd_clrpir_info-------sendcmdbuf-[%02X]-[%" - "02X]-[%02X]-\n", - sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); + sample_log_print("vlink_hi_channel_cmd_clrpir_info-------sendcmdbuf-[%02X]-[%02X]-[%02X]-\n", sendcmdbuf[0], sendcmdbuf[1], sendcmdbuf[2]); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_clrpir_info--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_clrpir_info--send ok\n"); - } + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_clrpir_info--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_clrpir_info--send ok\n"); + } - return 0; + return 0; } -hi_u32 vlink_hi_channel_cmd_reboot(hi_void) { - hi_u32 datalen = 0; - hi_u32 sendmsg_len = 0; - // cmd 1-byte, len 2-bytes, data 380 - unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; +hi_u32 vlink_hi_channel_cmd_reboot(hi_void) +{ + hi_u32 datalen = 0; + hi_u32 sendmsg_len = 0; + //cmd 1-byte, len 2-bytes, data 380 + unsigned char sendcmdbuf[VLINK_SEND_MSG_MAX_LEN] = {0}; - // memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); + //memset(sendcmdbuf, 0, VLINK_SEND_MSG_MAX_LEN); - sendcmdbuf[0] = 61; - // sendcmdbuf[1] = (datalen >> 8) & 0xFF; - // sendcmdbuf[2] = datalen & 0xFF; + sendcmdbuf[0] = 61; + //sendcmdbuf[1] = (datalen >> 8) & 0xFF; + //sendcmdbuf[2] = datalen & 0xFF; - sendmsg_len = 1; + sendmsg_len = 1; - sample_log_print("vlink_hi_channel_cmd_reboot-------sendcmdbuf-[%02X]-\n", - sendcmdbuf[0]); + sample_log_print("vlink_hi_channel_cmd_reboot-------sendcmdbuf-[%02X]-\n", sendcmdbuf[0]); - if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { - sample_log_print("vlink_hi_channel_cmd_reboot--send fail\n"); - } else { - sample_log_print("vlink_hi_channel_cmd_reboot--send ok\n"); - } + if (hi_channel_send_to_dev(sendcmdbuf, sendmsg_len) != HI_SUCCESS) { + sample_log_print("vlink_hi_channel_cmd_reboot--send fail\n"); + } else { + sample_log_print("vlink_hi_channel_cmd_reboot--send ok\n"); + } - return 0; + return 0; } diff --git a/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_hichannel_main.c b/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_hichannel_main.c index 1d9a47e0f..b8cf97576 100644 --- a/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_hichannel_main.c +++ b/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_hichannel_main.c @@ -1,37 +1,37 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights - * reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: sample cli file. + * Author: Hisilicon + * Create: 2020-09-09 */ /***************************************************************************** 1 Í·Îļþ°üº¬ *****************************************************************************/ -#include -#include -#include -#include -#include +#include #include -#include +#include #include #include -#include +#include +#include +#include +#include +#include +#include "securec.h" #include "hi_base.h" #include "hichannel_host.h" #include "hichannel_host_comm.h" -#include "securec.h" #include "cJSON.h" /***************************************************************************** 2 ºê¶¨Ò塢ȫ¾Ö±äÁ¿ *****************************************************************************/ -static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param, - hi_u32 len, hi_void *pmsg); -static hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, - hi_u32 len, hi_void *pmsg); +static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg); +static hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg); -static const sample_cmd_entry_stru g_sample_cmd[] = { +static const sample_cmd_entry_stru g_sample_cmd[] = { {"help", sample_help_cmd_process}, {"exit", sample_exit_cmd_process}, }; @@ -45,233 +45,231 @@ static const sample_cmd_entry_stru g_sample_cmd[] = { 3 ö¾Ù¡¢½á¹¹Ì嶨Òå *****************************************************************************/ typedef enum { - /* commands */ - SAMPLE_CMD_IOCTL, - SAMPLE_CMD_HELP, - SAMPLE_CMD_EXIT, - SAMPLE_CMD_BUTT, + /* commands */ + SAMPLE_CMD_IOCTL, + SAMPLE_CMD_HELP, + SAMPLE_CMD_EXIT, + SAMPLE_CMD_BUTT, } sample_cmd_e; typedef enum { - HOST_CMD_GET_MAC, - HOST_CMD_GET_IP, - HOST_CMD_SET_FILTER, - HOST_CMD_TBTT, -} host_cmd_e; + HOST_CMD_GET_MAC, + HOST_CMD_GET_IP, + HOST_CMD_SET_FILTER, + HOST_CMD_TBTT, +}host_cmd_e; /* command/event information */ typedef struct { - sample_cmd_e what; - hi_u32 len; - hi_u8 obj[CMD_MAX_LEN]; + sample_cmd_e what; + hi_u32 len; + hi_u8 obj[CMD_MAX_LEN]; } sample_message_s; struct snode { - sample_message_s message; - struct snode *next; + sample_message_s message; + struct snode *next; }; struct squeue { - struct snode *front; - struct snode *rear; + struct snode *front; + struct snode *rear; }; typedef struct { - pthread_mutex_t mut; - pthread_cond_t cond; - struct squeue cmd_queue; - pthread_t sock_thread; - hi_s32 sockfd; - hi_s32 eventfd; + pthread_mutex_t mut; + pthread_cond_t cond; + struct squeue cmd_queue; + pthread_t sock_thread; + hi_s32 sockfd; + hi_s32 eventfd; } sample_link_s; static hi_bool g_terminate = HI_FALSE; static sample_link_s *g_sample_link = HI_NULL; -static hi_char host_cmd[][MAX_CMD_LEN] = { - "cmd_get_mac", "cmd_get_ip", "cmd_set_filter", "cmd_set_netcfg", - "cmd_set_keeplive", "cmd_set_standby", "cmd_set_deepsleep"}; +static hi_char host_cmd[][MAX_CMD_LEN] = {"cmd_get_mac","cmd_get_ip","cmd_set_filter", "cmd_set_netcfg", "cmd_set_keeplive", "cmd_set_standby", "cmd_set_deepsleep"}; static hi_u8 g_netsta = 0; /***************************************************************************** 4 º¯ÊýʵÏÖ *****************************************************************************/ -static hi_void sample_usage(hi_void) { - printf("\nUsage:\n"); - printf("\tsample_cli quit quit sample_ap\n"); - printf("\tsample_cli help show this message\n"); - printf("\tsample_cli netcfg send ssid pwd\n"); - printf("\tsample_cli keeplive keeplive\n"); - printf("\tsample_cli standby stanby\n"); - printf("\tsample_cli deepsleep wifi deep sleep\n"); +static hi_void sample_usage(hi_void) +{ + printf("\nUsage:\n"); + printf("\tsample_cli quit quit sample_ap\n"); + printf("\tsample_cli help show this message\n"); + printf("\tsample_cli netcfg send ssid pwd\n"); + printf("\tsample_cli keeplive keeplive\n"); + printf("\tsample_cli standby stanby\n"); + printf("\tsample_cli deepsleep wifi deep sleep\n"); } -hi_s32 sample_str_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, - hi_void *pmsg) { - sample_unused(wdata); - sample_message_s *msg = (sample_message_s *)pmsg; - msg->what = SAMPLE_CMD_IOCTL; - msg->len = len; - (hi_void) memcpy_s(msg->obj, CMD_MAX_LEN, param, len); - msg->obj[CMD_MAX_LEN - 1] = '\0'; - return HI_SUCCESS; +hi_s32 sample_str_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg) +{ + sample_unused(wdata); + sample_message_s *msg = (sample_message_s *)pmsg; + msg->what = SAMPLE_CMD_IOCTL; + msg->len = len; + (hi_void)memcpy_s(msg->obj, CMD_MAX_LEN, param, len); + msg->obj[CMD_MAX_LEN - 1] = '\0'; + return HI_SUCCESS; } -hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, - hi_void *pmsg) { - sample_unused(wdata); - sample_unused(param); - sample_unused(len); - sample_message_s *msg = (sample_message_s *)pmsg; - msg->what = SAMPLE_CMD_HELP; - return HI_SUCCESS; +hi_s32 sample_help_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg) +{ + sample_unused(wdata); + sample_unused(param); + sample_unused(len); + sample_message_s *msg = (sample_message_s *)pmsg; + msg->what = SAMPLE_CMD_HELP; + return HI_SUCCESS; } -static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param, - hi_u32 len, hi_void *pmsg) { - sample_unused(wdata); - sample_unused(param); - sample_unused(len); - sample_message_s *msg = (sample_message_s *)pmsg; - msg->what = SAMPLE_CMD_EXIT; - return HI_SUCCESS; +static hi_s32 sample_exit_cmd_process(hi_void *wdata, hi_char *param, hi_u32 len, hi_void *pmsg) +{ + sample_unused(wdata); + sample_unused(param); + sample_unused(len); + sample_message_s *msg = (sample_message_s *)pmsg; + msg->what = SAMPLE_CMD_EXIT; + return HI_SUCCESS; } -static hi_void sample_cleanup(hi_void) { - sample_log_print("sample_cleanup enter\n"); +static hi_void sample_cleanup(hi_void) +{ + sample_log_print("sample_cleanup enter\n"); - vlink_hi_channel_cmd_reboot(); - usleep(100000); + vlink_hi_channel_cmd_reboot(); + usleep(100000); - if (g_sample_link->sock_thread) { - pthread_cancel(g_sample_link->sock_thread); - pthread_join(g_sample_link->sock_thread, HI_NULL); - } + if (g_sample_link->sock_thread) { + pthread_cancel(g_sample_link->sock_thread); + pthread_join(g_sample_link->sock_thread, HI_NULL); + } - pthread_mutex_destroy(&g_sample_link->mut); - pthread_cond_destroy(&g_sample_link->cond); + pthread_mutex_destroy(&g_sample_link->mut); + pthread_cond_destroy(&g_sample_link->cond); - if (g_sample_link->sockfd != -1) { - close(g_sample_link->sockfd); - } + if (g_sample_link->sockfd != -1) { + close(g_sample_link->sockfd); + } - if (g_sample_link->eventfd != -1) { - close(g_sample_link->eventfd); - } + if (g_sample_link->eventfd != -1) { + close(g_sample_link->eventfd); + } - if (g_sample_link != HI_NULL) { - free(g_sample_link); - g_sample_link = HI_NULL; - } + if (g_sample_link != HI_NULL) { + free(g_sample_link); + g_sample_link = HI_NULL; + } } -static hi_void sample_terminate(hi_s32 sig) { - sample_unused(sig); - sample_cleanup(); - g_terminate = HI_TRUE; - _exit(0); +static hi_void sample_terminate(hi_s32 sig) +{ + sample_unused(sig); + sample_cleanup(); + g_terminate = HI_TRUE; + _exit(0); } -static hi_void sample_power(hi_s32 sig) { sample_unused(sig); } - -static hi_s32 sample_wlan_init_up(hi_void) { - hi_s32 ret; - hi_char cmd[SYSTEM_CMD_SIZE] = {0}; - - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", - SYSTEM_NETDEV_NAME) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; - } - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s up error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } - - sample_log_print("net device up success\n"); - return HI_SUCCESS; +static hi_void sample_power(hi_s32 sig) +{ + sample_unused(sig); } -static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len) { - hi_s32 ret; - hi_char cmd[SYSTEM_CMD_SIZE] = {0}; +static hi_s32 sample_wlan_init_up(hi_void) +{ + hi_s32 ret; + hi_char cmd[SYSTEM_CMD_SIZE] = {0}; - if (len != WIFI_MAC_LEN) { - return HI_FAILURE; - } + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", SYSTEM_NETDEV_NAME) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s up error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down", - SYSTEM_NETDEV_NAME) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; - } - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s down error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } + sample_log_print("net device up success\n"); + return HI_SUCCESS; +} - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); +static hi_s32 sample_wlan_init_mac(hi_u8 *mac_addr, hi_u8 len) +{ + hi_s32 ret; + hi_char cmd[SYSTEM_CMD_SIZE] = {0}; + + if (len != WIFI_MAC_LEN) { + return HI_FAILURE; + } + + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down", SYSTEM_NETDEV_NAME) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s down error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } + + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); #if 0 if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s hw ether %x:%x:%x:%x:%x:%x", SYSTEM_NETDEV_NAME, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]) == -1) { #else - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, - "ifconfig %s hw ether %s", SYSTEM_NETDEV_NAME, - mac_addr) == -1) { + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s hw ether %s", SYSTEM_NETDEV_NAME, mac_addr) == -1) { #endif - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; -} -ret = system(cmd); -if (ret == -1) { - sample_log_print("%s set mac error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; -} + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s set mac error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } -(hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); -if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", - SYSTEM_NETDEV_NAME) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; -} -ret = system(cmd); -if (ret == -1) { - sample_log_print("%s up error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; -} + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", SYSTEM_NETDEV_NAME) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s up error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } -sample_log_print("net device set mac success\n"); + sample_log_print("net device set mac success\n"); -return HI_SUCCESS; -} - -static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 *netmask, - hi_u8 *gateway, hi_u8 *dnsfirst, - hi_u8 *dnssec, hi_u8 len) { - hi_s32 ret; - hi_char cmd[SYSTEM_CMD_SIZE] = {0}; - - sample_unused(len); - if ((ip_addr[0] == 0) && (ip_addr[1] == 0) && (ip_addr[2] == 0) && - (ip_addr[3] == 0)) { /* 1 2 3 ipaddr */ return HI_SUCCESS; - } +} - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down", - SYSTEM_NETDEV_NAME) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; - } - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s down error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } +static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 *netmask, hi_u8 *gateway, hi_u8 *dnsfirst, hi_u8 *dnssec, hi_u8 len) +{ + hi_s32 ret; + hi_char cmd[SYSTEM_CMD_SIZE] = {0}; - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + sample_unused(len); + if ((ip_addr[0] == 0) && (ip_addr[1] == 0) && (ip_addr[2] == 0) && (ip_addr[3] == 0)) { /* 1 2 3 ipaddr */ + return HI_SUCCESS; + } + + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s down", SYSTEM_NETDEV_NAME) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s down error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } + + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); #if 0 if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s %d.%d.%d.%d netmask %d.%d.%d.%d", SYSTEM_NETDEV_NAME, ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3] @@ -280,300 +278,295 @@ static hi_s32 sample_wlan_init_ip(hi_u8 *ip_addr, hi_u8 *netmask, return HI_FAILURE; } #else - (hi_void) snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, - "ifconfig %s %s netmask %s", SYSTEM_NETDEV_NAME, ip_addr, - netmask); + (hi_void)snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s %s netmask %s", SYSTEM_NETDEV_NAME, ip_addr, netmask); #endif - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s set ip error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s set ip error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", - SYSTEM_NETDEV_NAME) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; - } - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s up error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } - sample_log_print("net device set ip success\n"); + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s up", SYSTEM_NETDEV_NAME) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s up error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } + sample_log_print("net device set ip success\n"); - // route table - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - (hi_void) snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, - "route del default dev %s", SYSTEM_NETDEV_NAME); - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s error\n", cmd); - } +//route table + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + (hi_void)snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "route del default dev %s", SYSTEM_NETDEV_NAME); + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s error\n", cmd); + } - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - (hi_void) snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, - "route add default gw %s", gateway); - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s error\n", cmd); - return HI_FAILURE; - } - sample_log_print("net device set route success\n"); - // dns - ret = system("echo -n > /etc/resolv.conf"); - if (ret == -1) { - sample_log_print("%s error\n", cmd); - return HI_FAILURE; - } + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + (hi_void)snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "route add default gw %s", gateway); + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s error\n", cmd); + return HI_FAILURE; + } + sample_log_print("net device set route success\n"); +//dns + ret = system("echo -n > /etc/resolv.conf"); + if (ret == -1) { + sample_log_print("%s error\n", cmd); + return HI_FAILURE; + } - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - (hi_void) snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, - "echo nameserver %s >> /etc/resolv.conf", dnsfirst); - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s error\n", cmd); - return HI_FAILURE; - } + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + (hi_void)snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "echo nameserver %s >> /etc/resolv.conf", dnsfirst); + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s error\n", cmd); + return HI_FAILURE; + } - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - (hi_void) snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, - "echo nameserver %s >> /etc/resolv.conf", dnssec); - ret = system(cmd); - if (ret == -1) { - sample_log_print("%s error\n", cmd); - return HI_FAILURE; - } - sample_log_print("net device set dns success\n"); - return HI_SUCCESS; + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + (hi_void)snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "echo nameserver %s >> /etc/resolv.conf", dnssec); + ret = system(cmd); + if (ret == -1) { + sample_log_print("%s error\n", cmd); + return HI_FAILURE; + } + sample_log_print("net device set dns success\n"); + return HI_SUCCESS; } -static hi_s32 sample_wlan_flush_ip(hi_void) { - hi_s32 ret; - hi_char cmd[SYSTEM_CMD_SIZE] = {0}; +static hi_s32 sample_wlan_flush_ip(hi_void) +{ + hi_s32 ret; + hi_char cmd[SYSTEM_CMD_SIZE] = {0}; - (hi_void) memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); - if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, - "ifconfig %s 0.0.0.0", SYSTEM_NETDEV_NAME) == -1) { - sample_log_print("snprintf_s fail\n"); - return HI_FAILURE; - } - ret = system(cmd); - if (ret != 0) { - sample_log_print("%s flush error\n", SYSTEM_NETDEV_NAME); - return HI_FAILURE; - } - sample_log_print("net device flush ip success\n"); + (hi_void)memset_s(cmd, SYSTEM_CMD_SIZE, 0, SYSTEM_CMD_SIZE); + if (snprintf_s(cmd, SYSTEM_CMD_SIZE, SYSTEM_CMD_SIZE - 1, "ifconfig %s 0.0.0.0", SYSTEM_NETDEV_NAME) == -1) { + sample_log_print("snprintf_s fail\n"); + return HI_FAILURE; + } + ret = system(cmd); + if (ret != 0) { + sample_log_print("%s flush error\n", SYSTEM_NETDEV_NAME); + return HI_FAILURE; + } + sample_log_print("net device flush ip success\n"); } -static hi_void set_lo_ipaddr(hi_void) { - hi_s32 results; - hi_char cmd[SYSTEM_CMD_SIZE] = {0}; /* system Temporary variables */ - hi_char *spawn_args[] = {"ifconfig", "lo", "127.0.0.1", HI_NULL}; +static hi_void set_lo_ipaddr(hi_void) +{ + hi_s32 results; + hi_char cmd[SYSTEM_CMD_SIZE] = {0}; /* system Temporary variables */ + hi_char *spawn_args[] = {"ifconfig", "lo", "127.0.0.1", HI_NULL}; - results = sprintf_s( - cmd, sizeof(cmd), "%s %s %s", spawn_args[0], /* spawn_args[0]:ifconfig */ - spawn_args[1], spawn_args[2]); /* spawn_args[1]:lo,spawn_args[2]:ipaddr */ - if (results < EOK) { - sample_log_print("SAMPLE_STA: set lo ipaddr sprintf_s err!\n"); - return; - } + results = sprintf_s(cmd, sizeof(cmd), "%s %s %s", spawn_args[0], /* spawn_args[0]:ifconfig */ + spawn_args[1], spawn_args[2]); /* spawn_args[1]:lo,spawn_args[2]:ipaddr */ + if (results < EOK) { + sample_log_print("SAMPLE_STA: set lo ipaddr sprintf_s err!\n"); + return; + } - system(cmd); + system(cmd); } -static hi_s32 sample_sock_create(hi_void) { - if (g_sample_link == HI_NULL) { - return HI_FAILURE; - } +static hi_s32 sample_sock_create(hi_void) +{ + if (g_sample_link == HI_NULL) { + return HI_FAILURE; + } - g_sample_link->sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (g_sample_link->sockfd == -1) { - sample_log_print("error:%s", strerror(errno)); - return HI_FAILURE; - } + g_sample_link->sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (g_sample_link->sockfd == -1) { + sample_log_print("error:%s", strerror(errno)); + return HI_FAILURE; + } - struct sockaddr_in servaddr; - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(SOCK_PORT); + struct sockaddr_in servaddr; + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(SOCK_PORT); - if (bind(g_sample_link->sockfd, (const struct sockaddr *)&servaddr, - sizeof(servaddr)) == -1) { - sample_log_print("error:%s", strerror(errno)); - return HI_FAILURE; - } + if (bind(g_sample_link->sockfd, (const struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { + sample_log_print("error:%s", strerror(errno)); + return HI_FAILURE; + } - g_sample_link->eventfd = socket(AF_INET, SOCK_DGRAM, 0); - if (g_sample_link->eventfd == -1) { - sample_log_print("error:%s", strerror(errno)); - return HI_FAILURE; - } + g_sample_link->eventfd = socket(AF_INET, SOCK_DGRAM, 0); + if (g_sample_link->eventfd == -1) { + sample_log_print("error:%s", strerror(errno)); + return HI_FAILURE; + } - return HI_SUCCESS; + return HI_SUCCESS; } -static hi_s32 sample_enqueue(struct squeue *pqueue, - const sample_message_s *element) { - struct snode *pnew = HI_NULL; +static hi_s32 sample_enqueue(struct squeue *pqueue, const sample_message_s *element) +{ + struct snode *pnew = HI_NULL; - if (pqueue == HI_NULL || element == HI_NULL) { - return -1; - } - /* Create a new node */ - pnew = malloc(sizeof(struct snode)); - if (pnew == HI_NULL) { - return -1; - } + if (pqueue == HI_NULL || element == HI_NULL) { + return -1; + } + /* Create a new node */ + pnew = malloc(sizeof(struct snode)); + if (pnew == HI_NULL) { + return -1; + } - pnew->message = *element; - pnew->next = HI_NULL; + pnew->message = *element; + pnew->next = HI_NULL; - if (pqueue->rear == HI_NULL) { - /* queue is empty, set front and rear points to new node */ - pqueue->front = pqueue->rear = pnew; - } else { - /* queue is not empty, set rear points to the new node */ - pqueue->rear = pqueue->rear->next = pnew; - } + if (pqueue->rear == HI_NULL) { + /* queue is empty, set front and rear points to new node */ + pqueue->front = pqueue->rear = pnew; + } else { + /* queue is not empty, set rear points to the new node */ + pqueue->rear = pqueue->rear->next = pnew; + } - return HI_SUCCESS; + return HI_SUCCESS; } -static hi_s32 sample_dequeue(struct squeue *pqueue, sample_message_s *element) { - struct snode *p = HI_NULL; +static hi_s32 sample_dequeue(struct squeue *pqueue, sample_message_s *element) +{ + struct snode *p = HI_NULL; - if (pqueue == HI_NULL || element == HI_NULL) { - return HI_FAILURE; - } + if (pqueue == HI_NULL || element == HI_NULL) { + return HI_FAILURE; + } - if (pqueue->front == HI_NULL) { - return HI_FAILURE; - } + if (pqueue->front == HI_NULL) { + return HI_FAILURE; + } - *element = pqueue->front->message; - p = pqueue->front; - pqueue->front = p->next; - /* if the queue is empty, set rear = NULL */ - if (pqueue->front == HI_NULL) { - pqueue->rear = HI_NULL; - } + *element = pqueue->front->message; + p = pqueue->front; + pqueue->front = p->next; + /* if the queue is empty, set rear = NULL */ + if (pqueue->front == HI_NULL) { + pqueue->rear = HI_NULL; + } - free(p); - return HI_SUCCESS; + free(p); + return HI_SUCCESS; } -hi_s32 get_netcfg_info(char *ssid, char *password) { - FILE *fp; - int ret; +hi_s32 get_netcfg_info(char *ssid, char *password) +{ + FILE *fp; + int ret; - fp = fopen("/tmp/vlink_main.conf", "r"); - if (!fp) - return HI_FAILURE; - ret = fscanf(fp, "%s", ssid); - if (ret <= 0) - goto failure; - ret = fscanf(fp, "%s", password); - if (ret <= 0) - goto failure; + fp = fopen("/tmp/vlink_main.conf", "r"); + if (!fp) + return HI_FAILURE; + ret = fscanf(fp, "%s", ssid); + if (ret <= 0) + goto failure; + ret = fscanf(fp, "%s", password); + if (ret <= 0) + goto failure; - fclose(fp); - return HI_SUCCESS; + fclose(fp); + return HI_SUCCESS; failure: - fclose(fp); - return HI_FAILURE; + fclose(fp); + return HI_FAILURE; } -hi_s32 vlink_sample_str_cmd_process(hi_void *pmsg) { - sample_log_print("vlink_sample_str_cmd_process====pmsg=[%s]==\n", pmsg); - if (strncmp(pmsg, "netcfg", 6) == 0) { - char sendmsg[120] = {0}; - int msglen = 0; - char ssid[33] = {0}; - char password[65] = {0}; - if (get_netcfg_info(ssid, password) == HI_SUCCESS) { - vlink_hi_channel_cmd_netcfg_info(ssid, password, sendmsg, &msglen); - } else { +hi_s32 vlink_sample_str_cmd_process(hi_void *pmsg) +{ + sample_log_print("vlink_sample_str_cmd_process====pmsg=[%s]==\n", pmsg); + if (strncmp(pmsg, "netcfg", 6) == 0) { + char sendmsg[120] = {0}; + int msglen = 0; + char ssid[33] = {0}; + char password[65] = {0}; + if (get_netcfg_info(ssid, password) == HI_SUCCESS) { + vlink_hi_channel_cmd_netcfg_info(ssid, password, sendmsg, &msglen); + } else { #if 1 - vlink_hi_channel_cmd_netcfg_info("VLink", "Vlink8888", sendmsg, &msglen); + vlink_hi_channel_cmd_netcfg_info("VLink", "Vlink8888", sendmsg, &msglen); #else - vlink_hi_channel_cmd_netcfg_info("TP-LINK_AA04", "1427021981", sendmsg, - &msglen); + vlink_hi_channel_cmd_netcfg_info("TP-LINK_AA04", "1427021981", sendmsg, &msglen); #endif - // sample_log_print("vlink_sample_str_cmd_process====sendmsg=[%s]==\n", - // sendmsg); - } - hi_channel_send_to_dev(sendmsg, msglen); - } else if (strncmp(pmsg, "getip", 5) == 0) { - vlink_hi_channel_cmd_getip_info(); - } else if (strncmp(pmsg, "getmac", 6) == 0) { - vlink_hi_channel_cmd_getmac_info(); - } else if (strncmp(pmsg, "keeplive", 8) == 0) { - vlink_hi_channel_cmd_keeplive_info("192.168.3.116", "9000", "10"); - } else if (strncmp(pmsg, "filterwifi", 10) == 0) { - vlink_hi_channel_cmd_setfilter_info("wifi"); - } else if (strncmp(pmsg, "filtercam", 9) == 0) { - vlink_hi_channel_cmd_setfilter_info("camera"); - } else if (strncmp(pmsg, "deepsleep", 9) == 0) { - vlink_hi_channel_cmd_deepsleep_info(); - } else if (strncmp(pmsg, "startap", 7) == 0) { - vlink_hi_channel_cmd_startap_info(); - } else if (strncmp(pmsg, "tcpstart", 8) == 0) { - vlink_tcp_socket_start_info(); - } else if (strncmp(pmsg, "startota", 8) == 0) { - vlink_hi_channel_cmd_startota(); - } else if (strncmp(pmsg, "getrssi", 7) == 0) { - vlink_hi_channel_cmd_getrssi_info(); - } else if (strncmp(pmsg, "getver", 6) == 0) { - vlink_hi_channel_cmd_getversion_info(); - } else if (strncmp(pmsg, "wakecode", 8) == 0) { - vlink_hi_channel_cmd_getwakecode_info(); - } else if (strncmp(pmsg, "factory", 7) == 0) { - vlink_hi_channel_cmd_factoryreset_info(); - } else if (strncmp(pmsg, "pirset", 6) == 0) { - hi_u8 enable = 0; - sscanf_s(pmsg, "%*s %d", &enable); - vlink_hi_channel_cmd_setpir_info(enable); - } else if (strncmp(pmsg, "pirget", 6) == 0) { - vlink_hi_channel_cmd_getpir_info(); - } else if (strncmp(pmsg, "tyset", 5) == 0) { - vlink_hi_channel_cmd_settuya_info(); - } else if (strncmp(pmsg, "getall", 6) == 0) { - vlink_hi_channel_cmd_getall_info(); - } else if (strncmp(pmsg, "pirclr", 6) == 0) { - vlink_hi_channel_cmd_clrpir_info(); - } else if (strncmp(pmsg, "reboot", 6) == 0) { + //sample_log_print("vlink_sample_str_cmd_process====sendmsg=[%s]==\n", sendmsg); + } + hi_channel_send_to_dev(sendmsg, msglen); + } else if (strncmp(pmsg, "getip", 5) == 0) { + vlink_hi_channel_cmd_getip_info(); + } else if (strncmp(pmsg, "getmac", 6) == 0) { + vlink_hi_channel_cmd_getmac_info(); + } else if (strncmp(pmsg, "keeplive", 8) == 0) { + vlink_hi_channel_cmd_keeplive_info("192.168.3.116", "9000", "10"); + } else if (strncmp(pmsg, "filterwifi", 10) == 0) { + vlink_hi_channel_cmd_setfilter_info("wifi"); + } else if (strncmp(pmsg, "filtercam", 9) == 0) { + vlink_hi_channel_cmd_setfilter_info("camera"); + } else if (strncmp(pmsg, "deepsleep", 9) == 0) { + vlink_hi_channel_cmd_deepsleep_info(); + } else if (strncmp(pmsg, "startap", 7) == 0) { + vlink_hi_channel_cmd_startap_info(); + } else if (strncmp(pmsg, "tcpstart", 8) == 0) { + vlink_tcp_socket_start_info(); + } else if (strncmp(pmsg, "startota", 8) == 0) { + vlink_hi_channel_cmd_startota(); + } else if (strncmp(pmsg, "getrssi", 7) == 0) { + vlink_hi_channel_cmd_getrssi_info(); + } else if (strncmp(pmsg, "getver", 6) == 0) { + vlink_hi_channel_cmd_getversion_info(); + } else if (strncmp(pmsg, "wakecode", 8) == 0) { + vlink_hi_channel_cmd_getwakecode_info(); + } else if (strncmp(pmsg, "factory", 7) == 0) { + vlink_hi_channel_cmd_factoryreset_info(); + } else if (strncmp(pmsg, "pirset", 6) == 0) { + hi_u8 enable = 0; + sscanf_s(pmsg, "%*s %d", &enable); + vlink_hi_channel_cmd_setpir_info(enable); + } else if (strncmp(pmsg, "pirget", 6) == 0) { + vlink_hi_channel_cmd_getpir_info(); + } else if (strncmp(pmsg, "tyset", 5) == 0) { + vlink_hi_channel_cmd_settuya_info(); + } else if (strncmp(pmsg, "getall", 6) == 0) { + vlink_hi_channel_cmd_getall_info(); + } else if (strncmp(pmsg, "pirclr", 6) == 0) { + vlink_hi_channel_cmd_clrpir_info(); + } else if (strncmp(pmsg, "reboot", 6) == 0) { vlink_hi_channel_cmd_reboot(); - } + } - return HI_SUCCESS; + return HI_SUCCESS; } -static hi_void *sample_sock_thread(hi_void *args) { - hi_char link_buf[SOCK_BUF_MAX]; - ssize_t recvbytes = 0; - sample_message_s message; - struct sockaddr_in clientaddr; - socklen_t addrlen = sizeof(clientaddr); - sample_unused(args); - while (1) { - (hi_void) memset_s(link_buf, sizeof(link_buf), 0, sizeof(link_buf)); - (hi_void) memset_s(&clientaddr, sizeof(struct sockaddr_in), 0, addrlen); +static hi_void *sample_sock_thread(hi_void *args) +{ + hi_char link_buf[SOCK_BUF_MAX]; + ssize_t recvbytes = 0; + sample_message_s message; + struct sockaddr_in clientaddr; + socklen_t addrlen = sizeof(clientaddr); + sample_unused(args); - recvbytes = recvfrom(g_sample_link->sockfd, link_buf, sizeof(link_buf), 0, - (struct sockaddr *)&clientaddr, &addrlen); - if (recvbytes < 0) { - if (errno == EINTR) { - usleep(SLEEP_TIME); - continue; - } else { - sample_log_print("recvfrom error! fd:%d\n", g_sample_link->sockfd); - return HI_NULL; - } - } + while (1) { + (hi_void)memset_s(link_buf, sizeof(link_buf), 0, sizeof(link_buf)); + (hi_void)memset_s(&clientaddr, sizeof(struct sockaddr_in), 0, addrlen); + + recvbytes = recvfrom(g_sample_link->sockfd, link_buf, sizeof(link_buf), 0, (struct sockaddr *)&clientaddr, &addrlen); + if (recvbytes < 0) { + if (errno == EINTR) { + usleep(SLEEP_TIME); + continue; + } else { + sample_log_print("recvfrom error! fd:%d\n", g_sample_link->sockfd); + return HI_NULL; + } + } #if 0 if (sample_sock_cmd_entry(g_sample_link, link_buf, recvbytes, (hi_void *)&message) != HI_SUCCESS) { sample_log_print("sample_str_cmd_process entry\n"); @@ -584,27 +577,25 @@ static hi_void *sample_sock_thread(hi_void *args) { } sample_str_cmd_process(g_sample_link, link_buf, recvbytes, (hi_void *)&message); #endif - sample_log_print("sample_sock_thread====recvfrom string=[%s]==\n", - link_buf); + sample_log_print("sample_sock_thread====recvfrom string=[%s]==\n", link_buf); - if (vlink_sample_str_cmd_process(link_buf) != HI_SUCCESS) { - sample_log_print("vlink_sample_str_cmd_process error\n"); + if (vlink_sample_str_cmd_process(link_buf) != HI_SUCCESS) { + sample_log_print("vlink_sample_str_cmd_process error\n"); + } + + //sample_str_cmd_process(g_sample_link, link_buf, recvbytes, (hi_void *)&message); + + if (sendto(g_sample_link->sockfd, "OK", strlen("OK"), MSG_DONTWAIT, (const struct sockaddr *)&clientaddr, + addrlen) == -1) { + sample_log_print("sendto error!fd:%d\n", g_sample_link->sockfd); + } + + pthread_mutex_lock(&g_sample_link->mut); + if (sample_enqueue(&g_sample_link->cmd_queue, &message) == HI_SUCCESS) { + pthread_cond_signal(&g_sample_link->cond); + } + pthread_mutex_unlock(&g_sample_link->mut); } - - // sample_str_cmd_process(g_sample_link, link_buf, recvbytes, (hi_void - // *)&message); - - if (sendto(g_sample_link->sockfd, "OK", strlen("OK"), MSG_DONTWAIT, - (const struct sockaddr *)&clientaddr, addrlen) == -1) { - sample_log_print("sendto error!fd:%d\n", g_sample_link->sockfd); - } - - pthread_mutex_lock(&g_sample_link->mut); - if (sample_enqueue(&g_sample_link->cmd_queue, &message) == HI_SUCCESS) { - pthread_cond_signal(&g_sample_link->cond); - } - pthread_mutex_unlock(&g_sample_link->mut); - } } #if 0 @@ -634,356 +625,372 @@ void sample_link_rec_cb(unsigned char *msg_data, int len) } } #else -hi_s32 vlink_hi_channel_set_mac(hi_char *macaddr) { - hi_s32 ret; - // hi_u8 mactmp[6] = {0}; +hi_s32 vlink_hi_channel_set_mac(hi_char *macaddr) +{ + hi_s32 ret; + //hi_u8 mactmp[6] = {0}; - // sscanf(macaddr, "%02X:%02X:%02X:%02X:%02X:%02X", mactmp[0], mactmp[1], - // mactmp[2], mactmp[3], mactmp[4], mactmp[5]); - - sample_log_print("vlink_hi_channel_set_mac======mac_addr:%s\n", macaddr); - ret = sample_wlan_init_mac(macaddr, WIFI_MAC_LEN); - if (ret != HI_SUCCESS) { - sample_log_print("sample_wlan_init_mac is fail\n"); - } - - return ret; -} - -hi_s32 vlink_wifi_work_status_ret(hi_char *workstatus) { - hi_s32 ret; - /* - VLINK_WIFI_NETWORK_NETCFG = 0, - VLINK_WIFI_NETWORK_CONNECTING, - VLINK_WIFI_NETWORK_CONNECTE_OK, - VLINK_WIFI_NETWORK_DISCONNECTE, - VLINK_WIFI_NETWORK_DHCP_OK, - VLINK_WIFI_NETWORK_DHCP_ERR, - VLINK_WIFI_NETWORK_NOAP, - VLINK_WIFI_NETWORK_PWD_ERR, - VLINK_WIFI_NETWORK_OTH_ERR, - */ - sample_log_print("vlink_wifi_work_status_ret======workstatus:%s\n", - workstatus); - - switch (atoi(workstatus)) { - case 0: - sample_log_print("vlink_wifi_work_status_ret======net config\n"); - break; - case 1: - sample_log_print("vlink_wifi_work_status_ret======net connecting\n"); - break; - case 2: - sample_log_print("vlink_wifi_work_status_ret======net connect ok\n"); - break; - case 3: - sample_log_print("vlink_wifi_work_status_ret======net disconnect\n"); - break; - case 4: - sample_log_print("vlink_wifi_work_status_ret======net dhcp ok\n"); - break; - case 5: - sample_log_print("vlink_wifi_work_status_ret======net dhcp error\n"); - break; - case 6: - sample_log_print("vlink_wifi_work_status_ret======net no ap\n"); - break; - case 7: - sample_log_print("vlink_wifi_work_status_ret======net password error\n"); - break; - case 8: - sample_log_print("vlink_wifi_work_status_ret======net other error\n"); - break; - } - - return ret; -} - -hi_s32 sample_send_event(unsigned char *msg_data, int len) { - struct sockaddr_in servaddr; - - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); - servaddr.sin_port = htons(SOCK_EVENT_PORT); - - if (sendto(g_sample_link->eventfd, msg_data, len, MSG_DONTWAIT, - (const struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { - sample_log_print("sendto error!fd:%d\n", g_sample_link->eventfd); - return HI_FAILURE; - } - - return HI_SUCCESS; -} - -void sample_link_rec_cb(unsigned char *msg_data, int len) { - hi_s32 ret; - hi_s32 index; - - cJSON *item; - sample_log_print("sample_link_rec_cb:--start--\n"); - if ((len == 0) || (msg_data == HI_NULL)) { - return; - } - sample_log_print("sample_link_rec_cb:msg_data-[%s]-[%d]--\n", msg_data, len); - cJSON *root = cJSON_Parse(msg_data); - if (NULL == root) { - sample_log_print("sample_link_rec_cb:parseJson---Parse fail\n"); - return; - } - - item = cJSON_GetObjectItem(root, "cmd"); - if (NULL != item) { - hi_u8 cmdval = atoi(item->valuestring); - switch (cmdval) { - case 1: - - break; - case 2: { - hi_char macaddr[20] = {0}; - item = cJSON_GetObjectItem(root, "mac"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - vlink_hi_channel_set_mac(item->valuestring); - } - - sample_send_event(msg_data, len); - } break; - case 3: { - hi_char ipaddr[20] = {0}; - hi_char nwaddr[20] = {0}; - hi_char gwaddr[20] = {0}; - hi_char dnsfaddr[20] = {0}; - hi_char dnssaddr[20] = {0}; - - item = cJSON_GetObjectItem(root, "ip"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - memcpy_s(ipaddr, 20, item->valuestring, strlen(item->valuestring)); - if (strcmp(ipaddr, "0.0.0.0") != 0) { - g_netsta = 4; + //sscanf(macaddr, "%02X:%02X:%02X:%02X:%02X:%02X", mactmp[0], mactmp[1], mactmp[2], mactmp[3], mactmp[4], mactmp[5]); + + sample_log_print("vlink_hi_channel_set_mac======mac_addr:%s\n", macaddr); + ret = sample_wlan_init_mac(macaddr, WIFI_MAC_LEN); + if (ret != HI_SUCCESS) { + sample_log_print("sample_wlan_init_mac is fail\n"); } - } - item = cJSON_GetObjectItem(root, "nm"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - memcpy_s(nwaddr, 20, item->valuestring, strlen(item->valuestring)); - } - item = cJSON_GetObjectItem(root, "gw"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - memcpy_s(gwaddr, 20, item->valuestring, strlen(item->valuestring)); - } - item = cJSON_GetObjectItem(root, "dns1"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - memcpy_s(dnsfaddr, 20, item->valuestring, strlen(item->valuestring)); - } - item = cJSON_GetObjectItem(root, "dns2"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - memcpy_s(dnssaddr, 20, item->valuestring, strlen(item->valuestring)); - } - sample_wlan_init_ip(ipaddr, nwaddr, gwaddr, dnsfaddr, dnssaddr, 0); + return ret; +} - sample_send_event(msg_data, len); - } break; - case 4: +hi_s32 vlink_wifi_work_status_ret(hi_char *workstatus) +{ + hi_s32 ret; +/* + VLINK_WIFI_NETWORK_NETCFG = 0, + VLINK_WIFI_NETWORK_CONNECTING, + VLINK_WIFI_NETWORK_CONNECTE_OK, + VLINK_WIFI_NETWORK_DISCONNECTE, + VLINK_WIFI_NETWORK_DHCP_OK, + VLINK_WIFI_NETWORK_DHCP_ERR, + VLINK_WIFI_NETWORK_NOAP, + VLINK_WIFI_NETWORK_PWD_ERR, + VLINK_WIFI_NETWORK_OTH_ERR, +*/ + sample_log_print("vlink_wifi_work_status_ret======workstatus:%s\n", workstatus); - break; - case 5: + switch(atoi(workstatus)) + { + case 0: + sample_log_print("vlink_wifi_work_status_ret======net config\n"); + break; + case 1: + sample_log_print("vlink_wifi_work_status_ret======net connecting\n"); + break; + case 2: + sample_log_print("vlink_wifi_work_status_ret======net connect ok\n"); + break; + case 3: + sample_log_print("vlink_wifi_work_status_ret======net disconnect\n"); + break; + case 4: + sample_log_print("vlink_wifi_work_status_ret======net dhcp ok\n"); + break; + case 5: + sample_log_print("vlink_wifi_work_status_ret======net dhcp error\n"); + break; + case 6: + sample_log_print("vlink_wifi_work_status_ret======net no ap\n"); + break; + case 7: + sample_log_print("vlink_wifi_work_status_ret======net password error\n"); + break; + case 8: + sample_log_print("vlink_wifi_work_status_ret======net other error\n"); + break; + } - break; - case 6: + return ret; +} - break; - case 7: +hi_s32 sample_send_event(unsigned char *msg_data, int len) +{ + struct sockaddr_in servaddr; - break; - case 8: + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); + servaddr.sin_port = htons(SOCK_EVENT_PORT); - break; - case 9: - - break; - case 10: - - break; - case 11: // writeret - item = cJSON_GetObjectItem(root, "ret"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - vlink_wifi_ota_process_write_ret(item->valuestring); - } - break; - case 12: - - break; - case 13: - item = cJSON_GetObjectItem(root, "ret"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - vlink_wifi_work_status_ret(item->valuestring); - } - break; - case 14: - item = cJSON_GetObjectItem(root, "rssi"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - sample_log_print(":rssi-[%s]--\n", item->valuestring); - } - break; - case 15: - item = cJSON_GetObjectItem(root, "ver"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - sample_log_print(":ver-[%s]--\n", item->valuestring); - } - item = cJSON_GetObjectItem(root, "ker"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - sample_log_print(":ker-[%s]--\n", item->valuestring); - } - - sample_send_event(msg_data, len); - break; - case 16: - item = cJSON_GetObjectItem(root, "code"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - sample_log_print(":code-[%s]--\n", item->valuestring); - } - break; - case 17: - - break; - case 18: - - break; - case 19: - item = cJSON_GetObjectItem(root, "enable"); - if ((NULL != item) && (NULL != item->valuestring) && - (0 != strlen(item->valuestring))) { - sample_log_print(":pir enable-[%s]--\n", item->valuestring); - } - break; - case 20: - sample_send_event(msg_data, len); - break; - case 21: { - hi_u8 netsta; - - item = cJSON_GetObjectItem(root, "netsta"); - if ((NULL != item)) { - sample_log_print(":netsta-[%d]--\n", item->valueint); - netsta = item->valueint; - if ((g_netsta != netsta) && (netsta == 6)) { - sample_wlan_flush_ip(); - } - g_netsta = netsta; - } - } break; - case 22: - sample_send_event(msg_data, len); - break; - default: // - - break; + if (sendto(g_sample_link->eventfd, msg_data, len, MSG_DONTWAIT, (const struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { + sample_log_print("sendto error!fd:%d\n", g_sample_link->eventfd); + return HI_FAILURE; } - } else { - sample_log_print("sample_link_rec_cb:parseJson-cmd--Parse fail\n"); - cJSON_Delete(root); - return; - } + return HI_SUCCESS; +} - cJSON_Delete(root); - return; +void sample_link_rec_cb(unsigned char *msg_data, int len) +{ + hi_s32 ret; + hi_s32 index; + + cJSON* item; + sample_log_print("sample_link_rec_cb:--start--\n"); + if ((len == 0) || (msg_data == HI_NULL)) { + return; + } + sample_log_print("sample_link_rec_cb:msg_data-[%s]-[%d]--\n", msg_data, len); + cJSON* root = cJSON_Parse(msg_data); + if(NULL == root) + { + sample_log_print("sample_link_rec_cb:parseJson---Parse fail\n"); + return; + } + + item = cJSON_GetObjectItem(root, "cmd"); + if(NULL != item) + { + hi_u8 cmdval = atoi(item->valuestring); + switch(cmdval) + { + case 1: + + break; + case 2: + { + hi_char macaddr[20] = {0}; + item = cJSON_GetObjectItem(root, "mac"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + vlink_hi_channel_set_mac(item->valuestring); + } + + sample_send_event(msg_data, len); + } + break; + case 3: + { + hi_char ipaddr[20] = {0}; + hi_char nwaddr[20] = {0}; + hi_char gwaddr[20] = {0}; + hi_char dnsfaddr[20] = {0}; + hi_char dnssaddr[20] = {0}; + + item = cJSON_GetObjectItem(root, "ip"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + memcpy_s(ipaddr, 20, item->valuestring, strlen(item->valuestring)); + if(strcmp(ipaddr, "0.0.0.0") != 0) + { + g_netsta = 4; + } + } + item = cJSON_GetObjectItem(root, "nm"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + memcpy_s(nwaddr, 20, item->valuestring, strlen(item->valuestring)); + } + item = cJSON_GetObjectItem(root, "gw"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + memcpy_s(gwaddr, 20, item->valuestring, strlen(item->valuestring)); + } + item = cJSON_GetObjectItem(root, "dns1"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + memcpy_s(dnsfaddr, 20, item->valuestring, strlen(item->valuestring)); + } + item = cJSON_GetObjectItem(root, "dns2"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + memcpy_s(dnssaddr, 20, item->valuestring, strlen(item->valuestring)); + } + + sample_wlan_init_ip(ipaddr, nwaddr, gwaddr, dnsfaddr, dnssaddr, 0); + + sample_send_event(msg_data, len); + } + break; + case 4: + + break; + case 5: + + break; + case 6: + + break; + case 7: + + break; + case 8: + + break; + case 9: + + break; + case 10: + + break; + case 11://writeret + item = cJSON_GetObjectItem(root, "ret"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + vlink_wifi_ota_process_write_ret(item->valuestring); + } + break; + case 12: + + break; + case 13: + item = cJSON_GetObjectItem(root, "ret"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + vlink_wifi_work_status_ret(item->valuestring); + } + break; + case 14: + item = cJSON_GetObjectItem(root, "rssi"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + sample_log_print(":rssi-[%s]--\n", item->valuestring); + } + break; + case 15: + item = cJSON_GetObjectItem(root, "ver"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + sample_log_print(":ver-[%s]--\n", item->valuestring); + } + item = cJSON_GetObjectItem(root, "ker"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + sample_log_print(":ker-[%s]--\n", item->valuestring); + } + + sample_send_event(msg_data, len); + break; + case 16: + item = cJSON_GetObjectItem(root, "code"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + sample_log_print(":code-[%s]--\n", item->valuestring); + } + break; + case 17: + + break; + case 18: + + break; + case 19: + item = cJSON_GetObjectItem(root, "enable"); + if((NULL != item) && (NULL != item->valuestring) && (0 != strlen(item->valuestring))) + { + sample_log_print(":pir enable-[%s]--\n", item->valuestring); + } + break; + case 20: + sample_send_event(msg_data, len); + break; + case 21: + { + hi_u8 netsta; + + item = cJSON_GetObjectItem(root, "netsta"); + if((NULL != item)) + { + sample_log_print(":netsta-[%d]--\n", item->valueint); + netsta = item->valueint; + if((g_netsta != netsta) && (netsta == 6)) + { + sample_wlan_flush_ip(); + } + g_netsta = netsta; + } + } + break; + case 22: + sample_send_event(msg_data, len); + break; + default: // + + break; + } + + } else { + sample_log_print("sample_link_rec_cb:parseJson-cmd--Parse fail\n"); + cJSON_Delete(root); + return; + } + + cJSON_Delete(root); + return; } #endif -int main(int argc, char *argv[]) { - hi_s32 ret; - sample_unused(argc); - sample_unused(argv); - set_lo_ipaddr(); +int main(int argc, char *argv[]) +{ + hi_s32 ret; + sample_unused(argc); + sample_unused(argv); + set_lo_ipaddr(); - signal(SIGINT, sample_terminate); - signal(SIGTERM, sample_terminate); - signal(SIGPWR, sample_power); + signal(SIGINT, sample_terminate); + signal(SIGTERM, sample_terminate); + signal(SIGPWR, sample_power); - g_sample_link = (sample_link_s *)malloc(sizeof(sample_link_s)); - if (g_sample_link == HI_NULL) { - return -1; - } - - (void)memset_s(g_sample_link, sizeof(sample_link_s), 0, - sizeof(sample_link_s)); - pthread_mutex_init(&g_sample_link->mut, HI_NULL); - pthread_cond_init(&g_sample_link->cond, HI_NULL); - - if (sample_wlan_init_up() != HI_SUCCESS) { - sample_log_print("sample_wlan_init_up is fail\n"); - } - - if (hi_channel_init() != HI_SUCCESS) { - sample_log_print("hi_channel_init is fail\n"); - } else { - sample_log_print("hi_channel_init is ok\n"); - } - - hi_channel_register_rx_cb(sample_link_rec_cb); - // vlink_hi_channel_cmd_getmac_info(); - // hi_channel_send_to_dev((hi_u8 *)host_cmd[HOST_CMD_GET_MAC], - // (hi_s32)strlen(host_cmd[HOST_CMD_GET_MAC])); hi_channel_send_to_dev((hi_u8 - // *)host_cmd[HOST_CMD_GET_IP], (hi_s32)strlen(host_cmd[HOST_CMD_GET_IP])); - - if (sample_sock_create() != HI_SUCCESS) { - sample_log_print("create sock is fail\n"); - goto link_out; - } - - ret = pthread_create(&g_sample_link->sock_thread, HI_NULL, sample_sock_thread, - HI_NULL); - if (ret != HI_SUCCESS) { - sample_log_print("create sock thread is fail\n"); - goto link_out; - } - - vlink_hi_channel_cmd_getmac_info(); - - /* main loop */ - while (!g_terminate) { - sample_message_s message; - pthread_mutex_lock(&g_sample_link->mut); - while (sample_dequeue(&g_sample_link->cmd_queue, &message) != HI_SUCCESS) { - pthread_cond_wait(&g_sample_link->cond, &g_sample_link->mut); + g_sample_link = (sample_link_s *)malloc(sizeof(sample_link_s)); + if (g_sample_link == HI_NULL) { + return -1; } - pthread_mutex_unlock(&g_sample_link->mut); - sample_log_print("=====SAMPLE LOOP RECIEVE MSG-what[%d]:[%s] LEN:%d=====\n", - message.what, message.obj, message.len); - fflush(stdout); - /* - switch (message.what) { - case SAMPLE_CMD_HELP: - sample_usage(); - break; - case SAMPLE_CMD_EXIT: - g_terminate = HI_TRUE; - break; - case SAMPLE_CMD_IOCTL: - if (hi_channel_send_to_dev(message.obj, message.len) != - HI_SUCCESS) { SAMPLE_LOG_PRINT("sample_iwpriv_cmd send fail\n"); } else { - SAMPLE_LOG_PRINT("sample_iwpriv_cmd send ok\n"); - } - break; - default: - break; - } - */ - } + (void)memset_s(g_sample_link, sizeof(sample_link_s), 0, sizeof(sample_link_s)); + pthread_mutex_init(&g_sample_link->mut, HI_NULL); + pthread_cond_init(&g_sample_link->cond, HI_NULL); + + if (sample_wlan_init_up() != HI_SUCCESS) { + sample_log_print("sample_wlan_init_up is fail\n"); + } + + if (hi_channel_init() != HI_SUCCESS) { + sample_log_print("hi_channel_init is fail\n"); + } + else + { + sample_log_print("hi_channel_init is ok\n"); + } + + hi_channel_register_rx_cb(sample_link_rec_cb); + //vlink_hi_channel_cmd_getmac_info(); + //hi_channel_send_to_dev((hi_u8 *)host_cmd[HOST_CMD_GET_MAC], (hi_s32)strlen(host_cmd[HOST_CMD_GET_MAC])); + //hi_channel_send_to_dev((hi_u8 *)host_cmd[HOST_CMD_GET_IP], (hi_s32)strlen(host_cmd[HOST_CMD_GET_IP])); + + if (sample_sock_create() != HI_SUCCESS) { + sample_log_print("create sock is fail\n"); + goto link_out; + } + + ret = pthread_create(&g_sample_link->sock_thread, HI_NULL, sample_sock_thread, HI_NULL); + if (ret != HI_SUCCESS) { + sample_log_print("create sock thread is fail\n"); + goto link_out; + } + + vlink_hi_channel_cmd_getmac_info(); + + /* main loop */ + while (!g_terminate) { + sample_message_s message; + pthread_mutex_lock(&g_sample_link->mut); + while (sample_dequeue(&g_sample_link->cmd_queue, &message) != HI_SUCCESS) { + pthread_cond_wait(&g_sample_link->cond, &g_sample_link->mut); + } + pthread_mutex_unlock(&g_sample_link->mut); + sample_log_print("=====SAMPLE LOOP RECIEVE MSG-what[%d]:[%s] LEN:%d=====\n", message.what, message.obj, message.len); + fflush(stdout); + +/* + switch (message.what) { + case SAMPLE_CMD_HELP: + sample_usage(); + break; + case SAMPLE_CMD_EXIT: + g_terminate = HI_TRUE; + break; + case SAMPLE_CMD_IOCTL: + if (hi_channel_send_to_dev(message.obj, message.len) != HI_SUCCESS) { + SAMPLE_LOG_PRINT("sample_iwpriv_cmd send fail\n"); + } else { + SAMPLE_LOG_PRINT("sample_iwpriv_cmd send ok\n"); + } + break; + default: + break; + } +*/ + + } link_out: - sample_cleanup(); - return 0; + sample_cleanup(); + return 0; } + diff --git a/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_tcp_socket_main.c b/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_tcp_socket_main.c index a427452fa..a3cfcf884 100644 --- a/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_tcp_socket_main.c +++ b/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_tcp_socket_main.c @@ -1,91 +1,97 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights - * reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: sample cli file. + * Author: Hisilicon + * Create: 2020-09-09 */ /***************************************************************************** 1 Í·Îļþ°üº¬ *****************************************************************************/ -#include -#include -#include -#include -#include +#include #include -#include +#include #include #include -#include +#include +#include +#include +#include +#include +#include "securec.h" #include "hi_base.h" #include "hichannel_host.h" #include "hichannel_host_comm.h" -#include "securec.h" #include "cJSON.h" -#include -#include #include #include #include +#include +#include #define MAXLINE 4096 #define TCP_PORT 20000 -void *vlink_tcp_socket_thread(void *arg) { - int listenfd, connfd; - struct sockaddr_in servaddr; - char buff[4096]; - int n; +void* vlink_tcp_socket_thread(void* arg) +{ + int listenfd, connfd; + struct sockaddr_in servaddr; + char buff[4096]; + int n; - if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { - printf("create socket error: %s(errno: %d)\n", strerror(errno), errno); - return 0; - } - - memset(&servaddr, 0, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = inet_addr("192.168.43.1"); // htonl(INADDR_ANY); - servaddr.sin_port = htons(TCP_PORT); - - if (bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { - printf("bind socket error: %s(errno: %d)\n", strerror(errno), errno); - return 0; - } - - if (listen(listenfd, 10) == -1) { - printf("listen socket error: %s(errno: %d)\n", strerror(errno), errno); - return 0; - } - - printf("======waiting for client's request===ip[%s]=port[%d]==\n", - "192.168.43.1", TCP_PORT); - while (1) { - if ((connfd = accept(listenfd, (struct sockaddr *)NULL, NULL)) == -1) { - printf("accept socket error: %s(errno: %d)", strerror(errno), errno); - continue; - } - n = recv(connfd, buff, MAXLINE, 0); - buff[n] = '\0'; - printf("recv msg from client: %s\n", buff); - - if (send(connfd, buff, strlen(buff), 0) < 0) { - printf("send msg error: %s(errno: %d)\n", strerror(errno), errno); - return 0; + if( (listenfd = socket(AF_INET, SOCK_STREAM, 0)) == -1 ){ + printf("create socket error: %s(errno: %d)\n",strerror(errno),errno); + return 0; } - close(connfd); - } - close(listenfd); - return 0; + memset(&servaddr, 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = inet_addr("192.168.43.1");//htonl(INADDR_ANY); + servaddr.sin_port = htons(TCP_PORT); + + if( bind(listenfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) == -1){ + printf("bind socket error: %s(errno: %d)\n",strerror(errno),errno); + return 0; + } + + if( listen(listenfd, 10) == -1){ + printf("listen socket error: %s(errno: %d)\n",strerror(errno),errno); + return 0; + } + + printf("======waiting for client's request===ip[%s]=port[%d]==\n", "192.168.43.1", TCP_PORT); + while(1){ + if( (connfd = accept(listenfd, (struct sockaddr*)NULL, NULL)) == -1){ + printf("accept socket error: %s(errno: %d)",strerror(errno),errno); + continue; + } + n = recv(connfd, buff, MAXLINE, 0); + buff[n] = '\0'; + printf("recv msg from client: %s\n", buff); + + if( send(connfd, buff, strlen(buff), 0) < 0){ + printf("send msg error: %s(errno: %d)\n", strerror(errno), errno); + return 0; + } + + close(connfd); + } + close(listenfd); + return 0; } -int vlink_tcp_socket_start_info(void) { - pthread_t tcpserver; - int rc1 = 0; - rc1 = pthread_create(&tcpserver, NULL, vlink_tcp_socket_thread, NULL); - if (rc1 != 0) - printf("%s: %d\n", __func__, strerror(rc1)); +int vlink_tcp_socket_start_info(void) +{ + pthread_t tcpserver; + int rc1 = 0; + rc1 = pthread_create(&tcpserver, NULL, vlink_tcp_socket_thread, NULL); + if(rc1 != 0) + printf("%s: %d\n",__func__, strerror(rc1)); - pthread_detach(tcpserver); + pthread_detach(tcpserver); } + + + diff --git a/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_wifi_ota_main.c b/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_wifi_ota_main.c old mode 100644 new mode 100755 index 08380c6a2..5a52e87e5 --- a/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_wifi_ota_main.c +++ b/project/app/wifi_app/hisi_tools/app/vlinktest/vlink_wifi_ota_main.c @@ -1,178 +1,207 @@ /* - * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights - * reserved. Description: sample cli file. Author: Hisilicon Create: 2020-09-09 + * Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: sample cli file. + * Author: Hisilicon + * Create: 2020-09-09 */ /***************************************************************************** 1 Í·Îļþ°üº¬ *****************************************************************************/ -#include -#include -#include -#include -#include +#include #include -#include +#include #include #include -#include +#include +#include +#include +#include +#include +#include "securec.h" #include "hi_base.h" #include "hichannel_host.h" #include "hichannel_host_comm.h" -#include "securec.h" #include "cJSON.h" -#include -#include #include #include #include +#include +#include + +#include -#include - -#define SOCKET_DOMAIN "/tmp/wifiota.domain" +#define SOCKET_DOMAIN "/tmp/wifiota.domain" #define VLINK_WIFI_OTA_PATH "/mnt/T31ZL/030/Hi3861L_demo_ota.bin" #define MAXLINE 4096 #define TCP_PORT 20000 -static int create_wifi_ota_server_socket(void) { - int listen_fd; - int ret; - struct sockaddr_un srv_addr; - listen_fd = socket(PF_LOCAL, SOCK_DGRAM, 0); - if (listen_fd < 0) { - printf("cannot create communication socket\n"); - return -1; - } - // set server addr_param - srv_addr.sun_family = AF_LOCAL; - strncpy(srv_addr.sun_path, SOCKET_DOMAIN, sizeof(srv_addr.sun_path) - 1); - unlink(SOCKET_DOMAIN); - // bind sockfd & addr - ret = bind(listen_fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr)); - if (ret == -1) { - printf("cannot bind server socket\n"); - close(listen_fd); - unlink(SOCKET_DOMAIN); - return -1; - } - return listen_fd; -} +static int create_wifi_ota_server_socket(void) +{ + int listen_fd; + int ret; -void vlink_wifi_ota_process_write_ret(char *result) { + struct sockaddr_un srv_addr; + listen_fd = socket(PF_LOCAL, SOCK_DGRAM, 0); + if(listen_fd < 0) + { + printf("cannot create communication socket\n"); + return -1; + } + //set server addr_param + srv_addr.sun_family = AF_LOCAL; + strncpy(srv_addr.sun_path, SOCKET_DOMAIN, sizeof(srv_addr.sun_path) - 1); + unlink(SOCKET_DOMAIN); + //bind sockfd & addr + ret = bind(listen_fd, (struct sockaddr*)&srv_addr, sizeof(srv_addr)); + if(ret == -1) + { + printf("cannot bind server socket\n"); + close(listen_fd); + unlink(SOCKET_DOMAIN); + return -1; + } + + return listen_fd; +} + + +void vlink_wifi_ota_process_write_ret(char* result) +{ #define SENDSTRING "OK" - int ret = atoi(result); + int ret = atoi(result); - printf("vlink_wifi_ota_process_write_ret-[%d]-\n", ret); - if (ret == 0) { - int fd = -1; - struct sockaddr_un srv_addr; + printf("vlink_wifi_ota_process_write_ret-[%d]-\n", ret); + if (ret == 0) + { + int fd = -1; + struct sockaddr_un srv_addr; - // create socket - fd = socket(PF_LOCAL, SOCK_DGRAM, 0); - if (fd < 0) { - printf("cannot bind server socket\n"); - return; + //create socket + fd = socket(PF_LOCAL, SOCK_DGRAM, 0); + if (fd < 0) + { + printf("cannot bind server socket\n"); + return; + } + + srv_addr.sun_family = AF_LOCAL; + strcpy(srv_addr.sun_path, SOCKET_DOMAIN); + sendto(fd, SENDSTRING, strlen(SENDSTRING), 0, (struct sockaddr *)&srv_addr, sizeof(struct sockaddr_un)); + } + +} + + +int getIndexOfSigns(char ch) +{ + if(ch >= '0' && ch <= '9') + { + return ch - '0'; } - - srv_addr.sun_family = AF_LOCAL; - strcpy(srv_addr.sun_path, SOCKET_DOMAIN); - sendto(fd, SENDSTRING, strlen(SENDSTRING), 0, (struct sockaddr *)&srv_addr, - sizeof(struct sockaddr_un)); - } + if(ch >= 'A' && ch <='F') + { + return ch - 'A' + 10; + } + if(ch >= 'a' && ch <= 'f') + { + return ch - 'a' + 10; + } + return -1; } -int getIndexOfSigns(char ch) { - if (ch >= '0' && ch <= '9') { - return ch - '0'; - } - if (ch >= 'A' && ch <= 'F') { - return ch - 'A' + 10; - } - if (ch >= 'a' && ch <= 'f') { - return ch - 'a' + 10; - } - return -1; +int hexToDec(char *source) +{ + int sum = 0; + int t = 1; + int i, len; + + len = strlen(source); + for(i=len-1; i>=0; i--) + { + sum += t * getIndexOfSigns(*(source + i)); + t *= 16; + } + + return sum; } -int hexToDec(char *source) { - int sum = 0; - int t = 1; - int i, len; - - len = strlen(source); - for (i = len - 1; i >= 0; i--) { - sum += t * getIndexOfSigns(*(source + i)); - t *= 16; - } - - return sum; -} - -void *vlink_wifi_ota_thread(void *arg) { +void* vlink_wifi_ota_thread(void* arg) +{ #define BUFFSIZE 1450 - int listen_fd = create_wifi_ota_server_socket(); - char recv_buf[5]; - hi_uchar read_buf[BUFFSIZE]; - hi_uchar send_buf[SAMPLE_CMD_MAX_LEN]; - int send_len = 0; - int file_end = 0; - FILE *fpRead = NULL; + int listen_fd = create_wifi_ota_server_socket(); + char recv_buf[5]; + hi_uchar read_buf[BUFFSIZE]; + hi_uchar send_buf[SAMPLE_CMD_MAX_LEN]; + int send_len = 0; + int file_end = 0; + FILE *fpRead = NULL; + + printf("vlink_wifi_ota_thread------start-----------\n"); + if(listen_fd < 0) + { + printf("vlink_wifi_ota_thread--cannot creatServerSocket\n"); + unlink(SOCKET_DOMAIN); + return NULL; + } + fpRead = fopen(VLINK_WIFI_OTA_PATH, "rb"); + fseek(fpRead, 0, SEEK_SET); + + while (1) + { + int num = 0; + memset(recv_buf, 0, 5); + num = recvfrom (listen_fd, recv_buf, 5, 0, NULL, NULL); + if (num > 0) + { + recv_buf[num] = '\0'; + if (strcmp(recv_buf, "OK") == 0) + { + memset(send_buf, 0, SAMPLE_CMD_MAX_LEN); + send_buf[0] = CMD_SENDMSG_OTADATA; - printf("vlink_wifi_ota_thread------start-----------\n"); - if (listen_fd < 0) { - printf("vlink_wifi_ota_thread--cannot creatServerSocket\n"); - unlink(SOCKET_DOMAIN); - return NULL; - } - fpRead = fopen(VLINK_WIFI_OTA_PATH, "rb"); - fseek(fpRead, 0, SEEK_SET); - while (1) { - int num = 0; - memset(recv_buf, 0, 5); - num = recvfrom(listen_fd, recv_buf, 5, 0, NULL, NULL); - if (num > 0) { - recv_buf[num] = '\0'; - if (strcmp(recv_buf, "OK") == 0) { - memset(send_buf, 0, SAMPLE_CMD_MAX_LEN); - send_buf[0] = CMD_SENDMSG_OTADATA; + if (file_end == 0) + { + bzero (read_buf, BUFFSIZE); + int count = fread(read_buf, sizeof (char), BUFFSIZE, fpRead); + file_end = feof(fpRead); + printf ("%d, %d\n", count, file_end); + send_len = count + 3; + memcpy_s(&send_buf[3], count, read_buf, count); + } else { + send_len = 3; + } - if (file_end == 0) { - bzero(read_buf, BUFFSIZE); - int count = fread(read_buf, sizeof(char), BUFFSIZE, fpRead); - file_end = feof(fpRead); - printf("%d, %d\n", count, file_end); - send_len = count + 3; - memcpy_s(&send_buf[3], count, read_buf, count); - } else { - send_len = 3; - } + send_buf[1] = (send_len >> 8) & 0xFF; + send_buf[2] = send_len & 0xFF; - send_buf[1] = (send_len >> 8) & 0xFF; - send_buf[2] = send_len & 0xFF; - - if (hi_channel_send_to_dev(send_buf, send_len) != HI_SUCCESS) { - printf("vlink_hi_channel_cmd_startota--send fail\n"); - } else { - printf("vlink_hi_channel_cmd_startota--send ok\n"); - } - } - } - } - return NULL; + if (hi_channel_send_to_dev(send_buf, send_len) != HI_SUCCESS) { + printf("vlink_hi_channel_cmd_startota--send fail\n"); + } else { + printf("vlink_hi_channel_cmd_startota--send ok\n"); + } + } + } + } + return NULL; } -int vlink_wifi_ota_start_info(void) { - pthread_t wifiota; - int rc1 = 0; - rc1 = pthread_create(&wifiota, NULL, vlink_wifi_ota_thread, NULL); - if (rc1 != 0) - printf("%s: %d\n", __func__, strerror(rc1)); +int vlink_wifi_ota_start_info(void) +{ + pthread_t wifiota; + int rc1 = 0; + rc1 = pthread_create(&wifiota, NULL, vlink_wifi_ota_thread, NULL); + if(rc1 != 0) + printf("%s: %d\n",__func__, strerror(rc1)); - pthread_detach(wifiota); + pthread_detach(wifiota); } + + + diff --git a/project/app/wifi_app/hisi_tools/securec/fscanf_s.c b/project/app/wifi_app/hisi_tools/securec/fscanf_s.c index 0b0cc92f8..415cffc7e 100644 --- a/project/app/wifi_app/hisi_tools/securec/fscanf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/fscanf_s.c @@ -10,13 +10,12 @@ /* * * The fscanf_s function is equivalent to fscanf except that the c, s, - * and [ conversion specifiers apply to a pair of arguments (unless - * assignment suppression is indicated by a*) The fscanf function reads data - * from the current position of stream into the locations given by argument (if - * any). Each argument must be a pointer to a variable of a type that - * corresponds to a type specifier in format. format controls the interpretation - * of the input fields and has the same form and function as the format argument - * for scanf. + * and [ conversion specifiers apply to a pair of arguments (unless assignment suppression is indicated by a*) + * The fscanf function reads data from the current position of stream into + * the locations given by argument (if any). Each argument must be a pointer + * to a variable of a type that corresponds to a type specifier in format. + * format controls the interpretation of the input fields and has the same + * form and function as the format argument for scanf. * * * stream Pointer to FILE structure. @@ -27,20 +26,22 @@ * ... The convered value stored in user assigned address * * - * Each of these functions returns the number of fields successfully - * converted and assigned; the return value does not include fields that were - * read but not assigned. A return value of 0 indicates that no fields were - * assigned. return -1 if an error occurs. + * Each of these functions returns the number of fields successfully converted + * and assigned; the return value does not include fields that were read but + * not assigned. A return value of 0 indicates that no fields were assigned. + * return -1 if an error occurs. */ -int fscanf_s(FILE *stream, const char *format, ...) { - int ret; /* If initialization causes e838 */ - va_list argList; +int fscanf_s(FILE *stream, const char *format, ...) +{ + int ret; /* If initialization causes e838 */ + va_list argList; - va_start(argList, format); - ret = vfscanf_s(stream, format, argList); - va_end(argList); - (void)argList; /* To clear e438 last value assigned not used , the compiler - will optimize this code */ + va_start(argList, format); + ret = vfscanf_s(stream, format, argList); + va_end(argList); + (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */ - return ret; + return ret; } + + diff --git a/project/app/wifi_app/hisi_tools/securec/fwscanf_s.c b/project/app/wifi_app/hisi_tools/securec/fwscanf_s.c index 26d66045f..909c401b7 100644 --- a/project/app/wifi_app/hisi_tools/securec/fwscanf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/fwscanf_s.c @@ -9,12 +9,12 @@ /* * - * The fwscanf_s function is the wide-character equivalent of the - * fscanf_s function The fwscanf_s function reads data from the current position - * of stream into the locations given by argument (if any). Each argument must - * be a pointer to a variable of a type that corresponds to a type specifier in - * format. format controls the interpretation of the input fields and has the - * same form and function as the format argument for scanf. + * The fwscanf_s function is the wide-character equivalent of the fscanf_s function + * The fwscanf_s function reads data from the current position of stream into + * the locations given by argument (if any). Each argument must be a pointer + * to a variable of a type that corresponds to a type specifier in format. + * format controls the interpretation of the input fields and has the same + * form and function as the format argument for scanf. * * * stream Pointer to FILE structure. @@ -22,24 +22,25 @@ * ... Optional arguments. * * - * ... The converted value stored in user assigned - * address + * ... The converted value stored in user assigned address * * - * Each of these functions returns the number of fields successfully - * converted and assigned; the return value does not include fields that were - * read but not assigned. A return value of 0 indicates that no fields were - * assigned. return -1 if an error occurs. + * Each of these functions returns the number of fields successfully converted + * and assigned; the return value does not include fields that were read but + * not assigned. A return value of 0 indicates that no fields were assigned. + * return -1 if an error occurs. */ -int fwscanf_s(FILE *stream, const wchar_t *format, ...) { - int ret; /* If initialization causes e838 */ - va_list argList; +int fwscanf_s(FILE *stream, const wchar_t *format, ...) +{ + int ret; /* If initialization causes e838 */ + va_list argList; - va_start(argList, format); - ret = vfwscanf_s(stream, format, argList); - va_end(argList); - (void)argList; /* To clear e438 last value assigned not used , the compiler - will optimize this code */ + va_start(argList, format); + ret = vfwscanf_s(stream, format, argList); + va_end(argList); + (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */ - return ret; + return ret; } + + diff --git a/project/app/wifi_app/hisi_tools/securec/gets_s.c b/project/app/wifi_app/hisi_tools/securec/gets_s.c index 073538778..aceec5a15 100644 --- a/project/app/wifi_app/hisi_tools/securec/gets_s.c +++ b/project/app/wifi_app/hisi_tools/securec/gets_s.c @@ -7,24 +7,24 @@ #include "securecutil.h" -SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t len) { - int i; - /* No need to determine whether integer overflow exists */ - for (i = (int)(len - 1); i >= 0 && (buffer[i] == '\r' || buffer[i] == '\n'); - --i) { - buffer[i] = '\0'; - } +SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t len) +{ + int i; + /* No need to determine whether integer overflow exists */ + for (i = (int)(len - 1); i >= 0 && (buffer[i] == '\r' || buffer[i] == '\n'); --i) { + buffer[i] = '\0'; + } } /* * * The gets_s function reads at most one less than the number of characters - * specified by destMax from the std input stream, into the array pointed to - * by buffer The line consists of all characters up to and including the first - * newline character ('\n'). gets_s then replaces the newline character with a - * null character ('\0') before returning the line. If the first character read - * is the end-of-file character, a null character is stored at the beginning of - * buffer and NULL is returned. + * specified by destMax from the std input stream, into the array pointed to by buffer + * The line consists of all characters up to and including + * the first newline character ('\n'). gets_s then replaces the newline + * character with a null character ('\0') before returning the line. + * If the first character read is the end-of-file character, a null character + * is stored at the beginning of buffer and NULL is returned. * * * buffer Storage location for input string. @@ -37,29 +37,29 @@ SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t len) { * buffer Successful operation * NULL Improper parameter or read fail */ -char *gets_s(char *buffer, size_t numberOfElements) { - size_t len; +char *gets_s(char *buffer, size_t numberOfElements) +{ + size_t len; #ifdef SECUREC_COMPATIBLE_WIN_FORMAT - size_t bufferSize = ((numberOfElements == (size_t)-1) ? SECUREC_STRING_MAX_LEN - : numberOfElements); + size_t bufferSize = ((numberOfElements == (size_t)-1) ? SECUREC_STRING_MAX_LEN : numberOfElements); #else - size_t bufferSize = numberOfElements; + size_t bufferSize = numberOfElements; #endif - if (buffer == NULL || bufferSize == 0 || - bufferSize > SECUREC_STRING_MAX_LEN) { - SECUREC_ERROR_INVALID_PARAMTER("gets_s"); - return NULL; - } + if (buffer == NULL || bufferSize == 0 || bufferSize > SECUREC_STRING_MAX_LEN) { + SECUREC_ERROR_INVALID_PARAMTER("gets_s"); + return NULL; + } - if (fgets(buffer, (int)bufferSize, SECUREC_STREAM_STDIN) == NULL) { - return NULL; - } + if (fgets(buffer, (int)bufferSize, SECUREC_STREAM_STDIN) == NULL) { + return NULL; + } - len = strlen(buffer); - if (len > 0 && len < bufferSize) { - SecTrimCRLF(buffer, len); - } + len = strlen(buffer); + if (len > 0 && len < bufferSize) { + SecTrimCRLF(buffer, len); + } - return buffer; + return buffer; } + diff --git a/project/app/wifi_app/hisi_tools/securec/memcpy_s.c b/project/app/wifi_app/hisi_tools/securec/memcpy_s.c index 042bea086..f1e104dc0 100644 --- a/project/app/wifi_app/hisi_tools/securec/memcpy_s.c +++ b/project/app/wifi_app/hisi_tools/securec/memcpy_s.c @@ -6,9 +6,8 @@ */ /* * [Standardize-exceptions] Use unsafe function: Portability - * [reason] Use unsafe function to implement security function to maintain - * platform compatibility. And sufficient input validation is performed before - * calling + * [reason] Use unsafe function to implement security function to maintain platform compatibility. + * And sufficient input validation is performed before calling */ #include "securecutil.h" @@ -22,474 +21,467 @@ #define SECUREC_MEMCOPY_THRESHOLD_SIZE 64UL #endif -#define SECUREC_SMALL_MEM_COPY(dest, src, count) \ - do { \ - if (SECUREC_ADDR_ALIGNED_8(dest) && SECUREC_ADDR_ALIGNED_8(src)) { \ - /* Use struct assignment */ \ - switch (count) { \ - case 1: \ - *(SecStrBuf1 *)(dest) = *(const SecStrBuf1 *)(src); \ - break; \ - case 2: \ - *(SecStrBuf2 *)(dest) = *(const SecStrBuf2 *)(src); \ - break; \ - case 3: \ - *(SecStrBuf3 *)(dest) = *(const SecStrBuf3 *)(src); \ - break; \ - case 4: \ - *(SecStrBuf4 *)(dest) = *(const SecStrBuf4 *)(src); \ - break; \ - case 5: \ - *(SecStrBuf5 *)(dest) = *(const SecStrBuf5 *)(src); \ - break; \ - case 6: \ - *(SecStrBuf6 *)(dest) = *(const SecStrBuf6 *)(src); \ - break; \ - case 7: \ - *(SecStrBuf7 *)(dest) = *(const SecStrBuf7 *)(src); \ - break; \ - case 8: \ - *(SecStrBuf8 *)(dest) = *(const SecStrBuf8 *)(src); \ - break; \ - case 9: \ - *(SecStrBuf9 *)(dest) = *(const SecStrBuf9 *)(src); \ - break; \ - case 10: \ - *(SecStrBuf10 *)(dest) = *(const SecStrBuf10 *)(src); \ - break; \ - case 11: \ - *(SecStrBuf11 *)(dest) = *(const SecStrBuf11 *)(src); \ - break; \ - case 12: \ - *(SecStrBuf12 *)(dest) = *(const SecStrBuf12 *)(src); \ - break; \ - case 13: \ - *(SecStrBuf13 *)(dest) = *(const SecStrBuf13 *)(src); \ - break; \ - case 14: \ - *(SecStrBuf14 *)(dest) = *(const SecStrBuf14 *)(src); \ - break; \ - case 15: \ - *(SecStrBuf15 *)(dest) = *(const SecStrBuf15 *)(src); \ - break; \ - case 16: \ - *(SecStrBuf16 *)(dest) = *(const SecStrBuf16 *)(src); \ - break; \ - case 17: \ - *(SecStrBuf17 *)(dest) = *(const SecStrBuf17 *)(src); \ - break; \ - case 18: \ - *(SecStrBuf18 *)(dest) = *(const SecStrBuf18 *)(src); \ - break; \ - case 19: \ - *(SecStrBuf19 *)(dest) = *(const SecStrBuf19 *)(src); \ - break; \ - case 20: \ - *(SecStrBuf20 *)(dest) = *(const SecStrBuf20 *)(src); \ - break; \ - case 21: \ - *(SecStrBuf21 *)(dest) = *(const SecStrBuf21 *)(src); \ - break; \ - case 22: \ - *(SecStrBuf22 *)(dest) = *(const SecStrBuf22 *)(src); \ - break; \ - case 23: \ - *(SecStrBuf23 *)(dest) = *(const SecStrBuf23 *)(src); \ - break; \ - case 24: \ - *(SecStrBuf24 *)(dest) = *(const SecStrBuf24 *)(src); \ - break; \ - case 25: \ - *(SecStrBuf25 *)(dest) = *(const SecStrBuf25 *)(src); \ - break; \ - case 26: \ - *(SecStrBuf26 *)(dest) = *(const SecStrBuf26 *)(src); \ - break; \ - case 27: \ - *(SecStrBuf27 *)(dest) = *(const SecStrBuf27 *)(src); \ - break; \ - case 28: \ - *(SecStrBuf28 *)(dest) = *(const SecStrBuf28 *)(src); \ - break; \ - case 29: \ - *(SecStrBuf29 *)(dest) = *(const SecStrBuf29 *)(src); \ - break; \ - case 30: \ - *(SecStrBuf30 *)(dest) = *(const SecStrBuf30 *)(src); \ - break; \ - case 31: \ - *(SecStrBuf31 *)(dest) = *(const SecStrBuf31 *)(src); \ - break; \ - case 32: \ - *(SecStrBuf32 *)(dest) = *(const SecStrBuf32 *)(src); \ - break; \ - case 33: \ - *(SecStrBuf33 *)(dest) = *(const SecStrBuf33 *)(src); \ - break; \ - case 34: \ - *(SecStrBuf34 *)(dest) = *(const SecStrBuf34 *)(src); \ - break; \ - case 35: \ - *(SecStrBuf35 *)(dest) = *(const SecStrBuf35 *)(src); \ - break; \ - case 36: \ - *(SecStrBuf36 *)(dest) = *(const SecStrBuf36 *)(src); \ - break; \ - case 37: \ - *(SecStrBuf37 *)(dest) = *(const SecStrBuf37 *)(src); \ - break; \ - case 38: \ - *(SecStrBuf38 *)(dest) = *(const SecStrBuf38 *)(src); \ - break; \ - case 39: \ - *(SecStrBuf39 *)(dest) = *(const SecStrBuf39 *)(src); \ - break; \ - case 40: \ - *(SecStrBuf40 *)(dest) = *(const SecStrBuf40 *)(src); \ - break; \ - case 41: \ - *(SecStrBuf41 *)(dest) = *(const SecStrBuf41 *)(src); \ - break; \ - case 42: \ - *(SecStrBuf42 *)(dest) = *(const SecStrBuf42 *)(src); \ - break; \ - case 43: \ - *(SecStrBuf43 *)(dest) = *(const SecStrBuf43 *)(src); \ - break; \ - case 44: \ - *(SecStrBuf44 *)(dest) = *(const SecStrBuf44 *)(src); \ - break; \ - case 45: \ - *(SecStrBuf45 *)(dest) = *(const SecStrBuf45 *)(src); \ - break; \ - case 46: \ - *(SecStrBuf46 *)(dest) = *(const SecStrBuf46 *)(src); \ - break; \ - case 47: \ - *(SecStrBuf47 *)(dest) = *(const SecStrBuf47 *)(src); \ - break; \ - case 48: \ - *(SecStrBuf48 *)(dest) = *(const SecStrBuf48 *)(src); \ - break; \ - case 49: \ - *(SecStrBuf49 *)(dest) = *(const SecStrBuf49 *)(src); \ - break; \ - case 50: \ - *(SecStrBuf50 *)(dest) = *(const SecStrBuf50 *)(src); \ - break; \ - case 51: \ - *(SecStrBuf51 *)(dest) = *(const SecStrBuf51 *)(src); \ - break; \ - case 52: \ - *(SecStrBuf52 *)(dest) = *(const SecStrBuf52 *)(src); \ - break; \ - case 53: \ - *(SecStrBuf53 *)(dest) = *(const SecStrBuf53 *)(src); \ - break; \ - case 54: \ - *(SecStrBuf54 *)(dest) = *(const SecStrBuf54 *)(src); \ - break; \ - case 55: \ - *(SecStrBuf55 *)(dest) = *(const SecStrBuf55 *)(src); \ - break; \ - case 56: \ - *(SecStrBuf56 *)(dest) = *(const SecStrBuf56 *)(src); \ - break; \ - case 57: \ - *(SecStrBuf57 *)(dest) = *(const SecStrBuf57 *)(src); \ - break; \ - case 58: \ - *(SecStrBuf58 *)(dest) = *(const SecStrBuf58 *)(src); \ - break; \ - case 59: \ - *(SecStrBuf59 *)(dest) = *(const SecStrBuf59 *)(src); \ - break; \ - case 60: \ - *(SecStrBuf60 *)(dest) = *(const SecStrBuf60 *)(src); \ - break; \ - case 61: \ - *(SecStrBuf61 *)(dest) = *(const SecStrBuf61 *)(src); \ - break; \ - case 62: \ - *(SecStrBuf62 *)(dest) = *(const SecStrBuf62 *)(src); \ - break; \ - case 63: \ - *(SecStrBuf63 *)(dest) = *(const SecStrBuf63 *)(src); \ - break; \ - case 64: \ - *(SecStrBuf64 *)(dest) = *(const SecStrBuf64 *)(src); \ - break; \ - default: \ - break; \ - } /* END switch */ \ - } else { \ - char *tmpDest = (char *)(dest); \ - const char *tmpSrc = (const char *)(src); \ - switch (count) { \ - case 64: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 63: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 62: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 61: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 60: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 59: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 58: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 57: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 56: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 55: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 54: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 53: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 52: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 51: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 50: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 49: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 48: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 47: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 46: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 45: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 44: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 43: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 42: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 41: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 40: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 39: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 38: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 37: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 36: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 35: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 34: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 33: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 32: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 31: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 30: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 29: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 28: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 27: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 26: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 25: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 24: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 23: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 22: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 21: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 20: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 19: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 18: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 17: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 16: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 15: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 14: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 13: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 12: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 11: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 10: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 9: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 8: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 7: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 6: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 5: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 4: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 3: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 2: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 1: \ - *(tmpDest++) = *(tmpSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - default: \ - break; \ - } \ - } \ - } \ - SECUREC_WHILE_ZERO +#define SECUREC_SMALL_MEM_COPY(dest, src, count) do { \ + if (SECUREC_ADDR_ALIGNED_8(dest) && SECUREC_ADDR_ALIGNED_8(src)) { \ + /* Use struct assignment */ \ + switch (count) { \ + case 1: \ + *(SecStrBuf1 *)(dest) = *(const SecStrBuf1 *)(src); \ + break; \ + case 2: \ + *(SecStrBuf2 *)(dest) = *(const SecStrBuf2 *)(src); \ + break; \ + case 3: \ + *(SecStrBuf3 *)(dest) = *(const SecStrBuf3 *)(src); \ + break; \ + case 4: \ + *(SecStrBuf4 *)(dest) = *(const SecStrBuf4 *)(src); \ + break; \ + case 5: \ + *(SecStrBuf5 *)(dest) = *(const SecStrBuf5 *)(src); \ + break; \ + case 6: \ + *(SecStrBuf6 *)(dest) = *(const SecStrBuf6 *)(src); \ + break; \ + case 7: \ + *(SecStrBuf7 *)(dest) = *(const SecStrBuf7 *)(src); \ + break; \ + case 8: \ + *(SecStrBuf8 *)(dest) = *(const SecStrBuf8 *)(src); \ + break; \ + case 9: \ + *(SecStrBuf9 *)(dest) = *(const SecStrBuf9 *)(src); \ + break; \ + case 10: \ + *(SecStrBuf10 *)(dest) = *(const SecStrBuf10 *)(src); \ + break; \ + case 11: \ + *(SecStrBuf11 *)(dest) = *(const SecStrBuf11 *)(src); \ + break; \ + case 12: \ + *(SecStrBuf12 *)(dest) = *(const SecStrBuf12 *)(src); \ + break; \ + case 13: \ + *(SecStrBuf13 *)(dest) = *(const SecStrBuf13 *)(src); \ + break; \ + case 14: \ + *(SecStrBuf14 *)(dest) = *(const SecStrBuf14 *)(src); \ + break; \ + case 15: \ + *(SecStrBuf15 *)(dest) = *(const SecStrBuf15 *)(src); \ + break; \ + case 16: \ + *(SecStrBuf16 *)(dest) = *(const SecStrBuf16 *)(src); \ + break; \ + case 17: \ + *(SecStrBuf17 *)(dest) = *(const SecStrBuf17 *)(src); \ + break; \ + case 18: \ + *(SecStrBuf18 *)(dest) = *(const SecStrBuf18 *)(src); \ + break; \ + case 19: \ + *(SecStrBuf19 *)(dest) = *(const SecStrBuf19 *)(src); \ + break; \ + case 20: \ + *(SecStrBuf20 *)(dest) = *(const SecStrBuf20 *)(src); \ + break; \ + case 21: \ + *(SecStrBuf21 *)(dest) = *(const SecStrBuf21 *)(src); \ + break; \ + case 22: \ + *(SecStrBuf22 *)(dest) = *(const SecStrBuf22 *)(src); \ + break; \ + case 23: \ + *(SecStrBuf23 *)(dest) = *(const SecStrBuf23 *)(src); \ + break; \ + case 24: \ + *(SecStrBuf24 *)(dest) = *(const SecStrBuf24 *)(src); \ + break; \ + case 25: \ + *(SecStrBuf25 *)(dest) = *(const SecStrBuf25 *)(src); \ + break; \ + case 26: \ + *(SecStrBuf26 *)(dest) = *(const SecStrBuf26 *)(src); \ + break; \ + case 27: \ + *(SecStrBuf27 *)(dest) = *(const SecStrBuf27 *)(src); \ + break; \ + case 28: \ + *(SecStrBuf28 *)(dest) = *(const SecStrBuf28 *)(src); \ + break; \ + case 29: \ + *(SecStrBuf29 *)(dest) = *(const SecStrBuf29 *)(src); \ + break; \ + case 30: \ + *(SecStrBuf30 *)(dest) = *(const SecStrBuf30 *)(src); \ + break; \ + case 31: \ + *(SecStrBuf31 *)(dest) = *(const SecStrBuf31 *)(src); \ + break; \ + case 32: \ + *(SecStrBuf32 *)(dest) = *(const SecStrBuf32 *)(src); \ + break; \ + case 33: \ + *(SecStrBuf33 *)(dest) = *(const SecStrBuf33 *)(src); \ + break; \ + case 34: \ + *(SecStrBuf34 *)(dest) = *(const SecStrBuf34 *)(src); \ + break; \ + case 35: \ + *(SecStrBuf35 *)(dest) = *(const SecStrBuf35 *)(src); \ + break; \ + case 36: \ + *(SecStrBuf36 *)(dest) = *(const SecStrBuf36 *)(src); \ + break; \ + case 37: \ + *(SecStrBuf37 *)(dest) = *(const SecStrBuf37 *)(src); \ + break; \ + case 38: \ + *(SecStrBuf38 *)(dest) = *(const SecStrBuf38 *)(src); \ + break; \ + case 39: \ + *(SecStrBuf39 *)(dest) = *(const SecStrBuf39 *)(src); \ + break; \ + case 40: \ + *(SecStrBuf40 *)(dest) = *(const SecStrBuf40 *)(src); \ + break; \ + case 41: \ + *(SecStrBuf41 *)(dest) = *(const SecStrBuf41 *)(src); \ + break; \ + case 42: \ + *(SecStrBuf42 *)(dest) = *(const SecStrBuf42 *)(src); \ + break; \ + case 43: \ + *(SecStrBuf43 *)(dest) = *(const SecStrBuf43 *)(src); \ + break; \ + case 44: \ + *(SecStrBuf44 *)(dest) = *(const SecStrBuf44 *)(src); \ + break; \ + case 45: \ + *(SecStrBuf45 *)(dest) = *(const SecStrBuf45 *)(src); \ + break; \ + case 46: \ + *(SecStrBuf46 *)(dest) = *(const SecStrBuf46 *)(src); \ + break; \ + case 47: \ + *(SecStrBuf47 *)(dest) = *(const SecStrBuf47 *)(src); \ + break; \ + case 48: \ + *(SecStrBuf48 *)(dest) = *(const SecStrBuf48 *)(src); \ + break; \ + case 49: \ + *(SecStrBuf49 *)(dest) = *(const SecStrBuf49 *)(src); \ + break; \ + case 50: \ + *(SecStrBuf50 *)(dest) = *(const SecStrBuf50 *)(src); \ + break; \ + case 51: \ + *(SecStrBuf51 *)(dest) = *(const SecStrBuf51 *)(src); \ + break; \ + case 52: \ + *(SecStrBuf52 *)(dest) = *(const SecStrBuf52 *)(src); \ + break; \ + case 53: \ + *(SecStrBuf53 *)(dest) = *(const SecStrBuf53 *)(src); \ + break; \ + case 54: \ + *(SecStrBuf54 *)(dest) = *(const SecStrBuf54 *)(src); \ + break; \ + case 55: \ + *(SecStrBuf55 *)(dest) = *(const SecStrBuf55 *)(src); \ + break; \ + case 56: \ + *(SecStrBuf56 *)(dest) = *(const SecStrBuf56 *)(src); \ + break; \ + case 57: \ + *(SecStrBuf57 *)(dest) = *(const SecStrBuf57 *)(src); \ + break; \ + case 58: \ + *(SecStrBuf58 *)(dest) = *(const SecStrBuf58 *)(src); \ + break; \ + case 59: \ + *(SecStrBuf59 *)(dest) = *(const SecStrBuf59 *)(src); \ + break; \ + case 60: \ + *(SecStrBuf60 *)(dest) = *(const SecStrBuf60 *)(src); \ + break; \ + case 61: \ + *(SecStrBuf61 *)(dest) = *(const SecStrBuf61 *)(src); \ + break; \ + case 62: \ + *(SecStrBuf62 *)(dest) = *(const SecStrBuf62 *)(src); \ + break; \ + case 63: \ + *(SecStrBuf63 *)(dest) = *(const SecStrBuf63 *)(src); \ + break; \ + case 64: \ + *(SecStrBuf64 *)(dest) = *(const SecStrBuf64 *)(src); \ + break; \ + default: \ + break; \ + } /* END switch */ \ + } else { \ + char *tmpDest = (char *)(dest); \ + const char *tmpSrc = (const char *)(src); \ + switch (count) { \ + case 64: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 63: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 62: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 61: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 60: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 59: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 58: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 57: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 56: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 55: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 54: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 53: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 52: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 51: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 50: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 49: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 48: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 47: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 46: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 45: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 44: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 43: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 42: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 41: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 40: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 39: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 38: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 37: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 36: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 35: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 34: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 33: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 32: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 31: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 30: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 29: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 28: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 27: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 26: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 25: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 24: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 23: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 22: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 21: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 20: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 19: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 18: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 17: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 16: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 15: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 14: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 13: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 12: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 11: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 10: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 9: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 8: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 7: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 6: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 5: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 4: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 3: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 2: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 1: \ + *(tmpDest++) = *(tmpSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + default: \ + break; \ + } \ + } \ +} SECUREC_WHILE_ZERO /* * Performance optimization */ -#define SECUREC_MEMCPY_OPT(dest, src, count) \ - do { \ - if ((count) > SECUREC_MEMCOPY_THRESHOLD_SIZE) { \ - SECUREC_MEMCPY_WARP_OPT((dest), (src), (count)); \ - } else { \ - SECUREC_SMALL_MEM_COPY((dest), (src), (count)); \ - } \ - } \ - SECUREC_WHILE_ZERO +#define SECUREC_MEMCPY_OPT(dest, src, count) do { \ + if ((count) > SECUREC_MEMCOPY_THRESHOLD_SIZE) { \ + SECUREC_MEMCPY_WARP_OPT((dest), (src), (count)); \ + } else { \ + SECUREC_SMALL_MEM_COPY((dest), (src), (count)); \ + } \ +} SECUREC_WHILE_ZERO #endif /* * Handling errors */ -SECUREC_INLINE errno_t SecMemcpyError(void *dest, size_t destMax, - const void *src, size_t count) { - if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) { - SECUREC_ERROR_INVALID_RANGE("memcpy_s"); - return ERANGE; - } - if (dest == NULL || src == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("memcpy_s"); - if (dest != NULL) { - (void)memset(dest, 0, destMax); - return EINVAL_AND_RESET; +SECUREC_INLINE errno_t SecMemcpyError(void *dest, size_t destMax, const void *src, size_t count) +{ + if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) { + SECUREC_ERROR_INVALID_RANGE("memcpy_s"); + return ERANGE; } - return EINVAL; - } - if (count > destMax) { - (void)memset(dest, 0, destMax); - SECUREC_ERROR_INVALID_RANGE("memcpy_s"); - return ERANGE_AND_RESET; - } - if (SECUREC_MEMORY_IS_OVERLAP(dest, src, count)) { - (void)memset(dest, 0, destMax); - SECUREC_ERROR_BUFFER_OVERLAP("memcpy_s"); - return EOVERLAP_AND_RESET; - } - /* Count is 0 or dest equal src also ret EOK */ - return EOK; + if (dest == NULL || src == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("memcpy_s"); + if (dest != NULL) { + (void)memset(dest, 0, destMax); + return EINVAL_AND_RESET; + } + return EINVAL; + } + if (count > destMax) { + (void)memset(dest, 0, destMax); + SECUREC_ERROR_INVALID_RANGE("memcpy_s"); + return ERANGE_AND_RESET; + } + if (SECUREC_MEMORY_IS_OVERLAP(dest, src, count)) { + (void)memset(dest, 0, destMax); + SECUREC_ERROR_BUFFER_OVERLAP("memcpy_s"); + return EOVERLAP_AND_RESET; + } + /* Count is 0 or dest equal src also ret EOK */ + return EOK; } #if defined(SECUREC_COMPATIBLE_WIN_FORMAT) -/* - * The fread API in windows will call memcpy_s and pass 0xffffffff to destMax. - * To avoid the failure of fread, we don't check desMax limit. - */ -#define SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count) \ - (SECUREC_LIKELY((count) <= (destMax) && (dest) != NULL && (src) != NULL && \ - (count) > 0 && \ - SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count)))) + /* + * The fread API in windows will call memcpy_s and pass 0xffffffff to destMax. + * To avoid the failure of fread, we don't check desMax limit. + */ +#define SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count) (SECUREC_LIKELY((count) <= (destMax) && \ + (dest) != NULL && (src) != NULL && \ + (count) > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count)))) #else -#define SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count) \ - (SECUREC_LIKELY((count) <= (destMax) && (dest) != NULL && (src) != NULL && \ - (destMax) <= SECUREC_MEM_MAX_LEN && (count) > 0 && \ - SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count)))) +#define SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count) (SECUREC_LIKELY((count) <= (destMax) && \ + (dest) != NULL && (src) != NULL && (destMax) <= SECUREC_MEM_MAX_LEN && \ + (count) > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count)))) #endif /* * - * The memcpy_s function copies n characters from the object pointed to by - * src into the object pointed to by dest + * The memcpy_s function copies n characters from the object pointed to by src into the object pointed to by dest * * * dest Destination buffer. @@ -502,30 +494,31 @@ SECUREC_INLINE errno_t SecMemcpyError(void *dest, size_t destMax, * * * EOK Success - * EINVAL dest is NULL and destMax != 0 and destMax <= - * SECUREC_MEM_MAX_LEN EINVAL_AND_RESET dest != NULL and src is NULLL - * and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN ERANGE destMax > - * SECUREC_MEM_MAX_LEN or destMax is 0 ERANGE_AND_RESET count > destMax - * and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN and dest != NULL and - * src != NULL EOVERLAP_AND_RESET dest buffer and source buffer are - * overlapped and count <= destMax destMax != 0 and destMax <= - * SECUREC_MEM_MAX_LEN and dest != NULL and src != NULL and dest != src + * EINVAL dest is NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN + * EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN + * ERANGE destMax > SECUREC_MEM_MAX_LEN or destMax is 0 + * ERANGE_AND_RESET count > destMax and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN + * and dest != NULL and src != NULL + * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and + * count <= destMax destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN and dest != NULL + * and src != NULL and dest != src * * if an error occured, dest will be filled with 0. - * If the source and destination overlap, the behavior of memcpy_s is - * undefined. Use memmove_s to handle overlapping regions. + * If the source and destination overlap, the behavior of memcpy_s is undefined. + * Use memmove_s to handle overlapping regions. */ -errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count) { - if (SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count)) { +errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count) +{ + if (SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count)) { #if SECUREC_MEMCOPY_WITH_PERFORMANCE - SECUREC_MEMCPY_OPT(dest, src, count); + SECUREC_MEMCPY_OPT(dest, src, count); #else - SECUREC_MEMCPY_WARP_OPT(dest, src, count); + SECUREC_MEMCPY_WARP_OPT(dest, src, count); #endif - return EOK; - } - /* Meet some runtime violation, return error code */ - return SecMemcpyError(dest, destMax, src, count); + return EOK; + } + /* Meet some runtime violation, return error code */ + return SecMemcpyError(dest, destMax, src, count); } #if SECUREC_IN_KERNEL @@ -536,26 +529,26 @@ EXPORT_SYMBOL(memcpy_s); /* * Performance optimization */ -errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, - size_t count) { - if (SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count)) { - SECUREC_MEMCPY_OPT(dest, src, count); - return EOK; - } - /* Meet some runtime violation, return error code */ - return SecMemcpyError(dest, destMax, src, count); +errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count) +{ + if (SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count)) { + SECUREC_MEMCPY_OPT(dest, src, count); + return EOK; + } + /* Meet some runtime violation, return error code */ + return SecMemcpyError(dest, destMax, src, count); } /* Trim judgement on "destMax <= SECUREC_MEM_MAX_LEN" */ -errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, - size_t count) { - if (SECUREC_LIKELY(count <= destMax && dest != NULL && src != NULL && - count > 0 && - SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count)))) { - SECUREC_MEMCPY_OPT(dest, src, count); - return EOK; - } - /* Meet some runtime violation, return error code */ - return SecMemcpyError(dest, destMax, src, count); +errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count) +{ + if (SECUREC_LIKELY(count <= destMax && dest != NULL && src != NULL && \ + count > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count)))) { + SECUREC_MEMCPY_OPT(dest, src, count); + return EOK; + } + /* Meet some runtime violation, return error code */ + return SecMemcpyError(dest, destMax, src, count); } #endif + diff --git a/project/app/wifi_app/hisi_tools/securec/memmove_s.c b/project/app/wifi_app/hisi_tools/securec/memmove_s.c index d2a12d23c..52cc82f33 100644 --- a/project/app/wifi_app/hisi_tools/securec/memmove_s.c +++ b/project/app/wifi_app/hisi_tools/securec/memmove_s.c @@ -6,9 +6,8 @@ */ /* * [Standardize-exceptions] Use unsafe function: Portability - * [reason] Use unsafe function to implement security function to maintain - * platform compatibility. And sufficient input validation is performed before - * calling + * [reason] Use unsafe function to implement security function to maintain platform compatibility. + * And sufficient input validation is performed before calling */ #include "securecutil.h" @@ -17,34 +16,35 @@ /* * Implementing memory data movement */ -SECUREC_INLINE void SecUtilMemmove(void *dst, const void *src, size_t count) { - unsigned char *pDest = (unsigned char *)dst; - const unsigned char *pSrc = (const unsigned char *)src; - size_t maxCount = count; +SECUREC_INLINE void SecUtilMemmove(void *dst, const void *src, size_t count) +{ + unsigned char *pDest = (unsigned char *)dst; + const unsigned char *pSrc = (const unsigned char *)src; + size_t maxCount = count; - if (dst <= src || pDest >= (pSrc + maxCount)) { - /* - * Non-Overlapping Buffers - * Copy from lower addresses to higher addresses - */ - while (maxCount--) { - *pDest = *pSrc; - ++pDest; - ++pSrc; + if (dst <= src || pDest >= (pSrc + maxCount)) { + /* + * Non-Overlapping Buffers + * Copy from lower addresses to higher addresses + */ + while (maxCount--) { + *pDest = *pSrc; + ++pDest; + ++pSrc; + } + } else { + /* + * Overlapping Buffers + * Copy from higher addresses to lower addresses + */ + pDest = pDest + maxCount - 1; + pSrc = pSrc + maxCount - 1; + while (maxCount--) { + *pDest = *pSrc; + --pDest; + --pSrc; + } } - } else { - /* - * Overlapping Buffers - * Copy from higher addresses to lower addresses - */ - pDest = pDest + maxCount - 1; - pSrc = pSrc + maxCount - 1; - while (maxCount--) { - *pDest = *pSrc; - --pDest; - --pSrc; - } - } } #endif @@ -63,51 +63,52 @@ SECUREC_INLINE void SecUtilMemmove(void *dst, const void *src, size_t count) { * * * EOK Success - * EINVAL dest is NULL and destMax != 0 and destMax <= - * SECUREC_MEM_MAX_LEN EINVAL_AND_RESET dest != NULL and src is NULLL and - * destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN ERANGE destMax > - * SECUREC_MEM_MAX_LEN or destMax is 0 ERANGE_AND_RESET count > destMax - * and dest != NULL and src != NULL and destMax != 0 and destMax <= - * SECUREC_MEM_MAX_LEN + * EINVAL dest is NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN + * EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN + * ERANGE destMax > SECUREC_MEM_MAX_LEN or destMax is 0 + * ERANGE_AND_RESET count > destMax and dest != NULL and src != NULL and destMax != 0 + * and destMax <= SECUREC_MEM_MAX_LEN * - * If an error occured, dest will be filled with 0 when dest and destMax - * valid. If some regions of the source area and the destination overlap, - * memmove_s ensures that the original source bytes in the overlapping region - * are copied before being overwritten. + * If an error occured, dest will be filled with 0 when dest and destMax valid. + * If some regions of the source area and the destination overlap, memmove_s + * ensures that the original source bytes in the overlapping region are copied + * before being overwritten. */ -errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count) { - if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) { - SECUREC_ERROR_INVALID_RANGE("memmove_s"); - return ERANGE; - } - if (dest == NULL || src == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("memmove_s"); - if (dest != NULL) { - (void)memset(dest, 0, destMax); - return EINVAL_AND_RESET; +errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count) +{ + if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) { + SECUREC_ERROR_INVALID_RANGE("memmove_s"); + return ERANGE; + } + if (dest == NULL || src == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("memmove_s"); + if (dest != NULL) { + (void)memset(dest, 0, destMax); + return EINVAL_AND_RESET; + } + return EINVAL; + } + if (count > destMax) { + (void)memset(dest, 0, destMax); + SECUREC_ERROR_INVALID_RANGE("memmove_s"); + return ERANGE_AND_RESET; + } + if (dest == src) { + return EOK; } - return EINVAL; - } - if (count > destMax) { - (void)memset(dest, 0, destMax); - SECUREC_ERROR_INVALID_RANGE("memmove_s"); - return ERANGE_AND_RESET; - } - if (dest == src) { - return EOK; - } - if (count > 0) { + if (count > 0) { #ifdef SECUREC_NOT_CALL_LIBC_CORE_API - SecUtilMemmove(dest, src, count); + SecUtilMemmove(dest, src, count); #else - /* Use underlying memmove for performance consideration */ - (void)memmove(dest, src, count); + /* Use underlying memmove for performance consideration */ + (void)memmove(dest, src, count); #endif - } - return EOK; + } + return EOK; } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(memmove_s); #endif + diff --git a/project/app/wifi_app/hisi_tools/securec/memset_s.c b/project/app/wifi_app/hisi_tools/securec/memset_s.c index 91c0429ff..927e6412e 100644 --- a/project/app/wifi_app/hisi_tools/securec/memset_s.c +++ b/project/app/wifi_app/hisi_tools/securec/memset_s.c @@ -6,9 +6,8 @@ */ /* * [Standardize-exceptions] Use unsafe function: Portability - * [reason] Use unsafe function to implement security function to maintain - * platform compatibility. And sufficient input validation is performed before - * calling + * [reason] Use unsafe function to implement security function to maintain platform compatibility. + * And sufficient input validation is performed before calling */ #include "securecutil.h" @@ -17,502 +16,431 @@ #define SECUREC_MEMSET_WITH_PERFORMANCE 0 #endif -#define SECUREC_MEMSET_PARAM_OK(dest, destMax, count) \ - (SECUREC_LIKELY((destMax) <= SECUREC_MEM_MAX_LEN && (dest) != NULL && \ - (count) <= (destMax))) +#define SECUREC_MEMSET_PARAM_OK(dest, destMax, count) (SECUREC_LIKELY((destMax) <= SECUREC_MEM_MAX_LEN && \ + (dest) != NULL && (count) <= (destMax))) #if SECUREC_WITH_PERFORMANCE_ADDONS || SECUREC_MEMSET_WITH_PERFORMANCE /* Use union to clear strict-aliasing warning */ typedef union { - SecStrBuf32 buf32; - SecStrBuf31 buf31; - SecStrBuf30 buf30; - SecStrBuf29 buf29; - SecStrBuf28 buf28; - SecStrBuf27 buf27; - SecStrBuf26 buf26; - SecStrBuf25 buf25; - SecStrBuf24 buf24; - SecStrBuf23 buf23; - SecStrBuf22 buf22; - SecStrBuf21 buf21; - SecStrBuf20 buf20; - SecStrBuf19 buf19; - SecStrBuf18 buf18; - SecStrBuf17 buf17; - SecStrBuf16 buf16; - SecStrBuf15 buf15; - SecStrBuf14 buf14; - SecStrBuf13 buf13; - SecStrBuf12 buf12; - SecStrBuf11 buf11; - SecStrBuf10 buf10; - SecStrBuf9 buf9; - SecStrBuf8 buf8; - SecStrBuf7 buf7; - SecStrBuf6 buf6; - SecStrBuf5 buf5; - SecStrBuf4 buf4; - SecStrBuf3 buf3; - SecStrBuf2 buf2; - SecStrBuf1 buf1; + SecStrBuf32 buf32; + SecStrBuf31 buf31; + SecStrBuf30 buf30; + SecStrBuf29 buf29; + SecStrBuf28 buf28; + SecStrBuf27 buf27; + SecStrBuf26 buf26; + SecStrBuf25 buf25; + SecStrBuf24 buf24; + SecStrBuf23 buf23; + SecStrBuf22 buf22; + SecStrBuf21 buf21; + SecStrBuf20 buf20; + SecStrBuf19 buf19; + SecStrBuf18 buf18; + SecStrBuf17 buf17; + SecStrBuf16 buf16; + SecStrBuf15 buf15; + SecStrBuf14 buf14; + SecStrBuf13 buf13; + SecStrBuf12 buf12; + SecStrBuf11 buf11; + SecStrBuf10 buf10; + SecStrBuf9 buf9; + SecStrBuf8 buf8; + SecStrBuf7 buf7; + SecStrBuf6 buf6; + SecStrBuf5 buf5; + SecStrBuf4 buf4; + SecStrBuf3 buf3; + SecStrBuf2 buf2; + SecStrBuf1 buf1; } SecStrBuf32Union; /* C standard initializes the first member of the consortium. */ -static const SecStrBuf32 g_allZero = { - {'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}}; -static const SecStrBuf32 g_allFF = { - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}}; +static const SecStrBuf32 g_allZero = {{ + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' +}}; +static const SecStrBuf32 g_allFF = {{ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}}; /* Clear coversion warning strict aliasing" */ -SECUREC_INLINE const SecStrBuf32Union * -SecStrictAliasingCast(const SecStrBuf32 *buf) { - return (const SecStrBuf32Union *)buf; +SECUREC_INLINE const SecStrBuf32Union *SecStrictAliasingCast(const SecStrBuf32 *buf) +{ + return (const SecStrBuf32Union *)buf; } #ifndef SECUREC_MEMSET_THRESHOLD_SIZE #define SECUREC_MEMSET_THRESHOLD_SIZE 32UL #endif -#define SECUREC_UNALIGNED_SET(dest, c, count) \ - do { \ - char *pcDest = (char *)(dest); \ - switch (count) { \ - case 32: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 31: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 30: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 29: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 28: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 27: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 26: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 25: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 24: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 23: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 22: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 21: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 20: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 19: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 18: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 17: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 16: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 15: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 14: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 13: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 12: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 11: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 10: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 9: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 8: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 7: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 6: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 5: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 4: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 3: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 2: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - case 1: \ - *(pcDest++) = (char)(c); \ - /* fall-through */ /* FALLTHRU */ \ - default: \ - break; \ - } \ - } \ - SECUREC_WHILE_ZERO +#define SECUREC_UNALIGNED_SET(dest, c, count) do { \ + char *pcDest = (char *)(dest); \ + switch (count) { \ + case 32: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 31: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 30: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 29: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 28: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 27: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 26: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 25: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 24: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 23: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 22: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 21: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 20: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 19: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 18: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 17: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 16: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 15: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 14: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 13: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 12: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 11: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 10: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 9: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 8: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 7: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 6: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 5: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 4: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 3: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 2: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + case 1: \ + *(pcDest++) = (char)(c); \ + /* fall-through */ /* FALLTHRU */ \ + default: \ + break; \ + } \ +} SECUREC_WHILE_ZERO -#define SECUREC_ALIGNED_SET_OPT_ZERO_FF(dest, c, count) \ - do { \ - switch (c) { \ - case 0: \ - switch (count) { \ - case 1: \ - *(SecStrBuf1 *)(dest) = *( \ - const SecStrBuf1 *)(&((SecStrictAliasingCast(&g_allZero))->buf1)); \ - break; \ - case 2: \ - *(SecStrBuf2 *)(dest) = *( \ - const SecStrBuf2 *)(&((SecStrictAliasingCast(&g_allZero))->buf2)); \ - break; \ - case 3: \ - *(SecStrBuf3 *)(dest) = *( \ - const SecStrBuf3 *)(&((SecStrictAliasingCast(&g_allZero))->buf3)); \ - break; \ - case 4: \ - *(SecStrBuf4 *)(dest) = *( \ - const SecStrBuf4 *)(&((SecStrictAliasingCast(&g_allZero))->buf4)); \ - break; \ - case 5: \ - *(SecStrBuf5 *)(dest) = *( \ - const SecStrBuf5 *)(&((SecStrictAliasingCast(&g_allZero))->buf5)); \ - break; \ - case 6: \ - *(SecStrBuf6 *)(dest) = *( \ - const SecStrBuf6 *)(&((SecStrictAliasingCast(&g_allZero))->buf6)); \ - break; \ - case 7: \ - *(SecStrBuf7 *)(dest) = *( \ - const SecStrBuf7 *)(&((SecStrictAliasingCast(&g_allZero))->buf7)); \ - break; \ - case 8: \ - *(SecStrBuf8 *)(dest) = *( \ - const SecStrBuf8 *)(&((SecStrictAliasingCast(&g_allZero))->buf8)); \ - break; \ - case 9: \ - *(SecStrBuf9 *)(dest) = *( \ - const SecStrBuf9 *)(&((SecStrictAliasingCast(&g_allZero))->buf9)); \ - break; \ - case 10: \ - *(SecStrBuf10 *)(dest) = *(const SecStrBuf10 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf10)); \ - break; \ - case 11: \ - *(SecStrBuf11 *)(dest) = *(const SecStrBuf11 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf11)); \ - break; \ - case 12: \ - *(SecStrBuf12 *)(dest) = *(const SecStrBuf12 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf12)); \ - break; \ - case 13: \ - *(SecStrBuf13 *)(dest) = *(const SecStrBuf13 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf13)); \ - break; \ - case 14: \ - *(SecStrBuf14 *)(dest) = *(const SecStrBuf14 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf14)); \ - break; \ - case 15: \ - *(SecStrBuf15 *)(dest) = *(const SecStrBuf15 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf15)); \ - break; \ - case 16: \ - *(SecStrBuf16 *)(dest) = *(const SecStrBuf16 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf16)); \ - break; \ - case 17: \ - *(SecStrBuf17 *)(dest) = *(const SecStrBuf17 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf17)); \ - break; \ - case 18: \ - *(SecStrBuf18 *)(dest) = *(const SecStrBuf18 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf18)); \ - break; \ - case 19: \ - *(SecStrBuf19 *)(dest) = *(const SecStrBuf19 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf19)); \ - break; \ - case 20: \ - *(SecStrBuf20 *)(dest) = *(const SecStrBuf20 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf20)); \ - break; \ - case 21: \ - *(SecStrBuf21 *)(dest) = *(const SecStrBuf21 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf21)); \ - break; \ - case 22: \ - *(SecStrBuf22 *)(dest) = *(const SecStrBuf22 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf22)); \ - break; \ - case 23: \ - *(SecStrBuf23 *)(dest) = *(const SecStrBuf23 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf23)); \ - break; \ - case 24: \ - *(SecStrBuf24 *)(dest) = *(const SecStrBuf24 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf24)); \ - break; \ - case 25: \ - *(SecStrBuf25 *)(dest) = *(const SecStrBuf25 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf25)); \ - break; \ - case 26: \ - *(SecStrBuf26 *)(dest) = *(const SecStrBuf26 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf26)); \ - break; \ - case 27: \ - *(SecStrBuf27 *)(dest) = *(const SecStrBuf27 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf27)); \ - break; \ - case 28: \ - *(SecStrBuf28 *)(dest) = *(const SecStrBuf28 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf28)); \ - break; \ - case 29: \ - *(SecStrBuf29 *)(dest) = *(const SecStrBuf29 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf29)); \ - break; \ - case 30: \ - *(SecStrBuf30 *)(dest) = *(const SecStrBuf30 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf30)); \ - break; \ - case 31: \ - *(SecStrBuf31 *)(dest) = *(const SecStrBuf31 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf31)); \ - break; \ - case 32: \ - *(SecStrBuf32 *)(dest) = *(const SecStrBuf32 *)(&( \ - (SecStrictAliasingCast(&g_allZero))->buf32)); \ - break; \ - default: \ - break; \ - } \ - break; \ - case 0xFF: \ - switch (count) { \ - case 1: \ - *(SecStrBuf1 *)(dest) = \ - *(const SecStrBuf1 *)(&((SecStrictAliasingCast(&g_allFF))->buf1)); \ - break; \ - case 2: \ - *(SecStrBuf2 *)(dest) = \ - *(const SecStrBuf2 *)(&((SecStrictAliasingCast(&g_allFF))->buf2)); \ - break; \ - case 3: \ - *(SecStrBuf3 *)(dest) = \ - *(const SecStrBuf3 *)(&((SecStrictAliasingCast(&g_allFF))->buf3)); \ - break; \ - case 4: \ - *(SecStrBuf4 *)(dest) = \ - *(const SecStrBuf4 *)(&((SecStrictAliasingCast(&g_allFF))->buf4)); \ - break; \ - case 5: \ - *(SecStrBuf5 *)(dest) = \ - *(const SecStrBuf5 *)(&((SecStrictAliasingCast(&g_allFF))->buf5)); \ - break; \ - case 6: \ - *(SecStrBuf6 *)(dest) = \ - *(const SecStrBuf6 *)(&((SecStrictAliasingCast(&g_allFF))->buf6)); \ - break; \ - case 7: \ - *(SecStrBuf7 *)(dest) = \ - *(const SecStrBuf7 *)(&((SecStrictAliasingCast(&g_allFF))->buf7)); \ - break; \ - case 8: \ - *(SecStrBuf8 *)(dest) = \ - *(const SecStrBuf8 *)(&((SecStrictAliasingCast(&g_allFF))->buf8)); \ - break; \ - case 9: \ - *(SecStrBuf9 *)(dest) = \ - *(const SecStrBuf9 *)(&((SecStrictAliasingCast(&g_allFF))->buf9)); \ - break; \ - case 10: \ - *(SecStrBuf10 *)(dest) = *( \ - const SecStrBuf10 *)(&((SecStrictAliasingCast(&g_allFF))->buf10)); \ - break; \ - case 11: \ - *(SecStrBuf11 *)(dest) = *( \ - const SecStrBuf11 *)(&((SecStrictAliasingCast(&g_allFF))->buf11)); \ - break; \ - case 12: \ - *(SecStrBuf12 *)(dest) = *( \ - const SecStrBuf12 *)(&((SecStrictAliasingCast(&g_allFF))->buf12)); \ - break; \ - case 13: \ - *(SecStrBuf13 *)(dest) = *( \ - const SecStrBuf13 *)(&((SecStrictAliasingCast(&g_allFF))->buf13)); \ - break; \ - case 14: \ - *(SecStrBuf14 *)(dest) = *( \ - const SecStrBuf14 *)(&((SecStrictAliasingCast(&g_allFF))->buf14)); \ - break; \ - case 15: \ - *(SecStrBuf15 *)(dest) = *( \ - const SecStrBuf15 *)(&((SecStrictAliasingCast(&g_allFF))->buf15)); \ - break; \ - case 16: \ - *(SecStrBuf16 *)(dest) = *( \ - const SecStrBuf16 *)(&((SecStrictAliasingCast(&g_allFF))->buf16)); \ - break; \ - case 17: \ - *(SecStrBuf17 *)(dest) = *( \ - const SecStrBuf17 *)(&((SecStrictAliasingCast(&g_allFF))->buf17)); \ - break; \ - case 18: \ - *(SecStrBuf18 *)(dest) = *( \ - const SecStrBuf18 *)(&((SecStrictAliasingCast(&g_allFF))->buf18)); \ - break; \ - case 19: \ - *(SecStrBuf19 *)(dest) = *( \ - const SecStrBuf19 *)(&((SecStrictAliasingCast(&g_allFF))->buf19)); \ - break; \ - case 20: \ - *(SecStrBuf20 *)(dest) = *( \ - const SecStrBuf20 *)(&((SecStrictAliasingCast(&g_allFF))->buf20)); \ - break; \ - case 21: \ - *(SecStrBuf21 *)(dest) = *( \ - const SecStrBuf21 *)(&((SecStrictAliasingCast(&g_allFF))->buf21)); \ - break; \ - case 22: \ - *(SecStrBuf22 *)(dest) = *( \ - const SecStrBuf22 *)(&((SecStrictAliasingCast(&g_allFF))->buf22)); \ - break; \ - case 23: \ - *(SecStrBuf23 *)(dest) = *( \ - const SecStrBuf23 *)(&((SecStrictAliasingCast(&g_allFF))->buf23)); \ - break; \ - case 24: \ - *(SecStrBuf24 *)(dest) = *( \ - const SecStrBuf24 *)(&((SecStrictAliasingCast(&g_allFF))->buf24)); \ - break; \ - case 25: \ - *(SecStrBuf25 *)(dest) = *( \ - const SecStrBuf25 *)(&((SecStrictAliasingCast(&g_allFF))->buf25)); \ - break; \ - case 26: \ - *(SecStrBuf26 *)(dest) = *( \ - const SecStrBuf26 *)(&((SecStrictAliasingCast(&g_allFF))->buf26)); \ - break; \ - case 27: \ - *(SecStrBuf27 *)(dest) = *( \ - const SecStrBuf27 *)(&((SecStrictAliasingCast(&g_allFF))->buf27)); \ - break; \ - case 28: \ - *(SecStrBuf28 *)(dest) = *( \ - const SecStrBuf28 *)(&((SecStrictAliasingCast(&g_allFF))->buf28)); \ - break; \ - case 29: \ - *(SecStrBuf29 *)(dest) = *( \ - const SecStrBuf29 *)(&((SecStrictAliasingCast(&g_allFF))->buf29)); \ - break; \ - case 30: \ - *(SecStrBuf30 *)(dest) = *( \ - const SecStrBuf30 *)(&((SecStrictAliasingCast(&g_allFF))->buf30)); \ - break; \ - case 31: \ - *(SecStrBuf31 *)(dest) = *( \ - const SecStrBuf31 *)(&((SecStrictAliasingCast(&g_allFF))->buf31)); \ - break; \ - case 32: \ - *(SecStrBuf32 *)(dest) = *( \ - const SecStrBuf32 *)(&((SecStrictAliasingCast(&g_allFF))->buf32)); \ - break; \ - default: \ - break; \ - } \ - break; \ - default: \ - SECUREC_UNALIGNED_SET((dest), (c), (count)); \ - } /* END switch */ \ - } \ - SECUREC_WHILE_ZERO +#define SECUREC_ALIGNED_SET_OPT_ZERO_FF(dest, c, count) do { \ + switch (c) { \ + case 0: \ + switch (count) { \ + case 1: \ + *(SecStrBuf1 *)(dest) = *(const SecStrBuf1 *)(&((SecStrictAliasingCast(&g_allZero))->buf1)); \ + break; \ + case 2: \ + *(SecStrBuf2 *)(dest) = *(const SecStrBuf2 *)(&((SecStrictAliasingCast(&g_allZero))->buf2)); \ + break; \ + case 3: \ + *(SecStrBuf3 *)(dest) = *(const SecStrBuf3 *)(&((SecStrictAliasingCast(&g_allZero))->buf3)); \ + break; \ + case 4: \ + *(SecStrBuf4 *)(dest) = *(const SecStrBuf4 *)(&((SecStrictAliasingCast(&g_allZero))->buf4)); \ + break; \ + case 5: \ + *(SecStrBuf5 *)(dest) = *(const SecStrBuf5 *)(&((SecStrictAliasingCast(&g_allZero))->buf5)); \ + break; \ + case 6: \ + *(SecStrBuf6 *)(dest) = *(const SecStrBuf6 *)(&((SecStrictAliasingCast(&g_allZero))->buf6)); \ + break; \ + case 7: \ + *(SecStrBuf7 *)(dest) = *(const SecStrBuf7 *)(&((SecStrictAliasingCast(&g_allZero))->buf7)); \ + break; \ + case 8: \ + *(SecStrBuf8 *)(dest) = *(const SecStrBuf8 *)(&((SecStrictAliasingCast(&g_allZero))->buf8)); \ + break; \ + case 9: \ + *(SecStrBuf9 *)(dest) = *(const SecStrBuf9 *)(&((SecStrictAliasingCast(&g_allZero))->buf9)); \ + break; \ + case 10: \ + *(SecStrBuf10 *)(dest) = *(const SecStrBuf10 *)(&((SecStrictAliasingCast(&g_allZero))->buf10)); \ + break; \ + case 11: \ + *(SecStrBuf11 *)(dest) = *(const SecStrBuf11 *)(&((SecStrictAliasingCast(&g_allZero))->buf11)); \ + break; \ + case 12: \ + *(SecStrBuf12 *)(dest) = *(const SecStrBuf12 *)(&((SecStrictAliasingCast(&g_allZero))->buf12)); \ + break; \ + case 13: \ + *(SecStrBuf13 *)(dest) = *(const SecStrBuf13 *)(&((SecStrictAliasingCast(&g_allZero))->buf13)); \ + break; \ + case 14: \ + *(SecStrBuf14 *)(dest) = *(const SecStrBuf14 *)(&((SecStrictAliasingCast(&g_allZero))->buf14)); \ + break; \ + case 15: \ + *(SecStrBuf15 *)(dest) = *(const SecStrBuf15 *)(&((SecStrictAliasingCast(&g_allZero))->buf15)); \ + break; \ + case 16: \ + *(SecStrBuf16 *)(dest) = *(const SecStrBuf16 *)(&((SecStrictAliasingCast(&g_allZero))->buf16)); \ + break; \ + case 17: \ + *(SecStrBuf17 *)(dest) = *(const SecStrBuf17 *)(&((SecStrictAliasingCast(&g_allZero))->buf17)); \ + break; \ + case 18: \ + *(SecStrBuf18 *)(dest) = *(const SecStrBuf18 *)(&((SecStrictAliasingCast(&g_allZero))->buf18)); \ + break; \ + case 19: \ + *(SecStrBuf19 *)(dest) = *(const SecStrBuf19 *)(&((SecStrictAliasingCast(&g_allZero))->buf19)); \ + break; \ + case 20: \ + *(SecStrBuf20 *)(dest) = *(const SecStrBuf20 *)(&((SecStrictAliasingCast(&g_allZero))->buf20)); \ + break; \ + case 21: \ + *(SecStrBuf21 *)(dest) = *(const SecStrBuf21 *)(&((SecStrictAliasingCast(&g_allZero))->buf21)); \ + break; \ + case 22: \ + *(SecStrBuf22 *)(dest) = *(const SecStrBuf22 *)(&((SecStrictAliasingCast(&g_allZero))->buf22)); \ + break; \ + case 23: \ + *(SecStrBuf23 *)(dest) = *(const SecStrBuf23 *)(&((SecStrictAliasingCast(&g_allZero))->buf23)); \ + break; \ + case 24: \ + *(SecStrBuf24 *)(dest) = *(const SecStrBuf24 *)(&((SecStrictAliasingCast(&g_allZero))->buf24)); \ + break; \ + case 25: \ + *(SecStrBuf25 *)(dest) = *(const SecStrBuf25 *)(&((SecStrictAliasingCast(&g_allZero))->buf25)); \ + break; \ + case 26: \ + *(SecStrBuf26 *)(dest) = *(const SecStrBuf26 *)(&((SecStrictAliasingCast(&g_allZero))->buf26)); \ + break; \ + case 27: \ + *(SecStrBuf27 *)(dest) = *(const SecStrBuf27 *)(&((SecStrictAliasingCast(&g_allZero))->buf27)); \ + break; \ + case 28: \ + *(SecStrBuf28 *)(dest) = *(const SecStrBuf28 *)(&((SecStrictAliasingCast(&g_allZero))->buf28)); \ + break; \ + case 29: \ + *(SecStrBuf29 *)(dest) = *(const SecStrBuf29 *)(&((SecStrictAliasingCast(&g_allZero))->buf29)); \ + break; \ + case 30: \ + *(SecStrBuf30 *)(dest) = *(const SecStrBuf30 *)(&((SecStrictAliasingCast(&g_allZero))->buf30)); \ + break; \ + case 31: \ + *(SecStrBuf31 *)(dest) = *(const SecStrBuf31 *)(&((SecStrictAliasingCast(&g_allZero))->buf31)); \ + break; \ + case 32: \ + *(SecStrBuf32 *)(dest) = *(const SecStrBuf32 *)(&((SecStrictAliasingCast(&g_allZero))->buf32)); \ + break; \ + default: \ + break; \ + } \ + break; \ + case 0xFF: \ + switch (count) { \ + case 1: \ + *(SecStrBuf1 *)(dest) = *(const SecStrBuf1 *)(&((SecStrictAliasingCast(&g_allFF))->buf1)); \ + break; \ + case 2: \ + *(SecStrBuf2 *)(dest) = *(const SecStrBuf2 *)(&((SecStrictAliasingCast(&g_allFF))->buf2)); \ + break; \ + case 3: \ + *(SecStrBuf3 *)(dest) = *(const SecStrBuf3 *)(&((SecStrictAliasingCast(&g_allFF))->buf3)); \ + break; \ + case 4: \ + *(SecStrBuf4 *)(dest) = *(const SecStrBuf4 *)(&((SecStrictAliasingCast(&g_allFF))->buf4)); \ + break; \ + case 5: \ + *(SecStrBuf5 *)(dest) = *(const SecStrBuf5 *)(&((SecStrictAliasingCast(&g_allFF))->buf5)); \ + break; \ + case 6: \ + *(SecStrBuf6 *)(dest) = *(const SecStrBuf6 *)(&((SecStrictAliasingCast(&g_allFF))->buf6)); \ + break; \ + case 7: \ + *(SecStrBuf7 *)(dest) = *(const SecStrBuf7 *)(&((SecStrictAliasingCast(&g_allFF))->buf7)); \ + break; \ + case 8: \ + *(SecStrBuf8 *)(dest) = *(const SecStrBuf8 *)(&((SecStrictAliasingCast(&g_allFF))->buf8)); \ + break; \ + case 9: \ + *(SecStrBuf9 *)(dest) = *(const SecStrBuf9 *)(&((SecStrictAliasingCast(&g_allFF))->buf9)); \ + break; \ + case 10: \ + *(SecStrBuf10 *)(dest) = *(const SecStrBuf10 *)(&((SecStrictAliasingCast(&g_allFF))->buf10)); \ + break; \ + case 11: \ + *(SecStrBuf11 *)(dest) = *(const SecStrBuf11 *)(&((SecStrictAliasingCast(&g_allFF))->buf11)); \ + break; \ + case 12: \ + *(SecStrBuf12 *)(dest) = *(const SecStrBuf12 *)(&((SecStrictAliasingCast(&g_allFF))->buf12)); \ + break; \ + case 13: \ + *(SecStrBuf13 *)(dest) = *(const SecStrBuf13 *)(&((SecStrictAliasingCast(&g_allFF))->buf13)); \ + break; \ + case 14: \ + *(SecStrBuf14 *)(dest) = *(const SecStrBuf14 *)(&((SecStrictAliasingCast(&g_allFF))->buf14)); \ + break; \ + case 15: \ + *(SecStrBuf15 *)(dest) = *(const SecStrBuf15 *)(&((SecStrictAliasingCast(&g_allFF))->buf15)); \ + break; \ + case 16: \ + *(SecStrBuf16 *)(dest) = *(const SecStrBuf16 *)(&((SecStrictAliasingCast(&g_allFF))->buf16)); \ + break; \ + case 17: \ + *(SecStrBuf17 *)(dest) = *(const SecStrBuf17 *)(&((SecStrictAliasingCast(&g_allFF))->buf17)); \ + break; \ + case 18: \ + *(SecStrBuf18 *)(dest) = *(const SecStrBuf18 *)(&((SecStrictAliasingCast(&g_allFF))->buf18)); \ + break; \ + case 19: \ + *(SecStrBuf19 *)(dest) = *(const SecStrBuf19 *)(&((SecStrictAliasingCast(&g_allFF))->buf19)); \ + break; \ + case 20: \ + *(SecStrBuf20 *)(dest) = *(const SecStrBuf20 *)(&((SecStrictAliasingCast(&g_allFF))->buf20)); \ + break; \ + case 21: \ + *(SecStrBuf21 *)(dest) = *(const SecStrBuf21 *)(&((SecStrictAliasingCast(&g_allFF))->buf21)); \ + break; \ + case 22: \ + *(SecStrBuf22 *)(dest) = *(const SecStrBuf22 *)(&((SecStrictAliasingCast(&g_allFF))->buf22)); \ + break; \ + case 23: \ + *(SecStrBuf23 *)(dest) = *(const SecStrBuf23 *)(&((SecStrictAliasingCast(&g_allFF))->buf23)); \ + break; \ + case 24: \ + *(SecStrBuf24 *)(dest) = *(const SecStrBuf24 *)(&((SecStrictAliasingCast(&g_allFF))->buf24)); \ + break; \ + case 25: \ + *(SecStrBuf25 *)(dest) = *(const SecStrBuf25 *)(&((SecStrictAliasingCast(&g_allFF))->buf25)); \ + break; \ + case 26: \ + *(SecStrBuf26 *)(dest) = *(const SecStrBuf26 *)(&((SecStrictAliasingCast(&g_allFF))->buf26)); \ + break; \ + case 27: \ + *(SecStrBuf27 *)(dest) = *(const SecStrBuf27 *)(&((SecStrictAliasingCast(&g_allFF))->buf27)); \ + break; \ + case 28: \ + *(SecStrBuf28 *)(dest) = *(const SecStrBuf28 *)(&((SecStrictAliasingCast(&g_allFF))->buf28)); \ + break; \ + case 29: \ + *(SecStrBuf29 *)(dest) = *(const SecStrBuf29 *)(&((SecStrictAliasingCast(&g_allFF))->buf29)); \ + break; \ + case 30: \ + *(SecStrBuf30 *)(dest) = *(const SecStrBuf30 *)(&((SecStrictAliasingCast(&g_allFF))->buf30)); \ + break; \ + case 31: \ + *(SecStrBuf31 *)(dest) = *(const SecStrBuf31 *)(&((SecStrictAliasingCast(&g_allFF))->buf31)); \ + break; \ + case 32: \ + *(SecStrBuf32 *)(dest) = *(const SecStrBuf32 *)(&((SecStrictAliasingCast(&g_allFF))->buf32)); \ + break; \ + default: \ + break; \ + } \ + break; \ + default: \ + SECUREC_UNALIGNED_SET((dest), (c), (count)); \ + } /* END switch */ \ +} SECUREC_WHILE_ZERO -#define SECUREC_SMALL_MEM_SET(dest, c, count) \ - ; \ - do { \ - if (SECUREC_ADDR_ALIGNED_8((dest))) { \ - SECUREC_ALIGNED_SET_OPT_ZERO_FF((dest), (c), (count)); \ - } else { \ - SECUREC_UNALIGNED_SET((dest), (c), (count)); \ - } \ - } \ - SECUREC_WHILE_ZERO +#define SECUREC_SMALL_MEM_SET(dest, c, count); do { \ + if (SECUREC_ADDR_ALIGNED_8((dest))) { \ + SECUREC_ALIGNED_SET_OPT_ZERO_FF((dest), (c), (count)); \ + } else { \ + SECUREC_UNALIGNED_SET((dest), (c), (count)); \ + } \ +} SECUREC_WHILE_ZERO /* * Performance optimization */ -#define SECUREC_MEMSET_OPT(dest, c, count) \ - do { \ - if ((count) > SECUREC_MEMSET_THRESHOLD_SIZE) { \ - SECUREC_MEMSET_WARP_OPT((dest), (c), (count)); \ - } else { \ - SECUREC_SMALL_MEM_SET((dest), (c), (count)); \ - } \ - } \ - SECUREC_WHILE_ZERO +#define SECUREC_MEMSET_OPT(dest, c, count) do { \ + if ((count) > SECUREC_MEMSET_THRESHOLD_SIZE) { \ + SECUREC_MEMSET_WARP_OPT((dest), (c), (count)); \ + } else { \ + SECUREC_SMALL_MEM_SET((dest), (c), (count)); \ + } \ +} SECUREC_WHILE_ZERO #endif /* * Handling errors */ -SECUREC_INLINE errno_t SecMemsetError(void *dest, size_t destMax, int c, - size_t count) { - /* Check destMax is 0 compatible with _sp macro */ - if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) { - SECUREC_ERROR_INVALID_RANGE("memset_s"); - return ERANGE; - } - if (dest == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("memset_s"); - return EINVAL; - } - if (count > destMax) { - (void)memset(dest, c, destMax); /* Set entire buffer to value c */ - SECUREC_ERROR_INVALID_RANGE("memset_s"); - return ERANGE_AND_RESET; - } - return EOK; +SECUREC_INLINE errno_t SecMemsetError(void *dest, size_t destMax, int c, size_t count) +{ + /* Check destMax is 0 compatible with _sp macro */ + if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) { + SECUREC_ERROR_INVALID_RANGE("memset_s"); + return ERANGE; + } + if (dest == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("memset_s"); + return EINVAL; + } + if (count > destMax) { + (void)memset(dest, c, destMax); /* Set entire buffer to value c */ + SECUREC_ERROR_INVALID_RANGE("memset_s"); + return ERANGE_AND_RESET; + } + return EOK; } /* * - * The memset_s function copies the value of c (converted to an unsigned - * char) into each of the first count characters of the object pointed to by - * dest. + * The memset_s function copies the value of c (converted to an unsigned char) + * into each of the first count characters of the object pointed to by dest. * * * dest Pointer to destination. @@ -525,24 +453,24 @@ SECUREC_INLINE errno_t SecMemsetError(void *dest, size_t destMax, int c, * * * EOK Success - * EINVAL dest == NULL and destMax != 0 and destMax <= - * SECUREC_MEM_MAX_LEN ERANGE destMax > SECUREC_MEM_MAX_LEN or - * (destMax is 0 and count > destMax) ERANGE_AND_RESET count > destMax and - * destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN and dest != NULL + * EINVAL dest == NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN + * ERANGE destMax > SECUREC_MEM_MAX_LEN or (destMax is 0 and count > destMax) + * ERANGE_AND_RESET count > destMax and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN and dest != NULL * * if return ERANGE_AND_RESET then fill dest to c ,fill length is destMax */ -errno_t memset_s(void *dest, size_t destMax, int c, size_t count) { - if (SECUREC_MEMSET_PARAM_OK(dest, destMax, count)) { +errno_t memset_s(void *dest, size_t destMax, int c, size_t count) +{ + if (SECUREC_MEMSET_PARAM_OK(dest, destMax, count)) { #if SECUREC_MEMSET_WITH_PERFORMANCE - SECUREC_MEMSET_OPT(dest, c, count); + SECUREC_MEMSET_OPT(dest, c, count); #else - SECUREC_MEMSET_WARP_OPT(dest, c, count); + SECUREC_MEMSET_WARP_OPT(dest, c, count); #endif - return EOK; - } - /* Meet some runtime violation, return error code */ - return SecMemsetError(dest, destMax, c, count); + return EOK; + } + /* Meet some runtime violation, return error code */ + return SecMemsetError(dest, destMax, c, count); } #if SECUREC_IN_KERNEL @@ -553,24 +481,27 @@ EXPORT_SYMBOL(memset_s); /* * Performance optimization */ -errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count) { - if (SECUREC_MEMSET_PARAM_OK(dest, destMax, count)) { - SECUREC_MEMSET_OPT(dest, c, count); - return EOK; - } - /* Meet some runtime violation, return error code */ - return SecMemsetError(dest, destMax, c, count); +errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count) +{ + if (SECUREC_MEMSET_PARAM_OK(dest, destMax, count)) { + SECUREC_MEMSET_OPT(dest, c, count); + return EOK; + } + /* Meet some runtime violation, return error code */ + return SecMemsetError(dest, destMax, c, count); } /* * Performance optimization, trim judgement on "destMax <= SECUREC_MEM_MAX_LEN" */ -errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count) { - if (SECUREC_LIKELY(count <= destMax && dest != NULL)) { - SECUREC_MEMSET_OPT(dest, c, count); - return EOK; - } - /* Meet some runtime violation, return error code */ - return SecMemsetError(dest, destMax, c, count); +errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count) +{ + if (SECUREC_LIKELY(count <= destMax && dest != NULL)) { + SECUREC_MEMSET_OPT(dest, c, count); + return EOK; + } + /* Meet some runtime violation, return error code */ + return SecMemsetError(dest, destMax, c, count); } #endif + diff --git a/project/app/wifi_app/hisi_tools/securec/scanf_s.c b/project/app/wifi_app/hisi_tools/securec/scanf_s.c index 091d6e47e..8bb704014 100644 --- a/project/app/wifi_app/hisi_tools/securec/scanf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/scanf_s.c @@ -9,20 +9,19 @@ /* * - * The scanf_s function is equivalent to fscanf_s with the argument stdin - * interposed before the arguments to scanf_s The scanf_s function reads data - * from the standard input stream stdin and writes the data into the location - * that's given by argument. Each argument must be a pointer to a variable of a - * type that corresponds to a type specifier in format. If copying occurs - * between strings that overlap, the behavior is undefined. + * The scanf_s function is equivalent to fscanf_s with the argument stdin interposed before the arguments to scanf_s + * The scanf_s function reads data from the standard input stream stdin and + * writes the data into the location that's given by argument. Each argument + * must be a pointer to a variable of a type that corresponds to a type specifier + * in format. If copying occurs between strings that overlap, the behavior is + * undefined. * * * format Format control string. * ... Optional arguments. * * - * ... The converted value stored in user assigned - * address + * ... The converted value stored in user assigned address * * * Returns the number of fields successfully converted and assigned; @@ -30,15 +29,17 @@ * A return value of 0 indicates that no fields were assigned. * return -1 if an error occurs. */ -int scanf_s(const char *format, ...) { - int ret; /* If initialization causes e838 */ - va_list argList; +int scanf_s(const char *format, ...) +{ + int ret; /* If initialization causes e838 */ + va_list argList; - va_start(argList, format); - ret = vscanf_s(format, argList); - va_end(argList); - (void)argList; /* To clear e438 last value assigned not used , the compiler - will optimize this code */ + va_start(argList, format); + ret = vscanf_s(format, argList); + va_end(argList); + (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */ - return ret; + return ret; } + + diff --git a/project/app/wifi_app/hisi_tools/securec/secinput.h b/project/app/wifi_app/hisi_tools/securec/secinput.h index b2c33d82b..21e2cf14c 100644 --- a/project/app/wifi_app/hisi_tools/securec/secinput.h +++ b/project/app/wifi_app/hisi_tools/securec/secinput.h @@ -10,40 +10,39 @@ #define SEC_INPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C #include "securecutil.h" -#define SECUREC_SCANF_EINVAL (-1) -#define SECUREC_SCANF_ERROR_PARA (-2) +#define SECUREC_SCANF_EINVAL (-1) +#define SECUREC_SCANF_ERROR_PARA (-2) /* For internal stream flag */ -#define SECUREC_MEM_STR_FLAG 0X01 -#define SECUREC_FILE_STREAM_FLAG 0X02 -#define SECUREC_PIPE_STREAM_FLAG 0X04 -#define SECUREC_LOAD_FILE_TO_MEM_FLAG 0X08 +#define SECUREC_MEM_STR_FLAG 0X01 +#define SECUREC_FILE_STREAM_FLAG 0X02 +#define SECUREC_PIPE_STREAM_FLAG 0X04 +#define SECUREC_LOAD_FILE_TO_MEM_FLAG 0X08 -#define SECUREC_BOM_HEADER_SIZE 2 -#define SECUREC_BOM_HEADER_BE_1ST 0xFEU -#define SECUREC_BOM_HEADER_BE_2ST 0xFFU -#define SECUREC_BOM_HEADER_LE_1ST 0xFFU -#define SECUREC_BOM_HEADER_LE_2ST 0xFEU -#define SECUREC_UTF8_BOM_HEADER_SIZE 3 -#define SECUREC_UTF8_BOM_HEADER_1ST 0xEFU -#define SECUREC_UTF8_BOM_HEADER_2ND 0xBBU -#define SECUREC_UTF8_BOM_HEADER_3RD 0xBFU -#define SECUREC_UTF8_LEAD_1ST 0xE0 -#define SECUREC_UTF8_LEAD_2ND 0x80 +#define SECUREC_BOM_HEADER_SIZE 2 +#define SECUREC_BOM_HEADER_BE_1ST 0xFEU +#define SECUREC_BOM_HEADER_BE_2ST 0xFFU +#define SECUREC_BOM_HEADER_LE_1ST 0xFFU +#define SECUREC_BOM_HEADER_LE_2ST 0xFEU +#define SECUREC_UTF8_BOM_HEADER_SIZE 3 +#define SECUREC_UTF8_BOM_HEADER_1ST 0xEFU +#define SECUREC_UTF8_BOM_HEADER_2ND 0xBBU +#define SECUREC_UTF8_BOM_HEADER_3RD 0xBFU +#define SECUREC_UTF8_LEAD_1ST 0xE0 +#define SECUREC_UTF8_LEAD_2ND 0x80 typedef struct { - unsigned int flag; /* Mark the properties of input stream */ - int count; /* The size of buffered string in bytes */ - const char *cur; /* The pointer to next read position */ - char *base; /* The pointer to the header of buffered string */ + unsigned int flag; /* Mark the properties of input stream */ + int count; /* The size of buffered string in bytes */ + const char *cur; /* The pointer to next read position */ + char *base; /* The pointer to the header of buffered string */ #if SECUREC_ENABLE_SCANF_FILE - FILE *pf; /* The file pointer */ - long oriFilePos; /* The original position of file offset when fscanf is called - */ - int fileRealRead; + FILE *pf; /* The file pointer */ + long oriFilePos; /* The original position of file offset when fscanf is called */ + int fileRealRead; #ifdef SECUREC_NO_STD_UNGETC - unsigned int lastChar; /* The char code of last input */ - int fUnGet; /* The boolean flag of pushing a char back to read stream */ + unsigned int lastChar; /* The char code of last input */ + int fUnGet; /* The boolean flag of pushing a char back to read stream */ #endif #endif } SecFileStream; @@ -52,19 +51,19 @@ typedef struct { /* * This initialization for eliminating redundant initialization. */ -SECUREC_INLINE void SecInitFileStreamFromString(SecFileStream *stream, - const char *cur, int count) { - stream->flag = SECUREC_MEM_STR_FLAG; - stream->count = count; - stream->cur = cur; - stream->base = NULL; +SECUREC_INLINE void SecInitFileStreamFromString(SecFileStream *stream, const char *cur, int count) +{ + stream->flag = SECUREC_MEM_STR_FLAG; + stream->count = count; + stream->cur = cur; + stream->base = NULL; #if SECUREC_ENABLE_SCANF_FILE - stream->pf = NULL; - stream->oriFilePos = 0; - stream->fileRealRead = 0; + stream->pf = NULL; + stream->oriFilePos = 0; + stream->fileRealRead = 0; #ifdef SECUREC_NO_STD_UNGETC - stream->lastChar = 0; - stream->fUnGet = 0; + stream->lastChar = 0; + stream->fUnGet = 0; #endif #endif } @@ -74,42 +73,44 @@ SECUREC_INLINE void SecInitFileStreamFromString(SecFileStream *stream, /* * This initialization for eliminating redundant initialization. */ -SECUREC_INLINE void SecInitFileStreamFromStdin(SecFileStream *stream) { - stream->flag = SECUREC_PIPE_STREAM_FLAG; - stream->count = 0; - stream->cur = NULL; - stream->base = NULL; +SECUREC_INLINE void SecInitFileStreamFromStdin(SecFileStream *stream) +{ + stream->flag = SECUREC_PIPE_STREAM_FLAG; + stream->count = 0; + stream->cur = NULL; + stream->base = NULL; #if SECUREC_ENABLE_SCANF_FILE - stream->pf = SECUREC_STREAM_STDIN; - stream->oriFilePos = 0; - stream->fileRealRead = 0; + stream->pf = SECUREC_STREAM_STDIN; + stream->oriFilePos = 0; + stream->fileRealRead = 0; #ifdef SECUREC_NO_STD_UNGETC - stream->lastChar = 0; - stream->fUnGet = 0; + stream->lastChar = 0; + stream->fUnGet = 0; #endif #endif } #endif + #ifdef SECUREC_INLINE_INIT_FILE_STREAM_FILE /* * This initialization for eliminating redundant initialization. * Compared with the previous version initialization 0, * the current code causes the binary size to increase by some bytes */ -SECUREC_INLINE void SecInitFileStreamFromFile(SecFileStream *stream, - FILE *file) { - stream->flag = SECUREC_FILE_STREAM_FLAG; - stream->count = 0; - stream->cur = NULL; - stream->base = NULL; +SECUREC_INLINE void SecInitFileStreamFromFile(SecFileStream *stream, FILE *file) +{ + stream->flag = SECUREC_FILE_STREAM_FLAG; + stream->count = 0; + stream->cur = NULL; + stream->base = NULL; #if SECUREC_ENABLE_SCANF_FILE - stream->pf = file; - stream->oriFilePos = 0; - stream->fileRealRead = 0; + stream->pf = file; + stream->oriFilePos = 0; + stream->fileRealRead = 0; #ifdef SECUREC_NO_STD_UNGETC - stream->lastChar = 0; - stream->fUnGet = 0; + stream->lastChar = 0; + stream->fUnGet = 0; #endif #endif } @@ -119,32 +120,26 @@ SECUREC_INLINE void SecInitFileStreamFromFile(SecFileStream *stream, extern "C" { #endif -extern int SecInputS(SecFileStream *stream, const char *cFormat, - va_list argList); -extern void SecClearDestBuf(const char *buffer, const char *format, - va_list argList); + extern int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList); + extern void SecClearDestBuf(const char *buffer, const char *format, va_list argList); #if SECUREC_IN_KERNEL == 0 -extern int SecInputSW(SecFileStream *stream, const wchar_t *cFormat, - va_list argList); -extern void SecClearDestBufW(const wchar_t *buffer, const wchar_t *format, - va_list argList); + extern int SecInputSW(SecFileStream *stream, const wchar_t *cFormat, va_list argList); + extern void SecClearDestBufW(const wchar_t *buffer, const wchar_t *format, va_list argList); #endif /* 20150105 For software and hardware decoupling,such as UMG */ #if defined(SECUREC_SYSAPI4VXWORKS) #ifdef feof #undef feof #endif -extern int feof(FILE *stream); + extern int feof(FILE *stream); #endif #if defined(SECUREC_SYSAPI4VXWORKS) || defined(SECUREC_CTYPE_MACRO_ADAPT) #ifndef isspace -#define isspace(c) \ - (((c) == ' ') || ((c) == '\t') || ((c) == '\r') || ((c) == '\n')) +#define isspace(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\r') || ((c) == '\n')) #endif #ifndef iswspace -#define iswspace(c) \ - (((c) == L' ') || ((c) == L'\t') || ((c) == L'\r') || ((c) == L'\n')) +#define iswspace(c) (((c) == L' ') || ((c) == L'\t') || ((c) == L'\r') || ((c) == L'\n')) #endif #ifndef isascii #define isascii(c) (((unsigned char)(c)) <= 0x7f) @@ -181,3 +176,5 @@ extern int feof(FILE *stream); #define SECUREC_LOCK_STDIN(i, s) #define SECUREC_UNLOCK_STDIN(i, s) #endif + + diff --git a/project/app/wifi_app/hisi_tools/securec/securec.h b/project/app/wifi_app/hisi_tools/securec/securec.h index 834c7f2bf..ee70267bc 100644 --- a/project/app/wifi_app/hisi_tools/securec/securec.h +++ b/project/app/wifi_app/hisi_tools/securec/securec.h @@ -1,11 +1,12 @@ /* * Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved. - * Description: The user of this secure c library should include this header - * file in you source code. This header file declare all supported API prototype - * of the library, such as memcpy_s, strcpy_s, wcscpy_s,strcat_s, strncat_s, - * sprintf_s, scanf_s, and so on. Author: lishunda Create: 2014-02-25 Notes: Do - * not modify this file by yourself. History: 2018-09-27 zhaozhijian Code base - * quality improvement + * Description: The user of this secure c library should include this header file in you source code. + * This header file declare all supported API prototype of the library, + * such as memcpy_s, strcpy_s, wcscpy_s,strcat_s, strncat_s, sprintf_s, scanf_s, and so on. + * Author: lishunda + * Create: 2014-02-25 + * Notes: Do not modify this file by yourself. + * History: 2018-09-27 zhaozhijian Code base quality improvement */ #ifndef __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 @@ -34,7 +35,7 @@ #endif /* Define error code */ -#if defined(SECUREC_NEED_ERRNO_TYPE) || !defined(__STDC_WANT_LIB_EXT1__) || \ +#if defined(SECUREC_NEED_ERRNO_TYPE) || !defined(__STDC_WANT_LIB_EXT1__) || \ (defined(__STDC_WANT_LIB_EXT1__) && (__STDC_WANT_LIB_EXT1__ == 0)) #ifndef SECUREC_DEFINED_ERRNO_TYPE #define SECUREC_DEFINED_ERRNO_TYPE @@ -61,14 +62,13 @@ typedef int errno_t; #endif #ifndef ERANGE -/* The destination buffer is not long enough and destination buffer can not be - * reset */ +/* The destination buffer is not long enough and destination buffer can not be reset */ #define ERANGE 34 #endif #ifndef ERANGE_AND_RESET /* Once the error is detected, the dest buffer must be reseted! */ -#define ERANGE_AND_RESET (34 | 128) +#define ERANGE_AND_RESET (34 | 128) #endif #ifndef EOVERLAP_AND_RESET @@ -76,8 +76,7 @@ typedef int errno_t; #define EOVERLAP_AND_RESET (54 | 128) #endif -/* If you need export the function of this library in Win32 dll, use - * __declspec(dllexport) */ +/* If you need export the function of this library in Win32 dll, use __declspec(dllexport) */ #ifndef SECUREC_API #if defined(SECUREC_DLL_EXPORT) #define SECUREC_API __declspec(dllexport) @@ -85,10 +84,10 @@ typedef int errno_t; #define SECUREC_API __declspec(dllimport) #else /* - * Standardized function declaration. If a security function is declared in the - * your code, it may cause a compilation alarm,Please delete the security - * function you declared. Adding extern under windows will cause the system to - * have inline functions to expand, so do not add the extern in default + * Standardized function declaration. If a security function is declared in the your code, + * it may cause a compilation alarm,Please delete the security function you declared. + * Adding extern under windows will cause the system to have inline functions to expand, + * so do not add the extern in default */ #if defined(_MSC_VER) #define SECUREC_API @@ -101,569 +100,532 @@ typedef int errno_t; #ifdef __cplusplus extern "C" { #endif -/* - * Description: The GetHwSecureCVersion function get SecureC Version string and - * version number. Parameter: verNumber - to store version number Return: - * version string - */ -SECUREC_API const char *GetHwSecureCVersion(unsigned short *verNumber); + /* + * Description: The GetHwSecureCVersion function get SecureC Version string and version number. + * Parameter: verNumber - to store version number + * Return: version string + */ + SECUREC_API const char *GetHwSecureCVersion(unsigned short *verNumber); #if SECUREC_ENABLE_MEMSET -/* - * Description: The memset_s function copies the value of c (converted to an - * unsigned char) into each of the first count characters of the object pointed - * to by dest. Parameter: dest - destination address Parameter: destMax - The - * maximum length of destination buffer Parameter: c - the value to be copied - * Parameter: count - copies count bytes of value to dest - * Return: EOK if there was no runtime-constraint violation - */ -SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count); + /* + * Description: The memset_s function copies the value of c (converted to an unsigned char) into each of + * the first count characters of the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: c - the value to be copied + * Parameter: count - copies count bytes of value to dest + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count); #endif #ifndef SECUREC_ONLY_DECLARE_MEMSET -#define SECUREC_ONLY_DECLARE_MEMSET 0 +#define SECUREC_ONLY_DECLARE_MEMSET 0 #endif #if SECUREC_ONLY_DECLARE_MEMSET == 0 #if SECUREC_ENABLE_MEMMOVE -/* - * Description: The memmove_s function copies n characters from the object - * pointed to by src into the object pointed to by dest. Parameter: dest - - * destination address Parameter: destMax - The maximum length of destination - * buffer Parameter: src - source address Parameter: count - copies count bytes - * from the src Return: EOK if there was no runtime-constraint violation - */ -SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, - size_t count); + /* + * Description: The memmove_s function copies n characters from the object pointed to by src + * into the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: src - source address + * Parameter: count - copies count bytes from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count); #endif #if SECUREC_ENABLE_MEMCPY -/* - * Description: The memcpy_s function copies n characters from the object - * pointed to by src into the object pointed to by dest. Parameter: dest - - * destination address Parameter: destMax - The maximum length of destination - * buffer Parameter: src - source address Parameter: count - copies count bytes - * from the src Return: EOK if there was no runtime-constraint violation - */ -SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, - size_t count); + /* + * Description: The memcpy_s function copies n characters from the object pointed to + * by src into the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: src - source address + * Parameter: count - copies count bytes from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count); #endif #if SECUREC_ENABLE_STRCPY -/* - * Description: The strcpy_s function copies the string pointed to by strSrc - * (including the terminating null character) into the array pointed to by - * strDest Parameter: strDest - destination address Parameter: destMax - The - * maximum length of destination buffer(including the terminating null - * character) Parameter: strSrc - source address Return: EOK if there was no - * runtime-constraint violation - */ -SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc); + /* + * Description: The strcpy_s function copies the string pointed to by strSrc (including + * the terminating null character) into the array pointed to by strDest + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null character) + * Parameter: strSrc - source address + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc); #endif #if SECUREC_ENABLE_STRNCPY -/* - * Description: The strncpy_s function copies not more than n successive - * characters (not including the terminating null character) from the array - * pointed to by strSrc to the array pointed to by strDest. Parameter: strDest - - * destination address Parameter: destMax - The maximum length of destination - * buffer(including the terminating null character) Parameter: strSrc - source - * address Parameter: count - copies count characters from the src Return: EOK - * if there was no runtime-constraint violation - */ -SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, - size_t count); + /* + * Description: The strncpy_s function copies not more than n successive characters (not including + * the terminating null character) from the array pointed to by strSrc to the array pointed to by strDest. + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null character) + * Parameter: strSrc - source address + * Parameter: count - copies count characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count); #endif #if SECUREC_ENABLE_STRCAT -/* - * Description: The strcat_s function appends a copy of the string pointed to by - * strSrc (including the terminating null character) to the end of the string - * pointed to by strDest. Parameter: strDest - destination address Parameter: - * destMax - The maximum length of destination buffer(including the terminating - * null wide character) Parameter: strSrc - source address Return: EOK if - * there was no runtime-constraint violation - */ -SECUREC_API errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc); + /* + * Description: The strcat_s function appends a copy of the string pointed to by strSrc (including + * the terminating null character) to the end of the string pointed to by strDest. + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null wide character) + * Parameter: strSrc - source address + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc); #endif #if SECUREC_ENABLE_STRNCAT -/* - * Description: The strncat_s function appends not more than n successive - * characters (not including the terminating null character) from the array - * pointed to by strSrc to the end of the string pointed to by strDest. - * Parameter: strDest - destination address - * Parameter: destMax - The maximum length of destination buffer(including the - * terminating null character) Parameter: strSrc - source address Parameter: - * count - copies count characters from the src Return: EOK if there was no - * runtime-constraint violation - */ -SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, - size_t count); + /* + * Description: The strncat_s function appends not more than n successive characters (not including + * the terminating null character) + * from the array pointed to by strSrc to the end of the string pointed to by strDest. + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null character) + * Parameter: strSrc - source address + * Parameter: count - copies count characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count); #endif #if SECUREC_ENABLE_VSPRINTF -/* - * Description: The vsprintf_s function is equivalent to the vsprintf function - * except for the parameter destMax and the explicit runtime-constraints - * violation Parameter: strDest - produce output according to a format ,write - * to the character string strDest. Parameter: destMax - The maximum length of - * destination buffer(including the terminating null wide characte) Parameter: - * format - fromat string Parameter: argList - instead of a variable number of - * arguments Return: the number of characters printed(not including the - * terminating null byte '\0'), If an error occurred Return: -1. - */ -SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format, - va_list argList) SECUREC_ATTRIBUTE(3, 0); + /* + * Description: The vsprintf_s function is equivalent to the vsprintf function except for the parameter destMax + * and the explicit runtime-constraints violation + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null wide characte) + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1. + */ + SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format, + va_list argList) SECUREC_ATTRIBUTE(3, 0); #endif #if SECUREC_ENABLE_SPRINTF -/* - * Description: The sprintf_s function is equivalent to the sprintf function - * except for the parameter destMax and the explicit runtime-constraints - * violation Parameter: strDest - produce output according to a format ,write - * to the character string strDest. Parameter: destMax - The maximum length of - * destination buffer(including the terminating null byte '\0') Parameter: - * format - fromat string Return: the number of characters printed(not - * including the terminating null byte '\0'), If an error occurred Return: -1. - */ -SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format, - ...) SECUREC_ATTRIBUTE(3, 4); + /* + * Description: The sprintf_s function is equivalent to the sprintf function except for the parameter destMax + * and the explicit runtime-constraints violation + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: format - fromat string + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1. + */ + SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format, ...) SECUREC_ATTRIBUTE(3, 4); #endif #if SECUREC_ENABLE_VSNPRINTF -/* - * Description: The vsnprintf_s function is equivalent to the vsnprintf - * function except for the parameter destMax/count and the explicit - * runtime-constraints violation Parameter: strDest - produce output according - * to a format ,write to the character string strDest. Parameter: destMax - The - * maximum length of destination buffer(including the terminating null byte - * '\0') Parameter: count - do not write more than count bytes to strDest(not - * including the terminating null byte '\0') Parameter: format - fromat string - * Parameter: argList - instead of a variable number of arguments - * Return: the number of characters printed(not including the terminating - * null byte '\0'), If an error occurred Return: -1.Pay special attention to - * returning -1 when truncation occurs - */ -SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count, - const char *format, va_list argList) - SECUREC_ATTRIBUTE(4, 0); + /* + * Description: The vsnprintf_s function is equivalent to the vsnprintf function except for + * the parameter destMax/count and the explicit runtime-constraints violation + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0') + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs + */ + SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format, + va_list argList) SECUREC_ATTRIBUTE(4, 0); #endif #if SECUREC_ENABLE_SNPRINTF -/* - * Description: The snprintf_s function is equivalent to the snprintf function - * except for the parameter destMax/count and the explicit runtime-constraints - * violation Parameter: strDest - produce output according to a format ,write to - * the character string strDest. Parameter: destMax - The maximum length of - * destination buffer(including the terminating null byte '\0') Parameter: - * count - do not write more than count bytes to strDest(not including the - * terminating null byte '\0') Parameter: format - fromat string Return: the - * number of characters printed(not including the terminating null byte '\0'), - * If an error occurred Return: -1.Pay special attention to returning -1 when - * truncation occurs - */ -SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count, - const char *format, ...) SECUREC_ATTRIBUTE(4, 5); + /* + * Description: The snprintf_s function is equivalent to the snprintf function except for + * the parameter destMax/count and the explicit runtime-constraints violation + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0') + * Parameter: format - fromat string + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs + */ + SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, + ...) SECUREC_ATTRIBUTE(4, 5); #endif #if SECUREC_SNPRINTF_TRUNCATED -/* - * Description: The vsnprintf_truncated_s function is equivalent to the - * vsnprintf_s function except no count parameter and return value Parameter: - * strDest - produce output according to a format ,write to the character - * string strDest Parameter: destMax - The maximum length of destination - * buffer(including the terminating null byte '\0') Parameter: format - fromat - * string Parameter: argList - instead of a variable number of arguments - * Return: the number of characters printed(not including the terminating - * null byte '\0'), If an error occurred Return: -1.Pay special attention to - * returning destMax - 1 when truncation occurs - */ -SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax, - const char *format, va_list argList) - SECUREC_ATTRIBUTE(3, 0); + /* + * Description: The vsnprintf_truncated_s function is equivalent to the vsnprintf_s function except + * no count parameter and return value + * Parameter: strDest - produce output according to a format ,write to the character string strDest + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs + */ + SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format, + va_list argList) SECUREC_ATTRIBUTE(3, 0); -/* - * Description: The snprintf_truncated_s function is equivalent to the - * snprintf_2 function except no count parameter and return value Parameter: - * strDest - produce output according to a format ,write to the character - * string strDest. Parameter: destMax - The maximum length of destination - * buffer(including the terminating null byte '\0') Parameter: format - fromat - * string Return: the number of characters printed(not including the - * terminating null byte '\0'), If an error occurred Return: -1.Pay special - * attention to returning destMax - 1 when truncation occurs - */ -SECUREC_API int snprintf_truncated_s(char *strDest, size_t destMax, - const char *format, ...) - SECUREC_ATTRIBUTE(3, 4); + /* + * Description: The snprintf_truncated_s function is equivalent to the snprintf_2 function except + * no count parameter and return value + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: format - fromat string + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs + */ + SECUREC_API int snprintf_truncated_s(char *strDest, size_t destMax, + const char *format, ...) SECUREC_ATTRIBUTE(3, 4); #endif #if SECUREC_ENABLE_SCANF -/* - * Description: The scanf_s function is equivalent to fscanf_s with the - * argument stdin interposed before the arguments to scanf_s Parameter: format - - * fromat string Return: the number of input items assigned, If an error - * occurred Return: -1. - */ -SECUREC_API int scanf_s(const char *format, ...); + /* + * Description: The scanf_s function is equivalent to fscanf_s with the argument stdin + * interposed before the arguments to scanf_s + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int scanf_s(const char *format, ...); #endif #if SECUREC_ENABLE_VSCANF -/* - * Description: The vscanf_s function is equivalent to scanf_s, with the - * variable argument list replaced by argList Parameter: format - fromat string - * Parameter: argList - instead of a variable number of arguments - * Return: the number of input items assigned, If an error occurred Return: - * -1. - */ -SECUREC_API int vscanf_s(const char *format, va_list argList); + /* + * Description: The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vscanf_s(const char *format, va_list argList); #endif #if SECUREC_ENABLE_SSCANF -/* - * Description: The sscanf_s function is equivalent to fscanf_s, except that - * input is obtained from a string (specified by the argument buffer) rather - * than from a stream Parameter: buffer - read character from buffer - * Parameter: format - fromat string - * Return: the number of input items assigned, If an error occurred Return: - * -1. - */ -SECUREC_API int sscanf_s(const char *buffer, const char *format, ...); + /* + * Description: The sscanf_s function is equivalent to fscanf_s, except that input is obtained from a + * string (specified by the argument buffer) rather than from a stream + * Parameter: buffer - read character from buffer + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int sscanf_s(const char *buffer, const char *format, ...); #endif #if SECUREC_ENABLE_VSSCANF -/* - * Description: The vsscanf_s function is equivalent to sscanf_s, with the - * variable argument list replaced by argList Parameter: buffer - read - * character from buffer Parameter: format - fromat string Parameter: argList - - * instead of a variable number of arguments Return: the number of input - * items assigned, If an error occurred Return: -1. - */ -SECUREC_API int vsscanf_s(const char *buffer, const char *format, - va_list argList); + /* + * Description: The vsscanf_s function is equivalent to sscanf_s, with the variable argument list + * replaced by argList + * Parameter: buffer - read character from buffer + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vsscanf_s(const char *buffer, const char *format, va_list argList); #endif #if SECUREC_ENABLE_FSCANF -/* - * Description: The fscanf_s function is equivalent to fscanf except that the - * c, s, and [ conversion specifiers apply to a pair of arguments (unless - * assignment suppression is indicated by a*) Parameter: stream - stdio file - * stream Parameter: format - fromat string Return: the number of input items - * assigned, If an error occurred Return: -1. - */ -SECUREC_API int fscanf_s(FILE *stream, const char *format, ...); + /* + * Description: The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers + * apply to a pair of arguments (unless assignment suppression is indicated by a*) + * Parameter: stream - stdio file stream + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int fscanf_s(FILE *stream, const char *format, ...); #endif #if SECUREC_ENABLE_VFSCANF -/* - * Description: The vfscanf_s function is equivalent to fscanf_s, with the - * variable argument list replaced by argList Parameter: stream - stdio file - * stream Parameter: format - fromat string Parameter: argList - instead of a - * variable number of arguments Return: the number of input items assigned, - * If an error occurred Return: -1. - */ -SECUREC_API int vfscanf_s(FILE *stream, const char *format, va_list argList); + /* + * Description: The vfscanf_s function is equivalent to fscanf_s, with the variable argument list + * replaced by argList + * Parameter: stream - stdio file stream + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vfscanf_s(FILE *stream, const char *format, va_list argList); #endif #if SECUREC_ENABLE_STRTOK -/* - * Description: The strtok_s function parses a string into a sequence of - * strToken, replace all characters in strToken string that match to strDelimit - * set with 0. On the first call to strtok_s the string to be parsed should be - * specified in strToken. In each subsequent call that should parse the same - * string, strToken should be NULL Parameter: strToken - the string to be - * delimited Parameter: strDelimit - specifies a set of characters that delimit - * the tokens in the parsed string Parameter: context - is a pointer to a char * - * variable that is used internally by strtok_s function Return: On the first - * call returns the address of the first non \0 character, otherwise NULL is - * returned. In subsequent calls, the strtoken is set to NULL, and the context - * set is the same as the previous call, return NULL if the *context string - * length is equal 0, otherwise return *context. - */ -SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, - char **context); + /* + * Description: The strtok_s function parses a string into a sequence of strToken, + * replace all characters in strToken string that match to strDelimit set with 0. + * On the first call to strtok_s the string to be parsed should be specified in strToken. + * In each subsequent call that should parse the same string, strToken should be NULL + * Parameter: strToken - the string to be delimited + * Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string + * Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function + * Return: On the first call returns the address of the first non \0 character, otherwise NULL is returned. + * In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call, + * return NULL if the *context string length is equal 0, otherwise return *context. + */ + SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, char **context); #endif #if SECUREC_ENABLE_GETS && SECUREC_IN_KERNEL == 0 -/* - * Description: The gets_s function reads at most one less than the number of - * characters specified by destMax from the stream pointed to by stdin, into the - * array pointed to by buffer Parameter: buffer - destination address - * Parameter: destMax - The maximum length of destination buffer(including the - * terminating null character) Return: buffer if there was no - * runtime-constraint violation,If an error occurred Return: NULL. - */ -SECUREC_API char *gets_s(char *buffer, size_t destMax); + /* + * Description: The gets_s function reads at most one less than the number of characters specified + * by destMax from the stream pointed to by stdin, into the array pointed to by buffer + * Parameter: buffer - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null character) + * Return: buffer if there was no runtime-constraint violation,If an error occurred Return: NULL. + */ + SECUREC_API char *gets_s(char *buffer, size_t destMax); #endif + #if SECUREC_ENABLE_WCHAR_FUNC #if SECUREC_ENABLE_MEMCPY -/* - * Description: The wmemcpy_s function copies n successive wide characters from - * the object pointed to by src into the object pointed to by dest. Parameter: - * dest - destination address Parameter: destMax - The maximum length of - * destination buffer Parameter: src - source address Parameter: count - copies - * count wide characters from the src Return: EOK if there was no - * runtime-constraint violation - */ -SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, - size_t count); + /* + * Description: The wmemcpy_s function copies n successive wide characters from the object pointed to + * by src into the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: src - source address + * Parameter: count - copies count wide characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count); #endif #if SECUREC_ENABLE_MEMMOVE -/* - * Description: The wmemmove_s function copies n successive wide characters from - * the object pointed to by src into the object pointed to by dest. Parameter: - * dest - destination address Parameter: destMax - The maximum length of - * destination buffer Parameter: src - source address Parameter: count - copies - * count wide characters from the src Return: EOK if there was no - * runtime-constraint violation - */ -SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, - const wchar_t *src, size_t count); + /* + * Description: The wmemmove_s function copies n successive wide characters from the object + * pointed to by src into the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: src - source address + * Parameter: count - copies count wide characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count); #endif #if SECUREC_ENABLE_STRCPY -/* - * Description: The wcscpy_s function copies the wide string pointed to by - * strSrc (including theterminating null wide character) into the array pointed - * to by strDest Parameter: strDest - destination address Parameter: destMax - - * The maximum length of destination buffer Parameter: strSrc - source address - * Return: EOK if there was no runtime-constraint violation - */ -SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, - const wchar_t *strSrc); + /* + * Description: The wcscpy_s function copies the wide string pointed to by strSrc (including theterminating + * null wide character) into the array pointed to by strDest + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: strSrc - source address + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc); #endif #if SECUREC_ENABLE_STRNCPY -/* - * Description: The wcsncpy_s function copies not more than n successive wide - * characters (not including the terminating null wide character) from the array - * pointed to by strSrc to the array pointed to by strDest Parameter: strDest - - * destination address Parameter: destMax - The maximum length of destination - * buffer(including the terminating wide character) Parameter: strSrc - source - * address Parameter: count - copies count wide characters from the src Return: - * EOK if there was no runtime-constraint violation - */ -SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, - const wchar_t *strSrc, size_t count); + /* + * Description: The wcsncpy_s function copies not more than n successive wide characters (not including the + * terminating null wide character) from the array pointed to by strSrc to the array pointed to by strDest + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating wide character) + * Parameter: strSrc - source address + * Parameter: count - copies count wide characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count); #endif #if SECUREC_ENABLE_STRCAT -/* - * Description: The wcscat_s function appends a copy of the wide string pointed - * to by strSrc (including the terminating null wide character) to the end of - * the wide string pointed to by strDest Parameter: strDest - destination - * address Parameter: destMax - The maximum length of destination - * buffer(including the terminating wide character) Parameter: strSrc - source - * address Return: EOK if there was no runtime-constraint violation - */ -SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, - const wchar_t *strSrc); + /* + * Description: The wcscat_s function appends a copy of the wide string pointed to by strSrc (including the + * terminating null wide character) to the end of the wide string pointed to by strDest + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating wide character) + * Parameter: strSrc - source address + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc); #endif #if SECUREC_ENABLE_STRNCAT -/* - * Description: The wcsncat_s function appends not more than n successive wide - * characters (not including the terminating null wide character) from the array - * pointed to by strSrc to the end of the wide string pointed to by strDest. - * Parameter: strDest - destination address - * Parameter: destMax - The maximum length of destination buffer(including the - * terminating wide character) Parameter: strSrc - source address Parameter: - * count - copies count wide characters from the src Return: EOK if there - * was no runtime-constraint violation - */ -SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, - const wchar_t *strSrc, size_t count); + /* + * Description: The wcsncat_s function appends not more than n successive wide characters (not including the + * terminating null wide character) from the array pointed to by strSrc to the end of the wide string pointed to + * by strDest. + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating wide character) + * Parameter: strSrc - source address + * Parameter: count - copies count wide characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count); #endif #if SECUREC_ENABLE_STRTOK -/* - * Description: The wcstok_s function is the wide-character equivalent of - * the strtok_s function Parameter: strToken - the string to be delimited - * Parameter: strDelimit - specifies a set of characters that delimit the tokens - * in the parsed string Parameter: context - is a pointer to a char * variable - * that is used internally by strtok_s function Return: a pointer to the - * first character of a token, or a null pointer if there is no token or there - * is a runtime-constraint violation. - */ -SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, - wchar_t **context); + /* + * Description: The wcstok_s function is the wide-character equivalent of the strtok_s function + * Parameter: strToken - the string to be delimited + * Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string + * Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function + * Return: a pointer to the first character of a token, or a null pointer if there is no token + * or there is a runtime-constraint violation. + */ + SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context); #endif #if SECUREC_ENABLE_VSPRINTF -/* - * Description: The vswprintf_s function is the wide-character equivalent - * of the vsprintf_s function Parameter: strDest - produce output according to - * a format ,write to the character string strDest Parameter: destMax - The - * maximum length of destination buffer(including the terminating null ) - * Parameter: format - fromat string - * Parameter: argList - instead of a variable number of arguments - * Return: the number of characters printed(not including the terminating - * null wide characte), If an error occurred Return: -1. - */ -SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, - const wchar_t *format, va_list argList); + /* + * Description: The vswprintf_s function is the wide-character equivalent of the vsprintf_s function + * Parameter: strDest - produce output according to a format ,write to the character string strDest + * Parameter: destMax - The maximum length of destination buffer(including the terminating null ) + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of characters printed(not including the terminating null wide characte), + * If an error occurred Return: -1. + */ + SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList); #endif #if SECUREC_ENABLE_SPRINTF -/* - * Description: The swprintf_s function is the wide-character equivalent - * of the sprintf_s function Parameter: strDest - produce output according to a - * format ,write to the character string strDest Parameter: destMax - The - * maximum length of destination buffer(including the terminating null ) - * Parameter: format - fromat string - * Return: the number of characters printed(not including the terminating - * null wide characte), If an error occurred Return: -1. - */ -SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, - const wchar_t *format, ...); + /* + * Description: The swprintf_s function is the wide-character equivalent of the sprintf_s function + * Parameter: strDest - produce output according to a format ,write to the character string strDest + * Parameter: destMax - The maximum length of destination buffer(including the terminating null ) + * Parameter: format - fromat string + * Return: the number of characters printed(not including the terminating null wide characte), + * If an error occurred Return: -1. + */ + SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...); #endif #if SECUREC_ENABLE_FSCANF -/* - * Description: The fwscanf_s function is the wide-character equivalent - * of the fscanf_s function Parameter: stream - stdio file stream Parameter: - * format - fromat string Return: the number of input items assigned, If an - * error occurred Return: -1. - */ -SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...); + /* + * Description: The fwscanf_s function is the wide-character equivalent of the fscanf_s function + * Parameter: stream - stdio file stream + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...); #endif #if SECUREC_ENABLE_VFSCANF -/* - * Description: The vfwscanf_s function is the wide-character equivalent - * of the vfscanf_s function Parameter: stream - stdio file stream Parameter: - * format - fromat string Parameter: argList - instead of a variable number of - * arguments Return: the number of input items assigned, If an error occurred - * Return: -1. - */ -SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, - va_list argList); + /* + * Description: The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function + * Parameter: stream - stdio file stream + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList); #endif #if SECUREC_ENABLE_SCANF -/* - * Description: The wscanf_s function is the wide-character equivalent of - * the scanf_s function Parameter: format - fromat string Return: the number - * of input items assigned, If an error occurred Return: -1. - */ -SECUREC_API int wscanf_s(const wchar_t *format, ...); + /* + * Description: The wscanf_s function is the wide-character equivalent of the scanf_s function + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int wscanf_s(const wchar_t *format, ...); #endif #if SECUREC_ENABLE_VSCANF -/* - * Description: The vwscanf_s function is the wide-character equivalent - * of the vscanf_s function Parameter: format - fromat string Parameter: argList - * - instead of a variable number of arguments Return: the number of input - * items assigned, If an error occurred Return: -1. - */ -SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList); + /* + * Description: The vwscanf_s function is the wide-character equivalent of the vscanf_s function + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList); #endif #if SECUREC_ENABLE_SSCANF -/* - * Description: The swscanf_s function is the wide-character equivalent - * of the sscanf_s function Parameter: buffer - read character from buffer - * Parameter: format - fromat string - * Return: the number of input items assigned, If an error occurred Return: - * -1. - */ -SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...); + /* + * Description: The swscanf_s function is the wide-character equivalent of the sscanf_s function + * Parameter: buffer - read character from buffer + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...); #endif #if SECUREC_ENABLE_VSSCANF -/* - * Description: The vswscanf_s function is the wide-character equivalent - * of the vsscanf_s function Parameter: buffer - read character from buffer - * Parameter: format - fromat string - * Parameter: argList - instead of a variable number of arguments - * Return: the number of input items assigned, If an error occurred Return: - * -1. - */ -SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, - va_list argList); + /* + * Description: The vswscanf_s function is the wide-character equivalent of the vsscanf_s function + * Parameter: buffer - read character from buffer + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList); #endif #endif /* SECUREC_ENABLE_WCHAR_FUNC */ #endif -/* Those functions are used by macro ,must declare hare , also for without - * function declaration warning */ -extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, - size_t count); -extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc); + /* Those functions are used by macro ,must declare hare , also for without function declaration warning */ + extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count); + extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc); #if SECUREC_WITH_PERFORMANCE_ADDONS -/* Those functions are used by macro */ -extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count); -extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count); -extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, - size_t count); -extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, - size_t count); + /* Those functions are used by macro */ + extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count); + extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count); + extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count); + extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count); /* The strcpy_sp is a macro, not a function in performance optimization mode. */ -#define strcpy_sp(dest, destMax, src) \ - ((__builtin_constant_p((destMax)) && __builtin_constant_p((src))) \ - ? SECUREC_STRCPY_SM((dest), (destMax), (src)) \ - : strcpy_s((dest), (destMax), (src))) +#define strcpy_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \ + __builtin_constant_p((src))) ? \ + SECUREC_STRCPY_SM((dest), (destMax), (src)) : \ + strcpy_s((dest), (destMax), (src))) -/* The strncpy_sp is a macro, not a function in performance optimization mode. - */ -#define strncpy_sp(dest, destMax, src, count) \ - ((__builtin_constant_p((count)) && __builtin_constant_p((destMax)) && \ - __builtin_constant_p((src))) \ - ? SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) \ - : strncpy_s((dest), (destMax), (src), (count))) +/* The strncpy_sp is a macro, not a function in performance optimization mode. */ +#define strncpy_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \ + __builtin_constant_p((destMax)) && \ + __builtin_constant_p((src))) ? \ + SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) : \ + strncpy_s((dest), (destMax), (src), (count))) /* The strcat_sp is a macro, not a function in performance optimization mode. */ -#define strcat_sp(dest, destMax, src) \ - ((__builtin_constant_p((destMax)) && __builtin_constant_p((src))) \ - ? SECUREC_STRCAT_SM((dest), (destMax), (src)) \ - : strcat_s((dest), (destMax), (src))) +#define strcat_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \ + __builtin_constant_p((src))) ? \ + SECUREC_STRCAT_SM((dest), (destMax), (src)) : \ + strcat_s((dest), (destMax), (src))) -/* The strncat_sp is a macro, not a function in performance optimization mode. - */ -#define strncat_sp(dest, destMax, src, count) \ - ((__builtin_constant_p((count)) && __builtin_constant_p((destMax)) && \ - __builtin_constant_p((src))) \ - ? SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) \ - : strncat_s((dest), (destMax), (src), (count))) +/* The strncat_sp is a macro, not a function in performance optimization mode. */ +#define strncat_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \ + __builtin_constant_p((destMax)) && \ + __builtin_constant_p((src))) ? \ + SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) : \ + strncat_s((dest), (destMax), (src), (count))) /* The memcpy_sp is a macro, not a function in performance optimization mode. */ -#define memcpy_sp(dest, destMax, src, count) \ - (__builtin_constant_p((count)) \ - ? (SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) \ - : (__builtin_constant_p((destMax)) \ - ? (((size_t)(destMax) > 0 && \ - (((unsigned long long)(destMax) & \ - (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) \ - ? memcpy_sOptTc((dest), (destMax), (src), (count)) \ - : ERANGE) \ - : memcpy_sOptAsm((dest), (destMax), (src), (count)))) +#define memcpy_sp(dest, destMax, src, count) (__builtin_constant_p((count)) ? \ + (SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) : \ + (__builtin_constant_p((destMax)) ? \ + (((size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \ + memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE) : \ + memcpy_sOptAsm((dest), (destMax), (src), (count)))) /* The memset_sp is a macro, not a function in performance optimization mode. */ -#define memset_sp(dest, destMax, c, count) \ - (__builtin_constant_p((count)) \ - ? (SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) \ - : (__builtin_constant_p((destMax)) \ - ? (((((unsigned long long)(destMax) & \ - (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) \ - ? memset_sOptTc((dest), (destMax), (c), (count)) \ - : ERANGE) \ - : memset_sOptAsm((dest), (destMax), (c), (count)))) +#define memset_sp(dest, destMax, c, count) (__builtin_constant_p((count)) ? \ + (SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) : \ + (__builtin_constant_p((destMax)) ? \ + (((((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \ + memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE) : \ + memset_sOptAsm((dest), (destMax), (c), (count)))) #else -#define strcpy_sp strcpy_s -#define strncpy_sp strncpy_s -#define strcat_sp strcat_s -#define strncat_sp strncat_s -#define memcpy_sp memcpy_s -#define memset_sp memset_s +#define strcpy_sp strcpy_s +#define strncpy_sp strncpy_s +#define strcat_sp strcat_s +#define strncat_sp strncat_s +#define memcpy_sp memcpy_s +#define memset_sp memset_s #endif #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 */ + diff --git a/project/app/wifi_app/hisi_tools/securec/securectype.h b/project/app/wifi_app/hisi_tools/securec/securectype.h index c3712c61f..bd2a1ef26 100644 --- a/project/app/wifi_app/hisi_tools/securec/securectype.h +++ b/project/app/wifi_app/hisi_tools/securec/securectype.h @@ -1,14 +1,13 @@ /* * Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved. - * Description: Define internal used macro and data type. The marco of - * SECUREC_ON_64BITS will be determined in this header file, which is a switch - * for part of code. Some macro are used to supress warning by MS compiler. + * Description: Define internal used macro and data type. The marco of SECUREC_ON_64BITS + * will be determined in this header file, which is a switch for part + * of code. Some macro are used to supress warning by MS compiler. * Author: lishunda * Create: 2014-02-25 - * Notes: User can change the value of SECUREC_STRING_MAX_LEN and - * SECUREC_MEM_MAX_LEN macro to meet their special need, but The maximum value - * should not exceed 2G. History: 2018-09-27 zhaozhijian Code base quality - * improvement + * Notes: User can change the value of SECUREC_STRING_MAX_LEN and SECUREC_MEM_MAX_LEN + * macro to meet their special need, but The maximum value should not exceed 2G. + * History: 2018-09-27 zhaozhijian Code base quality improvement */ /* * [Standardize-exceptions]: Performance-sensitive @@ -21,32 +20,31 @@ #ifndef SECUREC_USING_STD_SECURE_LIB #if defined(_MSC_VER) && _MSC_VER >= 1400 #if defined(__STDC_WANT_SECURE_LIB__) && __STDC_WANT_SECURE_LIB__ == 0 -/* Security functions have been provided since vs2005, default use of system - * library functions */ -#define SECUREC_USING_STD_SECURE_LIB 0 +/* Security functions have been provided since vs2005, default use of system library functions */ +#define SECUREC_USING_STD_SECURE_LIB 0 #else -#define SECUREC_USING_STD_SECURE_LIB 1 +#define SECUREC_USING_STD_SECURE_LIB 1 #endif #else -#define SECUREC_USING_STD_SECURE_LIB 0 +#define SECUREC_USING_STD_SECURE_LIB 0 #endif #endif -/* Compatibility with older Secure C versions, shielding VC symbol redefinition - * warning */ + +/* Compatibility with older Secure C versions, shielding VC symbol redefinition warning */ #if defined(_MSC_VER) && _MSC_VER >= 1400 && SECUREC_USING_STD_SECURE_LIB == 0 #ifndef SECUREC_DISABLE_CRT_FUNC -#define SECUREC_DISABLE_CRT_FUNC 1 +#define SECUREC_DISABLE_CRT_FUNC 1 #endif #ifndef SECUREC_DISABLE_CRT_IMP -#define SECUREC_DISABLE_CRT_IMP 1 +#define SECUREC_DISABLE_CRT_IMP 1 #endif #else /* MSC VER */ #ifndef SECUREC_DISABLE_CRT_FUNC -#define SECUREC_DISABLE_CRT_FUNC 0 +#define SECUREC_DISABLE_CRT_FUNC 0 #endif #ifndef SECUREC_DISABLE_CRT_IMP -#define SECUREC_DISABLE_CRT_IMP 0 +#define SECUREC_DISABLE_CRT_IMP 0 #endif #endif @@ -54,233 +52,232 @@ #ifdef __STDC_WANT_SECURE_LIB__ #undef __STDC_WANT_SECURE_LIB__ #endif -#define __STDC_WANT_SECURE_LIB__ 0 +#define __STDC_WANT_SECURE_LIB__ 0 #endif #if SECUREC_DISABLE_CRT_IMP #ifdef _CRTIMP_ALTERNATIVE #undef _CRTIMP_ALTERNATIVE #endif -#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */ +#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */ #endif /* Compile in kernel under macro control */ #ifndef SECUREC_IN_KERNEL #ifdef __KERNEL__ -#define SECUREC_IN_KERNEL 1 +#define SECUREC_IN_KERNEL 1 #else -#define SECUREC_IN_KERNEL 0 +#define SECUREC_IN_KERNEL 0 #endif #endif #if SECUREC_IN_KERNEL #ifndef SECUREC_ENABLE_SCANF_FILE -#define SECUREC_ENABLE_SCANF_FILE 0 +#define SECUREC_ENABLE_SCANF_FILE 0 #endif #ifndef SECUREC_ENABLE_WCHAR_FUNC -#define SECUREC_ENABLE_WCHAR_FUNC 0 +#define SECUREC_ENABLE_WCHAR_FUNC 0 #endif #else /* SECUREC_IN_KERNEL */ #ifndef SECUREC_ENABLE_SCANF_FILE -#define SECUREC_ENABLE_SCANF_FILE 1 +#define SECUREC_ENABLE_SCANF_FILE 1 #endif #ifndef SECUREC_ENABLE_WCHAR_FUNC -#define SECUREC_ENABLE_WCHAR_FUNC 1 +#define SECUREC_ENABLE_WCHAR_FUNC 1 #endif #endif -/* Default secure function declaration, default declarations for non-standard - * functions */ + +/* Default secure function declaration, default declarations for non-standard functions */ #ifndef SECUREC_SNPRINTF_TRUNCATED -#define SECUREC_SNPRINTF_TRUNCATED 1 +#define SECUREC_SNPRINTF_TRUNCATED 1 #endif #if SECUREC_USING_STD_SECURE_LIB #if defined(_MSC_VER) && _MSC_VER >= 1400 /* Declare secure functions that are not available in the VS compiler */ #ifndef SECUREC_ENABLE_MEMSET -#define SECUREC_ENABLE_MEMSET 1 +#define SECUREC_ENABLE_MEMSET 1 #endif /* VS 2005 have vsnprintf_s function */ #ifndef SECUREC_ENABLE_VSNPRINTF -#define SECUREC_ENABLE_VSNPRINTF 0 +#define SECUREC_ENABLE_VSNPRINTF 0 #endif #ifndef SECUREC_ENABLE_SNPRINTF -/* VS 2005 have vsnprintf_s function Adapt the snprintf_s of the security - * function */ +/* VS 2005 have vsnprintf_s function Adapt the snprintf_s of the security function */ #define snprintf_s _snprintf_s -#define SECUREC_ENABLE_SNPRINTF 0 +#define SECUREC_ENABLE_SNPRINTF 0 #endif /* Before VS 2010 do not have v functions */ #if _MSC_VER <= 1600 || defined(SECUREC_FOR_V_SCANFS) #ifndef SECUREC_ENABLE_VFSCANF -#define SECUREC_ENABLE_VFSCANF 1 +#define SECUREC_ENABLE_VFSCANF 1 #endif #ifndef SECUREC_ENABLE_VSCANF -#define SECUREC_ENABLE_VSCANF 1 +#define SECUREC_ENABLE_VSCANF 1 #endif #ifndef SECUREC_ENABLE_VSSCANF -#define SECUREC_ENABLE_VSSCANF 1 +#define SECUREC_ENABLE_VSSCANF 1 #endif #endif #else /* MSC VER */ #ifndef SECUREC_ENABLE_MEMSET -#define SECUREC_ENABLE_MEMSET 0 +#define SECUREC_ENABLE_MEMSET 0 #endif #ifndef SECUREC_ENABLE_SNPRINTF -#define SECUREC_ENABLE_SNPRINTF 0 +#define SECUREC_ENABLE_SNPRINTF 0 #endif #ifndef SECUREC_ENABLE_VSNPRINTF -#define SECUREC_ENABLE_VSNPRINTF 0 +#define SECUREC_ENABLE_VSNPRINTF 0 #endif #endif #ifndef SECUREC_ENABLE_MEMMOVE -#define SECUREC_ENABLE_MEMMOVE 0 +#define SECUREC_ENABLE_MEMMOVE 0 #endif #ifndef SECUREC_ENABLE_MEMCPY -#define SECUREC_ENABLE_MEMCPY 0 +#define SECUREC_ENABLE_MEMCPY 0 #endif #ifndef SECUREC_ENABLE_STRCPY -#define SECUREC_ENABLE_STRCPY 0 +#define SECUREC_ENABLE_STRCPY 0 #endif #ifndef SECUREC_ENABLE_STRNCPY -#define SECUREC_ENABLE_STRNCPY 0 +#define SECUREC_ENABLE_STRNCPY 0 #endif #ifndef SECUREC_ENABLE_STRCAT -#define SECUREC_ENABLE_STRCAT 0 +#define SECUREC_ENABLE_STRCAT 0 #endif #ifndef SECUREC_ENABLE_STRNCAT -#define SECUREC_ENABLE_STRNCAT 0 +#define SECUREC_ENABLE_STRNCAT 0 #endif #ifndef SECUREC_ENABLE_SPRINTF -#define SECUREC_ENABLE_SPRINTF 0 +#define SECUREC_ENABLE_SPRINTF 0 #endif #ifndef SECUREC_ENABLE_VSPRINTF -#define SECUREC_ENABLE_VSPRINTF 0 +#define SECUREC_ENABLE_VSPRINTF 0 #endif #ifndef SECUREC_ENABLE_SSCANF -#define SECUREC_ENABLE_SSCANF 0 +#define SECUREC_ENABLE_SSCANF 0 #endif #ifndef SECUREC_ENABLE_VSSCANF -#define SECUREC_ENABLE_VSSCANF 0 +#define SECUREC_ENABLE_VSSCANF 0 #endif #ifndef SECUREC_ENABLE_SCANF -#define SECUREC_ENABLE_SCANF 0 +#define SECUREC_ENABLE_SCANF 0 #endif #ifndef SECUREC_ENABLE_VSCANF -#define SECUREC_ENABLE_VSCANF 0 +#define SECUREC_ENABLE_VSCANF 0 #endif #ifndef SECUREC_ENABLE_FSCANF -#define SECUREC_ENABLE_FSCANF 0 +#define SECUREC_ENABLE_FSCANF 0 #endif #ifndef SECUREC_ENABLE_VFSCANF -#define SECUREC_ENABLE_VFSCANF 0 +#define SECUREC_ENABLE_VFSCANF 0 #endif #ifndef SECUREC_ENABLE_STRTOK -#define SECUREC_ENABLE_STRTOK 0 +#define SECUREC_ENABLE_STRTOK 0 #endif #ifndef SECUREC_ENABLE_GETS -#define SECUREC_ENABLE_GETS 0 +#define SECUREC_ENABLE_GETS 0 #endif #else /* SECUREC USE STD SECURE LIB */ #ifndef SECUREC_ENABLE_MEMSET -#define SECUREC_ENABLE_MEMSET 1 +#define SECUREC_ENABLE_MEMSET 1 #endif #ifndef SECUREC_ENABLE_MEMMOVE -#define SECUREC_ENABLE_MEMMOVE 1 +#define SECUREC_ENABLE_MEMMOVE 1 #endif #ifndef SECUREC_ENABLE_MEMCPY -#define SECUREC_ENABLE_MEMCPY 1 +#define SECUREC_ENABLE_MEMCPY 1 #endif #ifndef SECUREC_ENABLE_STRCPY -#define SECUREC_ENABLE_STRCPY 1 +#define SECUREC_ENABLE_STRCPY 1 #endif #ifndef SECUREC_ENABLE_STRNCPY -#define SECUREC_ENABLE_STRNCPY 1 +#define SECUREC_ENABLE_STRNCPY 1 #endif #ifndef SECUREC_ENABLE_STRCAT -#define SECUREC_ENABLE_STRCAT 1 +#define SECUREC_ENABLE_STRCAT 1 #endif #ifndef SECUREC_ENABLE_STRNCAT -#define SECUREC_ENABLE_STRNCAT 1 +#define SECUREC_ENABLE_STRNCAT 1 #endif #ifndef SECUREC_ENABLE_SPRINTF -#define SECUREC_ENABLE_SPRINTF 1 +#define SECUREC_ENABLE_SPRINTF 1 #endif #ifndef SECUREC_ENABLE_VSPRINTF -#define SECUREC_ENABLE_VSPRINTF 1 +#define SECUREC_ENABLE_VSPRINTF 1 #endif #ifndef SECUREC_ENABLE_SNPRINTF -#define SECUREC_ENABLE_SNPRINTF 1 +#define SECUREC_ENABLE_SNPRINTF 1 #endif #ifndef SECUREC_ENABLE_VSNPRINTF -#define SECUREC_ENABLE_VSNPRINTF 1 +#define SECUREC_ENABLE_VSNPRINTF 1 #endif #ifndef SECUREC_ENABLE_SSCANF -#define SECUREC_ENABLE_SSCANF 1 +#define SECUREC_ENABLE_SSCANF 1 #endif #ifndef SECUREC_ENABLE_VSSCANF -#define SECUREC_ENABLE_VSSCANF 1 +#define SECUREC_ENABLE_VSSCANF 1 #endif #ifndef SECUREC_ENABLE_SCANF #if SECUREC_ENABLE_SCANF_FILE -#define SECUREC_ENABLE_SCANF 1 +#define SECUREC_ENABLE_SCANF 1 #else -#define SECUREC_ENABLE_SCANF 0 +#define SECUREC_ENABLE_SCANF 0 #endif #endif #ifndef SECUREC_ENABLE_VSCANF #if SECUREC_ENABLE_SCANF_FILE -#define SECUREC_ENABLE_VSCANF 1 +#define SECUREC_ENABLE_VSCANF 1 #else -#define SECUREC_ENABLE_VSCANF 0 +#define SECUREC_ENABLE_VSCANF 0 #endif #endif #ifndef SECUREC_ENABLE_FSCANF #if SECUREC_ENABLE_SCANF_FILE -#define SECUREC_ENABLE_FSCANF 1 +#define SECUREC_ENABLE_FSCANF 1 #else -#define SECUREC_ENABLE_FSCANF 0 +#define SECUREC_ENABLE_FSCANF 0 #endif #endif #ifndef SECUREC_ENABLE_VFSCANF #if SECUREC_ENABLE_SCANF_FILE -#define SECUREC_ENABLE_VFSCANF 1 +#define SECUREC_ENABLE_VFSCANF 1 #else -#define SECUREC_ENABLE_VFSCANF 0 +#define SECUREC_ENABLE_VFSCANF 0 #endif #endif #ifndef SECUREC_ENABLE_STRTOK -#define SECUREC_ENABLE_STRTOK 1 +#define SECUREC_ENABLE_STRTOK 1 #endif #ifndef SECUREC_ENABLE_GETS -#define SECUREC_ENABLE_GETS 1 +#define SECUREC_ENABLE_GETS 1 #endif #endif /* SECUREC_USE_STD_SECURE_LIB */ #if SECUREC_ENABLE_SCANF_FILE == 0 #if SECUREC_ENABLE_FSCANF #undef SECUREC_ENABLE_FSCANF -#define SECUREC_ENABLE_FSCANF 0 +#define SECUREC_ENABLE_FSCANF 0 #endif #if SECUREC_ENABLE_VFSCANF #undef SECUREC_ENABLE_VFSCANF -#define SECUREC_ENABLE_VFSCANF 0 +#define SECUREC_ENABLE_VFSCANF 0 #endif #if SECUREC_ENABLE_SCANF #undef SECUREC_ENABLE_SCANF -#define SECUREC_ENABLE_SCANF 0 +#define SECUREC_ENABLE_SCANF 0 #endif #if SECUREC_ENABLE_FSCANF #undef SECUREC_ENABLE_FSCANF -#define SECUREC_ENABLE_FSCANF 0 +#define SECUREC_ENABLE_FSCANF 0 #endif #endif @@ -310,9 +307,8 @@ #endif /* - * If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS - * macro, default is enable. The macro is automatically closed on the windows - * platform and linux kernel + * If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS macro, default is enable. + * The macro is automatically closed on the windows platform and linux kernel */ #ifndef SECUREC_WITH_PERFORMANCE_ADDONS #if SECUREC_IN_KERNEL @@ -322,18 +318,15 @@ #endif #endif -/* If enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible - * to Windows. */ -#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) && \ - !defined(SECUREC_COMPATIBLE_LINUX_FORMAT) +/* If enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible to Windows. */ +#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) && !defined(SECUREC_COMPATIBLE_LINUX_FORMAT) #ifndef SECUREC_COMPATIBLE_WIN_FORMAT #define SECUREC_COMPATIBLE_WIN_FORMAT #endif #endif #if defined(SECUREC_COMPATIBLE_WIN_FORMAT) -/* On windows platform, can't use optimized function for there is no - * __builtin_constant_p like function */ +/* On windows platform, can't use optimized function for there is no __builtin_constant_p like function */ /* If need optimized macro, can define this: define __builtin_constant_p(x) 0 */ #ifdef SECUREC_WITH_PERFORMANCE_ADDONS #undef SECUREC_WITH_PERFORMANCE_ADDONS @@ -341,17 +334,15 @@ #endif #endif -#if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || \ - defined(_VXWORKS_PLATFORM_) || defined(SECUREC_VXWORKS_VERSION_5_4) +#if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || defined(_VXWORKS_PLATFORM_) || \ + defined(SECUREC_VXWORKS_VERSION_5_4) #ifndef SECUREC_VXWORKS_PLATFORM #define SECUREC_VXWORKS_PLATFORM #endif #endif -/* If enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be - * compatible to Linux. */ -#if !defined(SECUREC_COMPATIBLE_WIN_FORMAT) && \ - !defined(SECUREC_VXWORKS_PLATFORM) +/* If enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be compatible to Linux. */ +#if !defined(SECUREC_COMPATIBLE_WIN_FORMAT) && !defined(SECUREC_VXWORKS_PLATFORM) #ifndef SECUREC_COMPATIBLE_LINUX_FORMAT #define SECUREC_COMPATIBLE_LINUX_FORMAT #endif @@ -368,10 +359,9 @@ #endif /* - * Add the -DSECUREC_SUPPORT_FORMAT_WARNING compiler option to supoort - * -Wformat. Default does not check the format is that the same data type in the - * actual code. In the product is different in the original data type definition - * of VxWorks and Linux. + * Add the -DSECUREC_SUPPORT_FORMAT_WARNING compiler option to supoort -Wformat. + * Default does not check the format is that the same data type in the actual code. + * In the product is different in the original data type definition of VxWorks and Linux. */ #ifndef SECUREC_SUPPORT_FORMAT_WARNING #define SECUREC_SUPPORT_FORMAT_WARNING 0 @@ -379,19 +369,18 @@ /* SECUREC_PCLINT for tool do not recognize __attribute__ just for pclint */ #if SECUREC_SUPPORT_FORMAT_WARNING && !defined(SECUREC_PCLINT) -#define SECUREC_ATTRIBUTE(x, y) __attribute__((format(printf, (x), (y)))) +#define SECUREC_ATTRIBUTE(x, y) __attribute__((format(printf, (x), (y)))) #else #define SECUREC_ATTRIBUTE(x, y) #endif /* SECUREC_PCLINT for tool do not recognize __builtin_expect, just for pclint */ -#if defined(__GNUC__) && \ - ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))) && \ +#if defined(__GNUC__) && \ + ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))) && \ !defined(SECUREC_PCLINT) /* - * This is a built-in function that can be used without a declaration, if you - * encounter an undeclared compilation alarm, you can add - * -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to complier options + * This is a built-in function that can be used without a declaration, if you encounter an undeclared compilation alarm, + * you can add -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to complier options */ #ifdef SECUREC_NEED_BUILTIN_EXPECT_DECLARE long __builtin_expect(long exp, long c); @@ -429,8 +418,7 @@ long __builtin_expect(long exp, long c); #define SECUREC_ON_64BITS #endif -#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__) && \ - defined(__SIZEOF_POINTER__)) +#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__) && defined(__SIZEOF_POINTER__)) #if __SIZEOF_POINTER__ == 8 #define SECUREC_ON_64BITS #endif @@ -445,30 +433,31 @@ long __builtin_expect(long exp, long c); #endif /* - * Codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknow - * system on default, and strtold. The function strtold is referenced first at - * ISO9899:1999(C99), and some old compilers can not support these functions. - * Here provides a macro to open these functions: SECUREC_SUPPORT_STRTOLD -- If - * defined, strtold will be used + * Codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknow system on default, + * and strtold. + * The function strtold is referenced first at ISO9899:1999(C99), and some old compilers can + * not support these functions. Here provides a macro to open these functions: + * SECUREC_SUPPORT_STRTOLD -- If defined, strtold will be used */ #ifndef SECUREC_SUPPORT_STRTOLD #define SECUREC_SUPPORT_STRTOLD 0 #if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT)) -#if defined(__USE_ISOC99) || (defined(_AIX) && defined(_ISOC99_SOURCE)) || \ - (defined(__hpux) && defined(__ia64)) || \ - (defined(SECUREC_ON_SOLARIS) && \ - (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ - defined(_STDC_C99) || defined(__EXTENSIONS__)) -#undef SECUREC_SUPPORT_STRTOLD +#if defined(__USE_ISOC99) || \ + (defined(_AIX) && defined(_ISOC99_SOURCE)) || \ + (defined(__hpux) && defined(__ia64)) || \ + (defined(SECUREC_ON_SOLARIS) && (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ + defined(_STDC_C99) || defined(__EXTENSIONS__)) +#undef SECUREC_SUPPORT_STRTOLD #define SECUREC_SUPPORT_STRTOLD 1 #endif #endif #if ((defined(SECUREC_WRLINUX_BELOW4) || defined(_WRLINUX_BELOW4_))) -#undef SECUREC_SUPPORT_STRTOLD +#undef SECUREC_SUPPORT_STRTOLD #define SECUREC_SUPPORT_STRTOLD 0 #endif #endif + #if SECUREC_WITH_PERFORMANCE_ADDONS #ifndef SECUREC_TWO_MIN @@ -476,121 +465,102 @@ long __builtin_expect(long exp, long c); #endif /* For strncpy_s performance optimization */ -#define SECUREC_STRNCPY_SM(dest, destMax, src, count) \ - (((void *)(dest) != NULL && (void *)(src) != NULL && \ - (size_t)(destMax) > 0 && \ - (((unsigned long long)(destMax) & (unsigned long long)(-2)) < \ - SECUREC_STRING_MAX_LEN) && \ - (SECUREC_TWO_MIN((size_t)(count), strlen(src)) + 1) <= (size_t)(destMax)) \ - ? (((size_t)(count) < strlen(src)) \ - ? (memcpy((dest), (src), (count)), \ - *((char *)(dest) + (count)) = '\0', EOK) \ - : (memcpy((dest), (src), strlen(src) + 1), EOK)) \ - : (strncpy_error((dest), (destMax), (src), (count)))) +#define SECUREC_STRNCPY_SM(dest, destMax, src, count) \ + (((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ + (SECUREC_TWO_MIN((size_t)(count), strlen(src)) + 1) <= (size_t)(destMax)) ? \ + (((size_t)(count) < strlen(src)) ? (memcpy((dest), (src), (count)), *((char *)(dest) + (count)) = '\0', EOK) : \ + (memcpy((dest), (src), strlen(src) + 1), EOK)) : (strncpy_error((dest), (destMax), (src), (count)))) -#define SECUREC_STRCPY_SM(dest, destMax, src) \ - (((void *)(dest) != NULL && (void *)(src) != NULL && \ - (size_t)(destMax) > 0 && \ - (((unsigned long long)(destMax) & (unsigned long long)(-2)) < \ - SECUREC_STRING_MAX_LEN) && \ - (strlen(src) + 1) <= (size_t)(destMax)) \ - ? (memcpy((dest), (src), strlen(src) + 1), EOK) \ - : (strcpy_error((dest), (destMax), (src)))) +#define SECUREC_STRCPY_SM(dest, destMax, src) \ + (((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ + (strlen(src) + 1) <= (size_t)(destMax)) ? (memcpy((dest), (src), strlen(src) + 1), EOK) : \ + (strcpy_error((dest), (destMax), (src)))) /* For strcat_s performance optimization */ #if defined(__GNUC__) -#define SECUREC_STRCAT_SM(dest, destMax, src) \ - ({ \ - int catRet = EOK; \ - if ((void *)(dest) != NULL && (void *)(src) != NULL && \ - (size_t)(destMax) > 0 && \ - (((unsigned long long)(destMax) & (unsigned long long)(-2)) < \ - SECUREC_STRING_MAX_LEN)) { \ - char *catTmpDst = (char *)(dest); \ - size_t catRestSize = (destMax); \ - while (catRestSize > 0 && *catTmpDst != '\0') { \ - ++catTmpDst; \ - --catRestSize; \ - } \ - if (catRestSize == 0) { \ - catRet = EINVAL; \ - } else if ((strlen(src) + 1) <= catRestSize) { \ - memcpy(catTmpDst, (src), strlen(src) + 1); \ - catRet = EOK; \ - } else { \ - catRet = ERANGE; \ - } \ - if (catRet != EOK) { \ - catRet = strcat_s((dest), (destMax), (src)); \ - } \ - } else { \ - catRet = strcat_s((dest), (destMax), (src)); \ - } \ - catRet; \ - }) +#define SECUREC_STRCAT_SM(dest, destMax, src) ({ \ + int catRet = EOK; \ + if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \ + char *catTmpDst = (char *)(dest); \ + size_t catRestSize = (destMax); \ + while (catRestSize > 0 && *catTmpDst != '\0') { \ + ++catTmpDst; \ + --catRestSize; \ + } \ + if (catRestSize == 0) { \ + catRet = EINVAL; \ + } else if ((strlen(src) + 1) <= catRestSize) { \ + memcpy(catTmpDst, (src), strlen(src) + 1); \ + catRet = EOK; \ + } else { \ + catRet = ERANGE; \ + } \ + if (catRet != EOK) { \ + catRet = strcat_s((dest), (destMax), (src)); \ + } \ + } else { \ + catRet = strcat_s((dest), (destMax), (src)); \ + } \ + catRet; \ +}) #else #define SECUREC_STRCAT_SM(dest, destMax, src) strcat_s((dest), (destMax), (src)) #endif /* For strncat_s performance optimization */ #if defined(__GNUC__) -#define SECUREC_STRNCAT_SM(dest, destMax, src, count) \ - ({ \ - int ncatRet = EOK; \ - if ((void *)(dest) != NULL && (void *)(src) != NULL && \ - (size_t)(destMax) > 0 && \ - (((unsigned long long)(destMax) & (unsigned long long)(-2)) < \ - SECUREC_STRING_MAX_LEN) && \ - (((unsigned long long)(count) & (unsigned long long)(-2)) < \ - SECUREC_STRING_MAX_LEN)) { \ - char *ncatTmpDest = (char *)(dest); \ - size_t ncatRestSize = (size_t)(destMax); \ - while (ncatRestSize > 0 && *ncatTmpDest != '\0') { \ - ++ncatTmpDest; \ - --ncatRestSize; \ - } \ - if (ncatRestSize == 0) { \ - ncatRet = EINVAL; \ - } else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= \ - ncatRestSize) { \ - if ((size_t)(count) < strlen(src)) { \ - memcpy(ncatTmpDest, (src), (count)); \ - *(ncatTmpDest + (count)) = '\0'; \ - } else { \ - memcpy(ncatTmpDest, (src), strlen(src) + 1); \ - } \ - } else { \ - ncatRet = ERANGE; \ - } \ - if (ncatRet != EOK) { \ - ncatRet = strncat_s((dest), (destMax), (src), (count)); \ - } \ - } else { \ - ncatRet = strncat_s((dest), (destMax), (src), (count)); \ - } \ - ncatRet; \ - }) +#define SECUREC_STRNCAT_SM(dest, destMax, src, count) ({ \ + int ncatRet = EOK; \ + if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ + (((unsigned long long)(count) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \ + char *ncatTmpDest = (char *)(dest); \ + size_t ncatRestSize = (size_t)(destMax); \ + while (ncatRestSize > 0 && *ncatTmpDest != '\0') { \ + ++ncatTmpDest; \ + --ncatRestSize; \ + } \ + if (ncatRestSize == 0) { \ + ncatRet = EINVAL; \ + } else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= ncatRestSize) { \ + if ((size_t)(count) < strlen(src)) { \ + memcpy(ncatTmpDest, (src), (count)); \ + *(ncatTmpDest + (count)) = '\0'; \ + } else { \ + memcpy(ncatTmpDest, (src), strlen(src) + 1); \ + } \ + } else { \ + ncatRet = ERANGE; \ + } \ + if (ncatRet != EOK) { \ + ncatRet = strncat_s((dest), (destMax), (src), (count)); \ + } \ + } else { \ + ncatRet = strncat_s((dest), (destMax), (src), (count)); \ + } \ + ncatRet; \ +}) #else -#define SECUREC_STRNCAT_SM(dest, destMax, src, count) \ - strncat_s((dest), (destMax), (src), (count)) +#define SECUREC_STRNCAT_SM(dest, destMax, src, count) strncat_s((dest), (destMax), (src), (count)) #endif /* This macro do not check buffer overlap by default */ -#define SECUREC_MEMCPY_SM(dest, destMax, src, count) \ - (!(((size_t)(destMax) == 0) || \ - (((unsigned long long)(destMax) & (unsigned long long)(-2)) > \ - SECUREC_MEM_MAX_LEN) || \ - ((size_t)(count) > (size_t)(destMax)) || ((void *)(dest)) == NULL || \ - ((void *)(src) == NULL)) \ - ? (memcpy((dest), (src), (count)), EOK) \ - : (memcpy_s((dest), (destMax), (src), (count)))) +#define SECUREC_MEMCPY_SM(dest, destMax, src, count) \ + (!(((size_t)(destMax) == 0) || \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \ + ((size_t)(count) > (size_t)(destMax)) || ((void *)(dest)) == NULL || ((void *)(src) == NULL)) ? \ + (memcpy((dest), (src), (count)), EOK) : \ + (memcpy_s((dest), (destMax), (src), (count)))) -#define SECUREC_MEMSET_SM(dest, destMax, c, count) \ - (!((((unsigned long long)(destMax) & (unsigned long long)(-2)) > \ - SECUREC_MEM_MAX_LEN) || \ - ((void *)(dest) == NULL) || ((size_t)(count) > (size_t)(destMax))) \ - ? (memset((dest), (c), (count)), EOK) \ - : (memset_s((dest), (destMax), (c), (count)))) +#define SECUREC_MEMSET_SM(dest, destMax, c, count) \ + (!((((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \ + ((void *)(dest) == NULL) || ((size_t)(count) > (size_t)(destMax))) ? \ + (memset((dest), (c), (count)), EOK) : \ + (memset_s((dest), (destMax), (c), (count)))) #endif #endif /* __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7 */ + diff --git a/project/app/wifi_app/hisi_tools/securec/securecutil.c b/project/app/wifi_app/hisi_tools/securec/securecutil.c index 417a5d9a8..df8a08747 100644 --- a/project/app/wifi_app/hisi_tools/securec/securecutil.c +++ b/project/app/wifi_app/hisi_tools/securec/securecutil.c @@ -16,23 +16,27 @@ /* * Convert wide characters to narrow multi-bytes */ -int wctomb(char *s, wchar_t wc) { return wcrtomb(s, wc, NULL); } +int wctomb(char *s, wchar_t wc) +{ + return wcrtomb(s, wc, NULL); +} #endif #if SECUREC_HAVE_MBTOWC /* * Converting narrow multi-byte characters to wide characters */ -int mbtowc(wchar_t *pwc, const char *s, size_t n) { - return mbrtowc(pwc, s, n, NULL); +int mbtowc(wchar_t *pwc, const char *s, size_t n) +{ + return mbrtowc(pwc, s, n, NULL); } #endif #endif /* The V100R001C01 version num is 0x5 */ -#define SECUREC_C_VERSION (0x5 << 8) -#define SECUREC_SPC_VERSION 9 -#define SECUREC_VERSION_STR "Huawei Secure C V100R001C01SPC009B003" +#define SECUREC_C_VERSION (0x5 << 8) +#define SECUREC_SPC_VERSION 9 +#define SECUREC_VERSION_STR "Huawei Secure C V100R001C01SPC009B003" /* * SPC verNumber<->verStr like: @@ -51,12 +55,14 @@ int mbtowc(wchar_t *pwc, const char *s, size_t n) { * 0X602<->CP0002 * ... */ -const char *GetHwSecureCVersion(unsigned short *verNumber) { - if (verNumber != NULL) { - *verNumber = (unsigned short)(SECUREC_C_VERSION | SECUREC_SPC_VERSION); - } - return SECUREC_VERSION_STR; +const char *GetHwSecureCVersion(unsigned short *verNumber) +{ + if (verNumber != NULL) { + *verNumber = (unsigned short)(SECUREC_C_VERSION | SECUREC_SPC_VERSION); + } + return SECUREC_VERSION_STR; } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(GetHwSecureCVersion); #endif + diff --git a/project/app/wifi_app/hisi_tools/securec/securecutil.h b/project/app/wifi_app/hisi_tools/securec/securecutil.h index 239268663..01657138f 100644 --- a/project/app/wifi_app/hisi_tools/securec/securecutil.h +++ b/project/app/wifi_app/hisi_tools/securec/securecutil.h @@ -1,8 +1,9 @@ /* * Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved. - * Description: Define macro, data struct, and declare internal used function - * prototype, which is used by secure functions. Author: lishunda Create: - * 2014-02-25 + * Description: Define macro, data struct, and declare internal used function prototype, + * which is used by secure functions. + * Author: lishunda + * Create: 2014-02-25 */ #ifndef SECURECUTIL_H_46C86578_F8FF_4E49_8E64_9B175241761F @@ -10,28 +11,23 @@ #include "securec.h" #if (defined(_MSC_VER)) && (_MSC_VER >= 1400) -/* Shield compilation alerts using discarded functions and Constant expression - * to maximize code compatibility */ -#define SECUREC_MASK_MSVC_CRT_WARNING \ - __pragma(warning(push)) __pragma(warning(disable : 4996 4127)) -#define SECUREC_END_MASK_MSVC_CRT_WARNING __pragma(warning(pop)) +/* Shield compilation alerts using discarded functions and Constant expression to maximize code compatibility */ +#define SECUREC_MASK_MSVC_CRT_WARNING __pragma(warning(push)) \ + __pragma(warning(disable : 4996 4127)) +#define SECUREC_END_MASK_MSVC_CRT_WARNING __pragma(warning(pop)) #else #define SECUREC_MASK_MSVC_CRT_WARNING #define SECUREC_END_MASK_MSVC_CRT_WARNING #endif -#define SECUREC_WHILE_ZERO \ - SECUREC_MASK_MSVC_CRT_WARNING while (0) SECUREC_END_MASK_MSVC_CRT_WARNING +#define SECUREC_WHILE_ZERO SECUREC_MASK_MSVC_CRT_WARNING while (0) SECUREC_END_MASK_MSVC_CRT_WARNING -/* Automatically identify the platform that supports strnlen function, and use - * this function to improve performance */ +/* Automatically identify the platform that supports strnlen function, and use this function to improve performance */ #ifndef SECUREC_HAVE_STRNLEN -#if (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) || \ - (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L) +#if (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L) #if SECUREC_IN_KERNEL #define SECUREC_HAVE_STRNLEN 0 #else -#if defined(__GLIBC__) && __GLIBC__ >= 2 && defined(__GLIBC_MINOR__) && \ - __GLIBC_MINOR__ >= 10 +#if defined(__GLIBC__) && __GLIBC__ >= 2 && defined(__GLIBC_MINOR__) && __GLIBC_MINOR__ >= 10 #define SECUREC_HAVE_STRNLEN 1 #else #define SECUREC_HAVE_STRNLEN 0 @@ -109,135 +105,118 @@ #define SECUREC_STREAM_STDIN stdin #endif -#define SECUREC_INT_MAX 2147483647 -#define SECUREC_MUL_SIXTEEN(x) ((x) << 4) -#define SECUREC_MUL_EIGHT(x) ((x) << 3) -#define SECUREC_MUL_TEN(x) ((((x) << 2) + (x)) << 1) +#define SECUREC_INT_MAX 2147483647 +#define SECUREC_MUL_SIXTEEN(x) ((x) << 4) +#define SECUREC_MUL_EIGHT(x) ((x) << 3) +#define SECUREC_MUL_TEN(x) ((((x) << 2) + (x)) << 1) /* Limited format input and output width */ -#define SECUREC_MAX_WIDTH_LEN_DIV_TEN 21474836 -#define SECUREC_MAX_WIDTH_LEN SECUREC_MUL_TEN(SECUREC_MAX_WIDTH_LEN_DIV_TEN) +#define SECUREC_MAX_WIDTH_LEN_DIV_TEN 21474836 +#define SECUREC_MAX_WIDTH_LEN SECUREC_MUL_TEN(SECUREC_MAX_WIDTH_LEN_DIV_TEN) /* Is the x multiplied by 10 greater than */ -#define SECUREC_MUL_TEN_ADD_BEYOND_MAX(x) \ - (((x) > SECUREC_MAX_WIDTH_LEN_DIV_TEN)) +#define SECUREC_MUL_TEN_ADD_BEYOND_MAX(x) (((x) > SECUREC_MAX_WIDTH_LEN_DIV_TEN)) -#define SECUREC_FLOAT_BUFSIZE (309 + 40) /* Max length of double value */ -#define SECUREC_FLOAT_BUFSIZE_LB \ - (4932 + 40) /* Max length of long double value */ -#define SECUREC_FLOAT_DEFAULT_PRECISION 6 +#define SECUREC_FLOAT_BUFSIZE (309 + 40) /* Max length of double value */ +#define SECUREC_FLOAT_BUFSIZE_LB (4932 + 40) /* Max length of long double value */ +#define SECUREC_FLOAT_DEFAULT_PRECISION 6 /* This macro does not handle pointer equality or integer overflow */ -#define SECUREC_MEMORY_NO_OVERLAP(dest, src, count) \ - (((src) < (dest) && ((const char *)(src) + (count)) <= (char *)(dest)) || \ - ((dest) < (src) && ((char *)(dest) + (count)) <= (const char *)(src))) +#define SECUREC_MEMORY_NO_OVERLAP(dest, src, count) \ + (((src) < (dest) && ((const char *)(src) + (count)) <= (char *)(dest)) || \ + ((dest) < (src) && ((char *)(dest) + (count)) <= (const char *)(src))) -#define SECUREC_MEMORY_IS_OVERLAP(dest, src, count) \ - (((src) < (dest) && ((const char *)(src) + (count)) > (char *)(dest)) || \ - ((dest) < (src) && ((char *)(dest) + (count)) > (const char *)(src))) +#define SECUREC_MEMORY_IS_OVERLAP(dest, src, count) \ + (((src) < (dest) && ((const char *)(src) + (count)) > (char *)(dest)) || \ + ((dest) < (src) && ((char *)(dest) + (count)) > (const char *)(src))) /* - * Check whether the strings overlap, len is the length of the string not - * include terminator Length is related to data type char or wchar , do not - * force conversion of types + * Check whether the strings overlap, len is the length of the string not include terminator + * Length is related to data type char or wchar , do not force conversion of types */ -#define SECUREC_STRING_NO_OVERLAP(dest, src, len) \ - (((src) < (dest) && ((src) + (len)) < (dest)) || \ - ((dest) < (src) && ((dest) + (len)) < (src))) +#define SECUREC_STRING_NO_OVERLAP(dest, src, len) \ + (((src) < (dest) && ((src) + (len)) < (dest)) || \ + ((dest) < (src) && ((dest) + (len)) < (src))) /* - * Check whether the strings overlap for strcpy wcscpy function, dest len and - * src Len are not include terminator Length is related to data type char or - * wchar , do not force conversion of types + * Check whether the strings overlap for strcpy wcscpy function, dest len and src Len are not include terminator + * Length is related to data type char or wchar , do not force conversion of types */ -#define SECUREC_STRING_IS_OVERLAP(dest, src, len) \ - (((src) < (dest) && ((src) + (len)) >= (dest)) || \ - ((dest) < (src) && ((dest) + (len)) >= (src))) +#define SECUREC_STRING_IS_OVERLAP(dest, src, len) \ + (((src) < (dest) && ((src) + (len)) >= (dest)) || \ + ((dest) < (src) && ((dest) + (len)) >= (src))) /* - * Check whether the strings overlap for strcat wcscat function, dest len and - * src Len are not include terminator Length is related to data type char or - * wchar , do not force conversion of types + * Check whether the strings overlap for strcat wcscat function, dest len and src Len are not include terminator + * Length is related to data type char or wchar , do not force conversion of types */ -#define SECUREC_CAT_STRING_IS_OVERLAP(dest, destLen, src, srcLen) \ - (((dest) < (src) && ((dest) + (destLen) + (srcLen)) >= (src)) || \ - ((src) < (dest) && ((src) + (srcLen)) >= (dest))) +#define SECUREC_CAT_STRING_IS_OVERLAP(dest, destLen, src, srcLen) \ + (((dest) < (src) && ((dest) + (destLen) + (srcLen)) >= (src)) || \ + ((src) < (dest) && ((src) + (srcLen)) >= (dest))) + #if SECUREC_HAVE_STRNLEN -#define SECUREC_CALC_STR_LEN(str, maxLen, outLen) \ - do { \ - *(outLen) = strnlen((str), (maxLen)); \ - } \ - SECUREC_WHILE_ZERO -#define SECUREC_CALC_STR_LEN_OPT(str, maxLen, outLen) \ - do { \ - if ((maxLen) > 8) { \ - /* Optimization or len less then 8 */ \ - if (*((str) + 0) == '\0') { \ - *(outLen) = 0; \ - } else if (*((str) + 1) == '\0') { \ - *(outLen) = 1; \ - } else if (*((str) + 2) == '\0') { \ - *(outLen) = 2; \ - } else if (*((str) + 3) == '\0') { \ - *(outLen) = 3; \ - } else if (*((str) + 4) == '\0') { \ - *(outLen) = 4; \ - } else if (*((str) + 5) == '\0') { \ - *(outLen) = 5; \ - } else if (*((str) + 6) == '\0') { \ - *(outLen) = 6; \ - } else if (*((str) + 7) == '\0') { \ - *(outLen) = 7; \ - } else if (*((str) + 8) == '\0') { \ - /* Optimization with a length of 8 */ \ - *(outLen) = 8; \ - } else { \ - /* The offset is 8 because the performance of 8 byte alignment is high \ - */ \ - *(outLen) = 8 + strnlen((str) + 8, (maxLen)-8); \ - } \ - } else { \ - SECUREC_CALC_STR_LEN((str), (maxLen), (outLen)); \ - } \ - } \ - SECUREC_WHILE_ZERO +#define SECUREC_CALC_STR_LEN(str, maxLen, outLen) do { \ + *(outLen) = strnlen((str), (maxLen)); \ +} SECUREC_WHILE_ZERO +#define SECUREC_CALC_STR_LEN_OPT(str, maxLen, outLen) do { \ + if ((maxLen) > 8) { \ + /* Optimization or len less then 8 */ \ + if (*((str) + 0) == '\0') { \ + *(outLen) = 0; \ + } else if (*((str) + 1) == '\0') { \ + *(outLen) = 1; \ + } else if (*((str) + 2) == '\0') { \ + *(outLen) = 2; \ + } else if (*((str) + 3) == '\0') { \ + *(outLen) = 3; \ + } else if (*((str) + 4) == '\0') { \ + *(outLen) = 4; \ + } else if (*((str) + 5) == '\0') { \ + *(outLen) = 5; \ + } else if (*((str) + 6) == '\0') { \ + *(outLen) = 6; \ + } else if (*((str) + 7) == '\0') { \ + *(outLen) = 7; \ + } else if (*((str) + 8) == '\0') { \ + /* Optimization with a length of 8 */ \ + *(outLen) = 8; \ + } else { \ + /* The offset is 8 because the performance of 8 byte alignment is high */ \ + *(outLen) = 8 + strnlen((str) + 8, (maxLen) - 8); \ + } \ + } else { \ + SECUREC_CALC_STR_LEN((str), (maxLen), (outLen)); \ + } \ +} SECUREC_WHILE_ZERO #else -#define SECUREC_CALC_STR_LEN(str, maxLen, outLen) \ - do { \ - const char *strEnd = (const char *)(str); \ - size_t availableSize = (size_t)(maxLen); \ - while (availableSize > 0 && *strEnd != '\0') { \ - --availableSize; \ - ++strEnd; \ - } \ - *(outLen) = (size_t)(strEnd - (str)); \ - } \ - SECUREC_WHILE_ZERO +#define SECUREC_CALC_STR_LEN(str, maxLen, outLen) do { \ + const char *strEnd = (const char *)(str); \ + size_t availableSize = (size_t)(maxLen); \ + while (availableSize > 0 && *strEnd != '\0') { \ + --availableSize; \ + ++strEnd; \ + } \ + *(outLen) = (size_t)(strEnd - (str)); \ +} SECUREC_WHILE_ZERO #define SECUREC_CALC_STR_LEN_OPT SECUREC_CALC_STR_LEN #endif -#define SECUREC_CALC_WSTR_LEN(str, maxLen, outLen) \ - do { \ - const wchar_t *strEnd = (const wchar_t *)(str); \ - size_t len = 0; \ - while (len < (maxLen) && *strEnd != L'\0') { \ - ++len; \ - ++strEnd; \ - } \ - *(outLen) = len; \ - } \ - SECUREC_WHILE_ZERO +#define SECUREC_CALC_WSTR_LEN(str, maxLen, outLen) do { \ + const wchar_t *strEnd = (const wchar_t *)(str); \ + size_t len = 0; \ + while (len < (maxLen) && *strEnd != L'\0') { \ + ++len; \ + ++strEnd; \ + } \ + *(outLen) = len; \ +} SECUREC_WHILE_ZERO /* Performance optimization, product may disable inline function */ #ifdef SECUREC_USE_ASM -#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) \ - (void)memcpy_opt((dest), (src), (count)) -#define SECUREC_MEMSET_WARP_OPT(dest, c, count) \ - (void)memset_opt((dest), (c), (count)) +#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) (void)memcpy_opt((dest), (src), (count)) +#define SECUREC_MEMSET_WARP_OPT(dest, c, count) (void)memset_opt((dest), (c), (count)) #else -#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) \ - (void)memcpy((dest), (src), (count)) -#define SECUREC_MEMSET_WARP_OPT(dest, c, count) \ - (void)memset((dest), (c), (count)) +#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) (void)memcpy((dest), (src), (count)) +#define SECUREC_MEMSET_WARP_OPT(dest, c, count) (void)memset((dest), (c), (count)) #endif #ifdef SECUREC_FORMAT_OUTPUT_INPUT @@ -278,12 +257,11 @@ typedef unsigned int SecUnsignedInt; * Determine whether the address is 8-byte aligned * Some systems do not have uintptr_t type, so use NULL to clear tool alarm 507 */ -#define SECUREC_ADDR_ALIGNED_8(addr) \ - ((((size_t)(addr)) & 7) == 0) /* Use 7 to check aligned 8 */ +#define SECUREC_ADDR_ALIGNED_8(addr) ((((size_t)(addr)) & 7) == 0) /* Use 7 to check aligned 8 */ /* - * If you define the memory allocation function, you need to define the function - * prototype. You can define this macro as a header file. + * If you define the memory allocation function, you need to define the function prototype. + * You can define this macro as a header file. */ #if defined(SECUREC_MALLOC_PROTOTYPE) SECUREC_MALLOC_PROTOTYPE @@ -294,265 +272,201 @@ SECUREC_MALLOC_PROTOTYPE #endif #ifndef SECUREC_FREE -#define SECUREC_FREE(x) free((void *)(x)) +#define SECUREC_FREE(x) free((void *)(x)) #endif /* Struct for performance */ typedef struct { - unsigned char buf[1]; /* Performance optimization code structure assignment - length 1 bytes */ + unsigned char buf[1]; /* Performance optimization code structure assignment length 1 bytes */ } SecStrBuf1; typedef struct { - unsigned char buf[2]; /* Performance optimization code structure assignment - length 2 bytes */ + unsigned char buf[2]; /* Performance optimization code structure assignment length 2 bytes */ } SecStrBuf2; typedef struct { - unsigned char buf[3]; /* Performance optimization code structure assignment - length 3 bytes */ + unsigned char buf[3]; /* Performance optimization code structure assignment length 3 bytes */ } SecStrBuf3; typedef struct { - unsigned char buf[4]; /* Performance optimization code structure assignment - length 4 bytes */ + unsigned char buf[4]; /* Performance optimization code structure assignment length 4 bytes */ } SecStrBuf4; typedef struct { - unsigned char buf[5]; /* Performance optimization code structure assignment - length 5 bytes */ + unsigned char buf[5]; /* Performance optimization code structure assignment length 5 bytes */ } SecStrBuf5; typedef struct { - unsigned char buf[6]; /* Performance optimization code structure assignment - length 6 bytes */ + unsigned char buf[6]; /* Performance optimization code structure assignment length 6 bytes */ } SecStrBuf6; typedef struct { - unsigned char buf[7]; /* Performance optimization code structure assignment - length 7 bytes */ + unsigned char buf[7]; /* Performance optimization code structure assignment length 7 bytes */ } SecStrBuf7; typedef struct { - unsigned char buf[8]; /* Performance optimization code structure assignment - length 8 bytes */ + unsigned char buf[8]; /* Performance optimization code structure assignment length 8 bytes */ } SecStrBuf8; typedef struct { - unsigned char buf[9]; /* Performance optimization code structure assignment - length 9 bytes */ + unsigned char buf[9]; /* Performance optimization code structure assignment length 9 bytes */ } SecStrBuf9; typedef struct { - unsigned char buf[10]; /* Performance optimization code structure assignment - length 10 bytes */ + unsigned char buf[10]; /* Performance optimization code structure assignment length 10 bytes */ } SecStrBuf10; typedef struct { - unsigned char buf[11]; /* Performance optimization code structure assignment - length 11 bytes */ + unsigned char buf[11]; /* Performance optimization code structure assignment length 11 bytes */ } SecStrBuf11; typedef struct { - unsigned char buf[12]; /* Performance optimization code structure assignment - length 12 bytes */ + unsigned char buf[12]; /* Performance optimization code structure assignment length 12 bytes */ } SecStrBuf12; typedef struct { - unsigned char buf[13]; /* Performance optimization code structure assignment - length 13 bytes */ + unsigned char buf[13]; /* Performance optimization code structure assignment length 13 bytes */ } SecStrBuf13; typedef struct { - unsigned char buf[14]; /* Performance optimization code structure assignment - length 14 bytes */ + unsigned char buf[14]; /* Performance optimization code structure assignment length 14 bytes */ } SecStrBuf14; typedef struct { - unsigned char buf[15]; /* Performance optimization code structure assignment - length 15 bytes */ + unsigned char buf[15]; /* Performance optimization code structure assignment length 15 bytes */ } SecStrBuf15; typedef struct { - unsigned char buf[16]; /* Performance optimization code structure assignment - length 16 bytes */ + unsigned char buf[16]; /* Performance optimization code structure assignment length 16 bytes */ } SecStrBuf16; typedef struct { - unsigned char buf[17]; /* Performance optimization code structure assignment - length 17 bytes */ + unsigned char buf[17]; /* Performance optimization code structure assignment length 17 bytes */ } SecStrBuf17; typedef struct { - unsigned char buf[18]; /* Performance optimization code structure assignment - length 18 bytes */ + unsigned char buf[18]; /* Performance optimization code structure assignment length 18 bytes */ } SecStrBuf18; typedef struct { - unsigned char buf[19]; /* Performance optimization code structure assignment - length 19 bytes */ + unsigned char buf[19]; /* Performance optimization code structure assignment length 19 bytes */ } SecStrBuf19; typedef struct { - unsigned char buf[20]; /* Performance optimization code structure assignment - length 20 bytes */ + unsigned char buf[20]; /* Performance optimization code structure assignment length 20 bytes */ } SecStrBuf20; typedef struct { - unsigned char buf[21]; /* Performance optimization code structure assignment - length 21 bytes */ + unsigned char buf[21]; /* Performance optimization code structure assignment length 21 bytes */ } SecStrBuf21; typedef struct { - unsigned char buf[22]; /* Performance optimization code structure assignment - length 22 bytes */ + unsigned char buf[22]; /* Performance optimization code structure assignment length 22 bytes */ } SecStrBuf22; typedef struct { - unsigned char buf[23]; /* Performance optimization code structure assignment - length 23 bytes */ + unsigned char buf[23]; /* Performance optimization code structure assignment length 23 bytes */ } SecStrBuf23; typedef struct { - unsigned char buf[24]; /* Performance optimization code structure assignment - length 24 bytes */ + unsigned char buf[24]; /* Performance optimization code structure assignment length 24 bytes */ } SecStrBuf24; typedef struct { - unsigned char buf[25]; /* Performance optimization code structure assignment - length 25 bytes */ + unsigned char buf[25]; /* Performance optimization code structure assignment length 25 bytes */ } SecStrBuf25; typedef struct { - unsigned char buf[26]; /* Performance optimization code structure assignment - length 26 bytes */ + unsigned char buf[26]; /* Performance optimization code structure assignment length 26 bytes */ } SecStrBuf26; typedef struct { - unsigned char buf[27]; /* Performance optimization code structure assignment - length 27 bytes */ + unsigned char buf[27]; /* Performance optimization code structure assignment length 27 bytes */ } SecStrBuf27; typedef struct { - unsigned char buf[28]; /* Performance optimization code structure assignment - length 28 bytes */ + unsigned char buf[28]; /* Performance optimization code structure assignment length 28 bytes */ } SecStrBuf28; typedef struct { - unsigned char buf[29]; /* Performance optimization code structure assignment - length 29 bytes */ + unsigned char buf[29]; /* Performance optimization code structure assignment length 29 bytes */ } SecStrBuf29; typedef struct { - unsigned char buf[30]; /* Performance optimization code structure assignment - length 30 bytes */ + unsigned char buf[30]; /* Performance optimization code structure assignment length 30 bytes */ } SecStrBuf30; typedef struct { - unsigned char buf[31]; /* Performance optimization code structure assignment - length 31 bytes */ + unsigned char buf[31]; /* Performance optimization code structure assignment length 31 bytes */ } SecStrBuf31; typedef struct { - unsigned char buf[32]; /* Performance optimization code structure assignment - length 32 bytes */ + unsigned char buf[32]; /* Performance optimization code structure assignment length 32 bytes */ } SecStrBuf32; typedef struct { - unsigned char buf[33]; /* Performance optimization code structure assignment - length 33 bytes */ + unsigned char buf[33]; /* Performance optimization code structure assignment length 33 bytes */ } SecStrBuf33; typedef struct { - unsigned char buf[34]; /* Performance optimization code structure assignment - length 34 bytes */ + unsigned char buf[34]; /* Performance optimization code structure assignment length 34 bytes */ } SecStrBuf34; typedef struct { - unsigned char buf[35]; /* Performance optimization code structure assignment - length 35 bytes */ + unsigned char buf[35]; /* Performance optimization code structure assignment length 35 bytes */ } SecStrBuf35; typedef struct { - unsigned char buf[36]; /* Performance optimization code structure assignment - length 36 bytes */ + unsigned char buf[36]; /* Performance optimization code structure assignment length 36 bytes */ } SecStrBuf36; typedef struct { - unsigned char buf[37]; /* Performance optimization code structure assignment - length 37 bytes */ + unsigned char buf[37]; /* Performance optimization code structure assignment length 37 bytes */ } SecStrBuf37; typedef struct { - unsigned char buf[38]; /* Performance optimization code structure assignment - length 38 bytes */ + unsigned char buf[38]; /* Performance optimization code structure assignment length 38 bytes */ } SecStrBuf38; typedef struct { - unsigned char buf[39]; /* Performance optimization code structure assignment - length 39 bytes */ + unsigned char buf[39]; /* Performance optimization code structure assignment length 39 bytes */ } SecStrBuf39; typedef struct { - unsigned char buf[40]; /* Performance optimization code structure assignment - length 40 bytes */ + unsigned char buf[40]; /* Performance optimization code structure assignment length 40 bytes */ } SecStrBuf40; typedef struct { - unsigned char buf[41]; /* Performance optimization code structure assignment - length 41 bytes */ + unsigned char buf[41]; /* Performance optimization code structure assignment length 41 bytes */ } SecStrBuf41; typedef struct { - unsigned char buf[42]; /* Performance optimization code structure assignment - length 42 bytes */ + unsigned char buf[42]; /* Performance optimization code structure assignment length 42 bytes */ } SecStrBuf42; typedef struct { - unsigned char buf[43]; /* Performance optimization code structure assignment - length 43 bytes */ + unsigned char buf[43]; /* Performance optimization code structure assignment length 43 bytes */ } SecStrBuf43; typedef struct { - unsigned char buf[44]; /* Performance optimization code structure assignment - length 44 bytes */ + unsigned char buf[44]; /* Performance optimization code structure assignment length 44 bytes */ } SecStrBuf44; typedef struct { - unsigned char buf[45]; /* Performance optimization code structure assignment - length 45 bytes */ + unsigned char buf[45]; /* Performance optimization code structure assignment length 45 bytes */ } SecStrBuf45; typedef struct { - unsigned char buf[46]; /* Performance optimization code structure assignment - length 46 bytes */ + unsigned char buf[46]; /* Performance optimization code structure assignment length 46 bytes */ } SecStrBuf46; typedef struct { - unsigned char buf[47]; /* Performance optimization code structure assignment - length 47 bytes */ + unsigned char buf[47]; /* Performance optimization code structure assignment length 47 bytes */ } SecStrBuf47; typedef struct { - unsigned char buf[48]; /* Performance optimization code structure assignment - length 48 bytes */ + unsigned char buf[48]; /* Performance optimization code structure assignment length 48 bytes */ } SecStrBuf48; typedef struct { - unsigned char buf[49]; /* Performance optimization code structure assignment - length 49 bytes */ + unsigned char buf[49]; /* Performance optimization code structure assignment length 49 bytes */ } SecStrBuf49; typedef struct { - unsigned char buf[50]; /* Performance optimization code structure assignment - length 50 bytes */ + unsigned char buf[50]; /* Performance optimization code structure assignment length 50 bytes */ } SecStrBuf50; typedef struct { - unsigned char buf[51]; /* Performance optimization code structure assignment - length 51 bytes */ + unsigned char buf[51]; /* Performance optimization code structure assignment length 51 bytes */ } SecStrBuf51; typedef struct { - unsigned char buf[52]; /* Performance optimization code structure assignment - length 52 bytes */ + unsigned char buf[52]; /* Performance optimization code structure assignment length 52 bytes */ } SecStrBuf52; typedef struct { - unsigned char buf[53]; /* Performance optimization code structure assignment - length 53 bytes */ + unsigned char buf[53]; /* Performance optimization code structure assignment length 53 bytes */ } SecStrBuf53; typedef struct { - unsigned char buf[54]; /* Performance optimization code structure assignment - length 54 bytes */ + unsigned char buf[54]; /* Performance optimization code structure assignment length 54 bytes */ } SecStrBuf54; typedef struct { - unsigned char buf[55]; /* Performance optimization code structure assignment - length 55 bytes */ + unsigned char buf[55]; /* Performance optimization code structure assignment length 55 bytes */ } SecStrBuf55; typedef struct { - unsigned char buf[56]; /* Performance optimization code structure assignment - length 56 bytes */ + unsigned char buf[56]; /* Performance optimization code structure assignment length 56 bytes */ } SecStrBuf56; typedef struct { - unsigned char buf[57]; /* Performance optimization code structure assignment - length 57 bytes */ + unsigned char buf[57]; /* Performance optimization code structure assignment length 57 bytes */ } SecStrBuf57; typedef struct { - unsigned char buf[58]; /* Performance optimization code structure assignment - length 58 bytes */ + unsigned char buf[58]; /* Performance optimization code structure assignment length 58 bytes */ } SecStrBuf58; typedef struct { - unsigned char buf[59]; /* Performance optimization code structure assignment - length 59 bytes */ + unsigned char buf[59]; /* Performance optimization code structure assignment length 59 bytes */ } SecStrBuf59; typedef struct { - unsigned char buf[60]; /* Performance optimization code structure assignment - length 60 bytes */ + unsigned char buf[60]; /* Performance optimization code structure assignment length 60 bytes */ } SecStrBuf60; typedef struct { - unsigned char buf[61]; /* Performance optimization code structure assignment - length 61 bytes */ + unsigned char buf[61]; /* Performance optimization code structure assignment length 61 bytes */ } SecStrBuf61; typedef struct { - unsigned char buf[62]; /* Performance optimization code structure assignment - length 62 bytes */ + unsigned char buf[62]; /* Performance optimization code structure assignment length 62 bytes */ } SecStrBuf62; typedef struct { - unsigned char buf[63]; /* Performance optimization code structure assignment - length 63 bytes */ + unsigned char buf[63]; /* Performance optimization code structure assignment length 63 bytes */ } SecStrBuf63; typedef struct { - unsigned char buf[64]; /* Performance optimization code structure assignment - length 64 bytes */ + unsigned char buf[64]; /* Performance optimization code structure assignment length 64 bytes */ } SecStrBuf64; /* @@ -561,29 +475,23 @@ typedef struct { */ #if defined(_DEBUG) || defined(DEBUG) #if defined(SECUREC_ERROR_HANDLER_BY_ASSERT) -#define SECUREC_ERROR_INVALID_PARAMTER(msg) \ - assert(msg "invalid argument" == NULL) -#define SECUREC_ERROR_INVALID_RANGE(msg) \ - assert(msg "invalid dest buffer size" == NULL) -#define SECUREC_ERROR_BUFFER_OVERLAP(msg) assert(msg "buffer overlap" == NULL) +#define SECUREC_ERROR_INVALID_PARAMTER(msg) assert(msg "invalid argument" == NULL) +#define SECUREC_ERROR_INVALID_RANGE(msg) assert(msg "invalid dest buffer size" == NULL) +#define SECUREC_ERROR_BUFFER_OVERLAP(msg) assert(msg "buffer overlap" == NULL) #elif defined(SECUREC_ERROR_HANDLER_BY_PRINTF) #if SECUREC_IN_KERNEL #define SECUREC_ERROR_INVALID_PARAMTER(msg) printk("%s invalid argument\n", msg) -#define SECUREC_ERROR_INVALID_RANGE(msg) \ - printk("%s invalid dest buffer size\n", msg) -#define SECUREC_ERROR_BUFFER_OVERLAP(msg) printk("%s buffer overlap\n", msg) +#define SECUREC_ERROR_INVALID_RANGE(msg) printk("%s invalid dest buffer size\n", msg) +#define SECUREC_ERROR_BUFFER_OVERLAP(msg) printk("%s buffer overlap\n", msg) #else #define SECUREC_ERROR_INVALID_PARAMTER(msg) printf("%s invalid argument\n", msg) -#define SECUREC_ERROR_INVALID_RANGE(msg) \ - printf("%s invalid dest buffer size\n", msg) -#define SECUREC_ERROR_BUFFER_OVERLAP(msg) printf("%s buffer overlap\n", msg) +#define SECUREC_ERROR_INVALID_RANGE(msg) printf("%s invalid dest buffer size\n", msg) +#define SECUREC_ERROR_BUFFER_OVERLAP(msg) printf("%s buffer overlap\n", msg) #endif #elif defined(SECUREC_ERROR_HANDLER_BY_FILE_LOG) -#define SECUREC_ERROR_INVALID_PARAMTER(msg) \ - LogSecureCRuntimeError(msg " EINVAL\n") -#define SECUREC_ERROR_INVALID_RANGE(msg) LogSecureCRuntimeError(msg " ERANGE\n") -#define SECUREC_ERROR_BUFFER_OVERLAP(msg) \ - LogSecureCRuntimeError(msg " EOVERLAP\n") +#define SECUREC_ERROR_INVALID_PARAMTER(msg) LogSecureCRuntimeError(msg " EINVAL\n") +#define SECUREC_ERROR_INVALID_RANGE(msg) LogSecureCRuntimeError(msg " ERANGE\n") +#define SECUREC_ERROR_BUFFER_OVERLAP(msg) LogSecureCRuntimeError(msg " EOVERLAP\n") #endif #endif @@ -592,10 +500,10 @@ typedef struct { #define SECUREC_ERROR_INVALID_PARAMTER(msg) ((void)0) #endif #ifndef SECUREC_ERROR_INVALID_RANGE -#define SECUREC_ERROR_INVALID_RANGE(msg) ((void)0) +#define SECUREC_ERROR_INVALID_RANGE(msg) ((void)0) #endif #ifndef SECUREC_ERROR_BUFFER_OVERLAP -#define SECUREC_ERROR_BUFFER_OVERLAP(msg) ((void)0) +#define SECUREC_ERROR_BUFFER_OVERLAP(msg) ((void)0) #endif #ifdef __cplusplus @@ -604,15 +512,16 @@ extern "C" { /* Assembly language memory copy and memory set for X86 or MIPS ... */ #ifdef SECUREC_USE_ASM -extern void *memcpy_opt(void *, const void *, size_t); -extern void *memset_opt(void *, int, size_t); + extern void *memcpy_opt(void *, const void *, size_t); + extern void *memset_opt(void *, int, size_t); #endif #if defined(SECUREC_ERROR_HANDLER_BY_FILE_LOG) -extern void LogSecureCRuntimeError(const char *errDetail); + extern void LogSecureCRuntimeError(const char *errDetail); #endif #ifdef __cplusplus } #endif /* __cplusplus */ #endif + diff --git a/project/app/wifi_app/hisi_tools/securec/secureinput_a.c b/project/app/wifi_app/hisi_tools/securec/secureinput_a.c index adffb5efd..b8cf40ff2 100644 --- a/project/app/wifi_app/hisi_tools/securec/secureinput_a.c +++ b/project/app/wifi_app/hisi_tools/securec/secureinput_a.c @@ -1,8 +1,9 @@ /* * Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved. * Description: By defining data type for ANSI string and including "input.inl", - * this file generates real underlying function used by scanf - * family API. Author: lishunda Create: 2014-02-25 + * this file generates real underlying function used by scanf family API. + * Author: lishunda + * Create: 2014-02-25 */ #define SECUREC_FORMAT_OUTPUT_INPUT 1 #ifdef SECUREC_FOR_WCHAR @@ -13,13 +14,17 @@ #include "input.inl" -SECUREC_INLINE int SecIsDigit(SecInt ch) { - /* SecInt to unsigned char clear 571 */ - return isdigit((unsigned char)(ch)&0x00ff); +SECUREC_INLINE int SecIsDigit(SecInt ch) +{ + /* SecInt to unsigned char clear 571 */ + return isdigit((unsigned char)(ch) & 0x00ff); } -SECUREC_INLINE int SecIsXdigit(SecInt ch) { - return isxdigit((unsigned char)(ch)&0x00ff); +SECUREC_INLINE int SecIsXdigit(SecInt ch) +{ + return isxdigit((unsigned char)(ch) & 0x00ff); } -SECUREC_INLINE int SecIsSpace(SecInt ch) { - return isspace((unsigned char)(ch)&0x00ff); +SECUREC_INLINE int SecIsSpace(SecInt ch) +{ + return isspace((unsigned char)(ch) & 0x00ff); } + diff --git a/project/app/wifi_app/hisi_tools/securec/secureinput_w.c b/project/app/wifi_app/hisi_tools/securec/secureinput_w.c index 6d7f8ac0a..2a98b30ec 100644 --- a/project/app/wifi_app/hisi_tools/securec/secureinput_w.c +++ b/project/app/wifi_app/hisi_tools/securec/secureinput_w.c @@ -1,8 +1,9 @@ /* * Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved. - * Description: By defining data type for UNICODE string and including - * "input.inl", this file generates real underlying function used by scanf - * family API. Author: lishunda Create: 2014-02-25 + * Description: By defining data type for UNICODE string and including "input.inl", + * this file generates real underlying function used by scanf family API. + * Author: lishunda + * Create: 2014-02-25 */ /* If some platforms don't have wchar.h, dont't include it */ @@ -14,15 +15,15 @@ #define __STDC_WANT_SECURE_LIB__ 0 #endif #ifndef _CRTIMP_ALTERNATIVE -#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */ +#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */ #endif #endif #include #endif /* Disable wchar func to clear vs warning */ -#define SECUREC_ENABLE_WCHAR_FUNC 0 -#define SECUREC_FORMAT_OUTPUT_INPUT 1 +#define SECUREC_ENABLE_WCHAR_FUNC 0 +#define SECUREC_FORMAT_OUTPUT_INPUT 1 #ifndef SECUREC_FOR_WCHAR #define SECUREC_FOR_WCHAR @@ -32,13 +33,19 @@ #include "input.inl" -SECUREC_INLINE int SecIsDigit(SecInt ch) { - /* Convert int to unsigned int clear 571 */ - return (!((unsigned int)(int)(ch)&0xff00) && - isdigit(((unsigned int)(int)(ch)&0x00ff))); +SECUREC_INLINE int SecIsDigit(SecInt ch) +{ + /* Convert int to unsigned int clear 571 */ + return (!((unsigned int)(int)(ch) & 0xff00) && isdigit(((unsigned int)(int)(ch) & 0x00ff))); } -SECUREC_INLINE int SecIsXdigit(SecInt ch) { - return (!((unsigned int)(int)(ch)&0xff00) && - isxdigit(((unsigned int)(int)(ch)&0x00ff))); +SECUREC_INLINE int SecIsXdigit(SecInt ch) +{ + return (!((unsigned int)(int)(ch) & 0xff00) && isxdigit(((unsigned int)(int)(ch) & 0x00ff))); } -SECUREC_INLINE int SecIsSpace(SecInt ch) { return iswspace((wint_t)(int)(ch)); } +SECUREC_INLINE int SecIsSpace(SecInt ch) +{ + return iswspace((wint_t)(int)(ch)); +} + + + diff --git a/project/app/wifi_app/hisi_tools/securec/secureprintoutput.h b/project/app/wifi_app/hisi_tools/securec/secureprintoutput.h index 94056df85..76e6bdd73 100644 --- a/project/app/wifi_app/hisi_tools/securec/secureprintoutput.h +++ b/project/app/wifi_app/hisi_tools/securec/secureprintoutput.h @@ -1,7 +1,7 @@ /* * Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved. - * Description: Define macro, enum, data struct, and declare internal used - * function prototype, which is used by output.inl, secureprintoutput_w.c and + * Description: Define macro, enum, data struct, and declare internal used function + * prototype, which is used by output.inl, secureprintoutput_w.c and * secureprintoutput_a.c. * Author: lishunda * Create: 2014-02-25 @@ -13,115 +13,108 @@ /* * Flag definitions. - * Using macros instead of enumerations is because some of the enumerated types - * under the compiler are 16bit. + * Using macros instead of enumerations is because some of the enumerated types under the compiler are 16bit. */ -#define SECUREC_FLAG_SIGN 0x00001U -#define SECUREC_FLAG_SIGN_SPACE 0x00002U -#define SECUREC_FLAG_LEFT 0x00004U -#define SECUREC_FLAG_LEADZERO 0x00008U -#define SECUREC_FLAG_LONG 0x00010U -#define SECUREC_FLAG_SHORT 0x00020U -#define SECUREC_FLAG_SIGNED 0x00040U -#define SECUREC_FLAG_ALTERNATE 0x00080U -#define SECUREC_FLAG_NEGATIVE 0x00100U -#define SECUREC_FLAG_FORCE_OCTAL 0x00200U -#define SECUREC_FLAG_LONG_DOUBLE 0x00400U -#define SECUREC_FLAG_WIDECHAR 0x00800U -#define SECUREC_FLAG_LONGLONG 0x01000U -#define SECUREC_FLAG_CHAR 0x02000U -#define SECUREC_FLAG_POINTER 0x04000U -#define SECUREC_FLAG_I64 0x08000U -#define SECUREC_FLAG_PTRDIFF 0x10000U -#define SECUREC_FLAG_SIZE 0x20000U -#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT -#define SECUREC_FLAG_INTMAX 0x40000U +#define SECUREC_FLAG_SIGN 0x00001U +#define SECUREC_FLAG_SIGN_SPACE 0x00002U +#define SECUREC_FLAG_LEFT 0x00004U +#define SECUREC_FLAG_LEADZERO 0x00008U +#define SECUREC_FLAG_LONG 0x00010U +#define SECUREC_FLAG_SHORT 0x00020U +#define SECUREC_FLAG_SIGNED 0x00040U +#define SECUREC_FLAG_ALTERNATE 0x00080U +#define SECUREC_FLAG_NEGATIVE 0x00100U +#define SECUREC_FLAG_FORCE_OCTAL 0x00200U +#define SECUREC_FLAG_LONG_DOUBLE 0x00400U +#define SECUREC_FLAG_WIDECHAR 0x00800U +#define SECUREC_FLAG_LONGLONG 0x01000U +#define SECUREC_FLAG_CHAR 0x02000U +#define SECUREC_FLAG_POINTER 0x04000U +#define SECUREC_FLAG_I64 0x08000U +#define SECUREC_FLAG_PTRDIFF 0x10000U +#define SECUREC_FLAG_SIZE 0x20000U +#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT +#define SECUREC_FLAG_INTMAX 0x40000U #endif /* State definitions. Identify the status of the current format */ typedef enum { - STAT_NORMAL, - STAT_PERCENT, - STAT_FLAG, - STAT_WIDTH, - STAT_DOT, - STAT_PRECIS, - STAT_SIZE, - STAT_TYPE, - STAT_INVALID + STAT_NORMAL, + STAT_PERCENT, + STAT_FLAG, + STAT_WIDTH, + STAT_DOT, + STAT_PRECIS, + STAT_SIZE, + STAT_TYPE, + STAT_INVALID } SecFmtState; /* Format output buffer pointer and available size */ typedef struct { - int count; - char *cur; + int count; + char *cur; } SecPrintfStream; + #ifndef SECUREC_BUFFER_SIZE #if SECUREC_IN_KERNEL -#define SECUREC_BUFFER_SIZE 32 +#define SECUREC_BUFFER_SIZE 32 #elif defined(SECUREC_STACK_SIZE_LESS_THAN_1K) /* * SECUREC BUFFER SIZE Can not be less than 23 * The length of the octal representation of 64-bit integers with zero lead */ -#define SECUREC_BUFFER_SIZE 256 +#define SECUREC_BUFFER_SIZE 256 #else -#define SECUREC_BUFFER_SIZE 512 +#define SECUREC_BUFFER_SIZE 512 #endif #endif #if SECUREC_BUFFER_SIZE < 23 #error SECUREC_BUFFER_SIZE Can not be less than 23 #endif -/* Buffer size for wchar, use 4 to make the compiler aligns as 8 bytes as - * possible */ +/* Buffer size for wchar, use 4 to make the compiler aligns as 8 bytes as possible */ #define SECUREC_WCHAR_BUFFER_SIZE 4 -#define SECUREC_MAX_PRECISION SECUREC_BUFFER_SIZE + +#define SECUREC_MAX_PRECISION SECUREC_BUFFER_SIZE /* Max. # bytes in multibyte char ,see MB_LEN_MAX */ #define SECUREC_MB_LEN 16 -/* The return value of the internal function, which is returned when truncated - */ +/* The return value of the internal function, which is returned when truncated */ #define SECUREC_PRINTF_TRUNCATE (-2) -#define SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, maxLimit) \ - ((format) == NULL || (strDest) == NULL || (destMax) == 0 || \ - (destMax) > (maxLimit)) +#define SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, maxLimit) \ + ((format) == NULL || (strDest) == NULL || (destMax) == 0 || (destMax) > (maxLimit)) -#define SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, maxLimit) \ - do { \ - if ((strDest) != NULL && (destMax) > 0 && (destMax) <= (maxLimit)) { \ - *(strDest) = '\0'; \ - } \ - } \ - SECUREC_WHILE_ZERO +#define SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, maxLimit) do { \ + if ((strDest) != NULL && (destMax) > 0 && (destMax) <= (maxLimit)) { \ + *(strDest) = '\0'; \ + } \ +} SECUREC_WHILE_ZERO #ifdef SECUREC_COMPATIBLE_WIN_FORMAT -#define SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, \ - maxLimit) \ - (((format) == NULL || (strDest) == NULL || (destMax) == 0 || \ - (destMax) > (maxLimit)) || \ - ((count) > (SECUREC_STRING_MAX_LEN - 1) && (count) != (size_t)(-1))) +#define SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, maxLimit) \ + (((format) == NULL || (strDest) == NULL || (destMax) == 0 || (destMax) > (maxLimit)) || \ + ((count) > (SECUREC_STRING_MAX_LEN - 1) && (count) != (size_t)(-1))) #else -#define SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, \ - maxLimit) \ - (((format) == NULL || (strDest) == NULL || (destMax) == 0 || \ - (destMax) > (maxLimit)) || \ - ((count) > (SECUREC_STRING_MAX_LEN - 1))) +#define SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, maxLimit) \ + (((format) == NULL || (strDest) == NULL || (destMax) == 0 || (destMax) > (maxLimit)) || \ + ((count) > (SECUREC_STRING_MAX_LEN - 1))) #endif + #ifdef __cplusplus extern "C" { #endif -extern int SecVsnprintfImpl(char *string, size_t count, const char *format, - va_list argList); + extern int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList); #if SECUREC_IN_KERNEL == 0 -extern int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, - const wchar_t *format, va_list argList); + extern int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, va_list argList); #endif #ifdef __cplusplus } #endif #endif + + diff --git a/project/app/wifi_app/hisi_tools/securec/secureprintoutput_a.c b/project/app/wifi_app/hisi_tools/securec/secureprintoutput_a.c index e983dd658..2f22ba44c 100644 --- a/project/app/wifi_app/hisi_tools/securec/secureprintoutput_a.c +++ b/project/app/wifi_app/hisi_tools/securec/secureprintoutput_a.c @@ -1,8 +1,9 @@ /* * Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved. - * Description: By defining corresponding macro for ANSI string and including - * "output.inl", this file generates real underlying function used by printf - * family API. Author: lishunda Create: 2014-02-25 + * Description: By defining corresponding macro for ANSI string and including "output.inl", + * this file generates real underlying function used by printf family API. + * Author: lishunda + * Create: 2014-02-25 */ #define SECUREC_FORMAT_OUTPUT_INPUT 1 @@ -18,77 +19,74 @@ static const unsigned char g_flagTable[SECUREC_FORMAT_FLAG_TABLE_SIZE] = { /* * Known flag is "0123456789 +-#hlLwZzjqt*I" */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}; + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 +}; -SECUREC_INLINE const char *SecSkipKnownFlags(const char *format) { - const char *fmt = format; - while (*fmt != '\0') { - char fmtChar = *fmt; - if ((unsigned char)fmtChar > - 0x7f) { /* 0x7f is upper limit of format char value */ - break; +SECUREC_INLINE const char *SecSkipKnownFlags(const char *format) +{ + const char *fmt = format; + while (*fmt != '\0') { + char fmtChar = *fmt; + if ((unsigned char)fmtChar > 0x7f) { /* 0x7f is upper limit of format char value */ + break; + } + if (g_flagTable[(unsigned char)fmtChar] == 0) { + break; + } + ++fmt; } - if (g_flagTable[(unsigned char)fmtChar] == 0) { - break; - } - ++fmt; - } - return fmt; + return fmt; } -SECUREC_INLINE int SecFormatContainN(const char *format) { - const char *fmt = format; - while (*fmt != '\0') { - ++fmt; - /* Skip normal char */ - if (*(fmt - 1) != '%') { - continue; +SECUREC_INLINE int SecFormatContainN(const char *format) +{ + const char *fmt = format; + while (*fmt != '\0') { + ++fmt; + /* Skip normal char */ + if (*(fmt - 1) != '%') { + continue; + } + /* Meet %% */ + if (*fmt == '%') { + ++fmt; /* Point to the character after the %. Correct handling %%xx */ + continue; + } + /* Now parse %..., fmt point to the character after the % */ + fmt = SecSkipKnownFlags(fmt); + if (*fmt == 'n') { + return 1; + } } - /* Meet %% */ - if (*fmt == '%') { - ++fmt; /* Point to the character after the %. Correct handling %%xx */ - continue; - } - /* Now parse %..., fmt point to the character after the % */ - fmt = SecSkipKnownFlags(fmt); - if (*fmt == 'n') { - return 1; - } - } - return 0; + return 0; } /* - * Multi character formatted output implementation, the count include \0 - * character, must be greater than zero + * Multi character formatted output implementation, the count include \0 character, must be greater than zero */ -int SecVsnprintfImpl(char *string, size_t count, const char *format, - va_list argList) { - int retVal; - if (SecFormatContainN(format)) { - string[0] = '\0'; - return -1; - } - retVal = vsnprintf(string, count, format, argList); - if (retVal >= (int)count) { /* The size_t to int is ok, count max is - SECUREC_STRING_MAX_LEN */ - /* The buffer was too small; we return truncation */ - string[count - 1] = '\0'; - return SECUREC_PRINTF_TRUNCATE; - } else if (retVal < 0) { - string[0] = '\0'; /* Empty the dest strDest */ - return -1; - } - return retVal; +int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList) +{ + int retVal; + if (SecFormatContainN(format)) { + string[0] = '\0'; + return -1; + } + retVal = vsnprintf(string, count, format, argList); + if (retVal >= (int)count) { /* The size_t to int is ok, count max is SECUREC_STRING_MAX_LEN */ + /* The buffer was too small; we return truncation */ + string[count - 1] = '\0'; + return SECUREC_PRINTF_TRUNCATE; + } else if (retVal < 0) { + string[0] = '\0'; /* Empty the dest strDest */ + return -1; + } + return retVal; } #else #if SECUREC_IN_KERNEL @@ -96,76 +94,73 @@ int SecVsnprintfImpl(char *string, size_t count, const char *format, #endif #define SECUREC_CHAR(x) x -#define SECUREC_WRITE_MULTI_CHAR SecWriteMultiChar -#define SECUREC_WRITE_STRING SecWriteString +#define SECUREC_WRITE_MULTI_CHAR SecWriteMultiChar +#define SECUREC_WRITE_STRING SecWriteString #ifndef EOF #define EOF (-1) #endif -SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, - int *pnumwritten); -SECUREC_INLINE void SecWriteString(const char *string, int len, - SecPrintfStream *f, int *pnumwritten); +SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, int *pnumwritten); +SECUREC_INLINE void SecWriteString(const char *string, int len, SecPrintfStream *f, int *pnumwritten); #include "output.inl" /* * Multi character formatted output implementation */ -int SecVsnprintfImpl(char *string, size_t count, const char *format, - va_list argList) { - SecPrintfStream str; - int retVal; +int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList) +{ + SecPrintfStream str; + int retVal; - str.count = (int) - count; /* The count include \0 character, must be greater than zero */ - str.cur = string; + str.count = (int)count; /* The count include \0 character, must be greater than zero */ + str.cur = string; - retVal = SecOutputS(&str, format, argList); - if (retVal >= 0 && SecPutZeroChar(&str) == 0) { - return retVal; - } else if (str.count < 0) { - /* The buffer was too small; we return truncation */ - string[count - 1] = '\0'; - return SECUREC_PRINTF_TRUNCATE; - } - string[0] = '\0'; /* Empty the dest strDest */ - return -1; + retVal = SecOutputS(&str, format, argList); + if (retVal >= 0 && SecPutZeroChar(&str) == 0) { + return retVal; + } else if (str.count < 0) { + /* The buffer was too small; we return truncation */ + string[count - 1] = '\0'; + return SECUREC_PRINTF_TRUNCATE; + } + string[0] = '\0'; /* Empty the dest strDest */ + return -1; } /* * Write a wide character */ -SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, - int *pnumwritten) { - int count = num; - while (count-- > 0 && --(f->count) >= 0) { - *(f->cur) = ch; - ++(f->cur); - *pnumwritten = *pnumwritten + 1; - } - if (f->count < 0) { - *pnumwritten = -1; - } +SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, int *pnumwritten) +{ + int count = num; + while (count-- > 0 && --(f->count) >= 0) { + *(f->cur) = ch; + ++(f->cur); + *pnumwritten = *pnumwritten + 1; + } + if (f->count < 0) { + *pnumwritten = -1; + } } /* - * Write string function, where this function is called, make sure that len is - * greater than 0 + * Write string function, where this function is called, make sure that len is greater than 0 */ -SECUREC_INLINE void SecWriteString(const char *string, int len, - SecPrintfStream *f, int *pnumwritten) { - const char *str = string; - int count = len; - while (count-- > 0 && --(f->count) >= 0) { - *(f->cur) = *str; - ++(f->cur); - ++str; - } - *pnumwritten = *pnumwritten + (int)(size_t)(str - string); - if (f->count < 0) { - *pnumwritten = -1; - } +SECUREC_INLINE void SecWriteString(const char *string, int len, SecPrintfStream *f, int *pnumwritten) +{ + const char *str = string; + int count = len; + while (count-- > 0 && --(f->count) >= 0) { + *(f->cur) = *str; + ++(f->cur); + ++str; + } + *pnumwritten = *pnumwritten + (int)(size_t)(str - string); + if (f->count < 0) { + *pnumwritten = -1; + } } #endif + diff --git a/project/app/wifi_app/hisi_tools/securec/secureprintoutput_w.c b/project/app/wifi_app/hisi_tools/securec/secureprintoutput_w.c index 83aaecab4..aa82421ab 100644 --- a/project/app/wifi_app/hisi_tools/securec/secureprintoutput_w.c +++ b/project/app/wifi_app/hisi_tools/securec/secureprintoutput_w.c @@ -1,8 +1,9 @@ /* * Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved. - * Description: By defining corresponding macro for UNICODE string and including - * "output.inl", this file generates real underlying function used by printf - * family API. Author: lishunda Create: 2014-02-25 + * Description: By defining corresponding macro for UNICODE string and including "output.inl", + * this file generates real underlying function used by printf family API. + * Author: lishunda + * Create: 2014-02-25 */ /* If some platforms don't have wchar.h, dont't include it */ @@ -10,7 +11,7 @@ /* If there is no macro above, it will cause compiling alarm */ #if defined(_MSC_VER) && (_MSC_VER >= 1400) #ifndef _CRTIMP_ALTERNATIVE -#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */ +#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */ #endif #ifndef __STDC_WANT_SECURE_LIB__ #define __STDC_WANT_SECURE_LIB__ 0 @@ -20,7 +21,7 @@ #endif /* Disable wchar func to clear vs warning */ -#define SECUREC_ENABLE_WCHAR_FUNC 0 +#define SECUREC_ENABLE_WCHAR_FUNC 0 #define SECUREC_FORMAT_OUTPUT_INPUT 1 #ifndef SECUREC_FOR_WCHAR @@ -34,114 +35,108 @@ #include "secureprintoutput.h" -#define SECUREC_CHAR(x) L##x +#define SECUREC_CHAR(x) L ## x #define SECUREC_WRITE_MULTI_CHAR SecWriteMultiCharW -#define SECUREC_WRITE_STRING SecWriteStringW +#define SECUREC_WRITE_STRING SecWriteStringW -SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f, - int *pnumwritten); -SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, - int *pnumwritten); -SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len, - SecPrintfStream *f, int *pnumwritten); -SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str, - int zeroCount); +SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f, int *pnumwritten); +SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, int *pnumwritten); +SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len, SecPrintfStream *f, int *pnumwritten); +SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str, int zeroCount); #include "output.inl" /* * Wide character formatted output implementation */ -int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, - va_list argList) { - SecPrintfStream str; - int retVal; /* If initialization causes e838 */ +int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, va_list argList) +{ + SecPrintfStream str; + int retVal; /* If initialization causes e838 */ - str.cur = (char *)string; - /* This count include \0 character, Must be greater than zero */ - str.count = (int)(sizeInWchar * sizeof(wchar_t)); + str.cur = (char *)string; + /* This count include \0 character, Must be greater than zero */ + str.count = (int)(sizeInWchar * sizeof(wchar_t)); - retVal = SecOutputSW(&str, format, argList); - if (retVal >= 0 && - SecPutWcharStrEndingZero(&str, (int)sizeof(wchar_t)) == 0) { - return (retVal); - } else if (str.count < 0) { - /* The buffer was too small; we return truncation */ - string[sizeInWchar - 1] = L'\0'; - return SECUREC_PRINTF_TRUNCATE; - } - string[0] = L'\0'; - return -1; + retVal = SecOutputSW(&str, format, argList); + if (retVal >= 0 && SecPutWcharStrEndingZero(&str, (int)sizeof(wchar_t)) == 0) { + return (retVal); + } else if (str.count < 0) { + /* The buffer was too small; we return truncation */ + string[sizeInWchar - 1] = L'\0'; + return SECUREC_PRINTF_TRUNCATE; + } + string[0] = L'\0'; + return -1; } /* * Output a wide character zero end into the SecPrintfStream structure */ -SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str, - int zeroCount) { - int i = 0; - while (i < zeroCount && SecPutZeroChar(str) == 0) { - ++i; - } - if (i == zeroCount) { - return 0; - } - return -1; +SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str, int zeroCount) +{ + int i = 0; + while (i < zeroCount && SecPutZeroChar(str) == 0) { + ++i; + } + if (i == zeroCount) { + return 0; + } + return -1; } /* * Output a wide character into the SecPrintfStream structure */ -SECUREC_INLINE int SecPutCharW(wchar_t ch, SecPrintfStream *f) { - if (((f)->count -= (int)sizeof(wchar_t)) >= 0) { - *(wchar_t *)(void *)(f->cur) = ch; - f->cur += sizeof(wchar_t); - return 0; - } - return -1; -} - -/* - * Output a wide character into the SecPrintfStream structure, returns the - * number of characters written - */ -SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f, - int *pnumwritten) { - if (SecPutCharW(ch, f) == 0) { - *pnumwritten = *pnumwritten + 1; - } else { - *pnumwritten = -1; - } -} - -/* - * Output multiple wide character into the SecPrintfStream structure, returns - * the number of characters written - */ -SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, - int *pnumwritten) { - int count = num; - while (count-- > 0) { - SecWriteCharW(ch, f, pnumwritten); - if (*pnumwritten == -1) { - break; +SECUREC_INLINE int SecPutCharW(wchar_t ch, SecPrintfStream *f) +{ + if (((f)->count -= (int)sizeof(wchar_t)) >= 0) { + *(wchar_t *)(void *)(f->cur) = ch; + f->cur += sizeof(wchar_t); + return 0; } - } + return -1; } /* - * Output a wide string into the SecPrintfStream structure, returns the number - * of characters written + * Output a wide character into the SecPrintfStream structure, returns the number of characters written */ -SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len, - SecPrintfStream *f, int *pnumwritten) { - const wchar_t *str = string; - int count = len; - while (count-- > 0) { - SecWriteCharW(*str, f, pnumwritten); - ++str; - if (*pnumwritten == -1) { - break; +SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f, int *pnumwritten) +{ + if (SecPutCharW(ch, f) == 0) { + *pnumwritten = *pnumwritten + 1; + } else { + *pnumwritten = -1; } - } } + +/* + * Output multiple wide character into the SecPrintfStream structure, returns the number of characters written + */ +SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, int *pnumwritten) +{ + int count = num; + while (count-- > 0) { + SecWriteCharW(ch, f, pnumwritten); + if (*pnumwritten == -1) { + break; + } + } +} + +/* + * Output a wide string into the SecPrintfStream structure, returns the number of characters written + */ +SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len, SecPrintfStream *f, int *pnumwritten) +{ + const wchar_t *str = string; + int count = len; + while (count-- > 0) { + SecWriteCharW(*str, f, pnumwritten); + ++str; + if (*pnumwritten == -1) { + break; + } + } +} + diff --git a/project/app/wifi_app/hisi_tools/securec/snprintf_s.c b/project/app/wifi_app/hisi_tools/securec/snprintf_s.c index 5954cda54..d5ff75653 100644 --- a/project/app/wifi_app/hisi_tools/securec/snprintf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/snprintf_s.c @@ -11,19 +11,18 @@ /* * * The snprintf_s function is equivalent to the snprintf function - * except for the parameter destMax/count and the explicit - * runtime-constraints violation The snprintf_s function formats and stores - * count or fewer characters in strDest and appends a terminating null. Each - * argument (if any) is converted and output according to the corresponding - * format specification in format. The formatting is consistent with the printf - * family of functions; If copying occurs between strings that overlap, the - * behavior is undefined. + * except for the parameter destMax/count and the explicit runtime-constraints violation + * The snprintf_s function formats and stores count or fewer characters in + * strDest and appends a terminating null. Each argument (if any) is converted + * and output according to the corresponding format specification in format. + * The formatting is consistent with the printf family of functions; If copying + * occurs between strings that overlap, the behavior is undefined. * * * strDest Storage location for the output. * destMax The size of the storage location for output. Size - * in bytes for snprintf_s or size in words for - * snwprintf_s. count Maximum number of character to store. + * in bytes for snprintf_s or size in words for snwprintf_s. + * count Maximum number of character to store. * format Format-control string. * ... Optional arguments. * @@ -31,26 +30,24 @@ * strDest is updated * * - * return the number of characters written, not including the terminating - * null return -1 if an error occurs. return -1 if count < destMax and the - * output string has been truncated + * return the number of characters written, not including the terminating null + * return -1 if an error occurs. + * return -1 if count < destMax and the output string has been truncated * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid * */ -int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, - ...) { - int ret; /* If initialization causes e838 */ - va_list argList; +int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, ...) +{ + int ret; /* If initialization causes e838 */ + va_list argList; - va_start(argList, format); - ret = vsnprintf_s(strDest, destMax, count, format, argList); - va_end(argList); - (void)argList; /* To clear e438 last value assigned not used , the compiler - will optimize this code */ + va_start(argList, format); + ret = vsnprintf_s(strDest, destMax, count, format, argList); + va_end(argList); + (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */ - return ret; + return ret; } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(snprintf_s); @@ -61,48 +58,47 @@ EXPORT_SYMBOL(snprintf_s); /* * * The snprintf_truncated_s function is equivalent to the snprintf function - * except for the parameter destMax/count and the explicit - * runtime-constraints violation The snprintf_truncated_s function formats and - * stores count or fewer characters in strDest and appends a terminating null. - * Each argument (if any) is converted and output according to the corresponding - * format specification in format. The formatting is consistent with the printf - * family of functions; If copying occurs between strings that overlap, the - * behavior is undefined. + * except for the parameter destMax/count and the explicit runtime-constraints violation + * The snprintf_truncated_s function formats and stores count or fewer characters in + * strDest and appends a terminating null. Each argument (if any) is converted + * and output according to the corresponding format specification in format. + * The formatting is consistent with the printf family of functions; If copying + * occurs between strings that overlap, the behavior is undefined. * * * strDest Storage location for the output. * destMax The size of the storage location for output. Size - * in bytes for snprintf_truncated_s or size in - * words for snwprintf_s. format Format-control string. + * in bytes for snprintf_truncated_s or size in words for snwprintf_s. + * format Format-control string. * ... Optional arguments. * * * strDest is updated * * - * return the number of characters written, not including the terminating - * null return -1 if an error occurs. return destMax-1 if output string has - * been truncated + * return the number of characters written, not including the terminating null + * return -1 if an error occurs. + * return destMax-1 if output string has been truncated * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid * */ -int snprintf_truncated_s(char *strDest, size_t destMax, const char *format, - ...) { - int ret; /* If initialization causes e838 */ - va_list argList; +int snprintf_truncated_s(char *strDest, size_t destMax, const char *format, ...) +{ + int ret; /* If initialization causes e838 */ + va_list argList; - va_start(argList, format); - ret = vsnprintf_truncated_s(strDest, destMax, format, argList); - va_end(argList); - (void)argList; /* To clear e438 last value assigned not used , the compiler - will optimize this code */ + va_start(argList, format); + ret = vsnprintf_truncated_s(strDest, destMax, format, argList); + va_end(argList); + (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */ - return ret; + return ret; } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(snprintf_truncated_s); #endif #endif + + diff --git a/project/app/wifi_app/hisi_tools/securec/sprintf_s.c b/project/app/wifi_app/hisi_tools/securec/sprintf_s.c index adec1d1dd..239835f39 100644 --- a/project/app/wifi_app/hisi_tools/securec/sprintf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/sprintf_s.c @@ -10,14 +10,13 @@ /* * * The sprintf_s function is equivalent to the sprintf function - * except for the parameter destMax and the explicit runtime-constraints - * violation The sprintf_s function formats and stores a series of characters - * and values in strDest. Each argument (if any) is converted and output - * according to the corresponding format specification in format. The format - * consists of ordinary characters and has the same form and function as the - * format argument for printf. A null character is appended after the last - * character written. If copying occurs between strings that overlap, the - * behavior is undefined. + * except for the parameter destMax and the explicit runtime-constraints violation + * The sprintf_s function formats and stores a series of characters and values + * in strDest. Each argument (if any) is converted and output according to + * the corresponding format specification in format. The format consists of + * ordinary characters and has the same form and function as the format argument + * for printf. A null character is appended after the last character written. + * If copying occurs between strings that overlap, the behavior is undefined. * * * strDest Storage location for output. @@ -29,24 +28,25 @@ * strDest is updated * * - * return the number of bytes stored in strDest, not counting the terminating - * null character. return -1 if an error occurred. + * return the number of bytes stored in strDest, not counting the terminating null character. + * return -1 if an error occurred. * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -int sprintf_s(char *strDest, size_t destMax, const char *format, ...) { - int ret; /* If initialization causes e838 */ - va_list argList; +int sprintf_s(char *strDest, size_t destMax, const char *format, ...) +{ + int ret; /* If initialization causes e838 */ + va_list argList; - va_start(argList, format); - ret = vsprintf_s(strDest, destMax, format, argList); - va_end(argList); - (void)argList; /* To clear e438 last value assigned not used , the compiler - will optimize this code */ + va_start(argList, format); + ret = vsprintf_s(strDest, destMax, format, argList); + va_end(argList); + (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */ - return ret; + return ret; } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(sprintf_s); #endif + + diff --git a/project/app/wifi_app/hisi_tools/securec/sscanf_s.c b/project/app/wifi_app/hisi_tools/securec/sscanf_s.c index 0b07f3fd2..45afcd04c 100644 --- a/project/app/wifi_app/hisi_tools/securec/sscanf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/sscanf_s.c @@ -10,13 +10,13 @@ /* * * The sscanf_s function is equivalent to fscanf_s, - * except that input is obtained from a string (specified by the argument - * buffer) rather than from a stream The sscanf function reads data from buffer - * into the location given by each argument. Every argument must be a pointer to - * a variable with a type that corresponds to a type specifier in format. The - * format argument controls the interpretation of the input fields and has the - * same form and function as the format argument for the scanf function. If - * copying takes place between strings that overlap, the behavior is undefined. + * except that input is obtained from a string (specified by the argument buffer) rather than from a stream + * The sscanf function reads data from buffer into the location given by each + * argument. Every argument must be a pointer to a variable with a type that + * corresponds to a type specifier in format. The format argument controls the + * interpretation of the input fields and has the same form and function as + * the format argument for the scanf function. + * If copying takes place between strings that overlap, the behavior is undefined. * * * buffer Stored data. @@ -27,23 +27,26 @@ * ... The converted value stored in user assigned address * * - * Each of these functions returns the number of fields successfully - * converted and assigned; the return value does not include fields that were - * read but not assigned. A return value of 0 indicates that no fields were - * assigned. return -1 if an error occurs. + * Each of these functions returns the number of fields successfully converted + * and assigned; the return value does not include fields that were read but + * not assigned. + * A return value of 0 indicates that no fields were assigned. + * return -1 if an error occurs. */ -int sscanf_s(const char *buffer, const char *format, ...) { - int ret; /* If initialization causes e838 */ - va_list argList; +int sscanf_s(const char *buffer, const char *format, ...) +{ + int ret; /* If initialization causes e838 */ + va_list argList; - va_start(argList, format); - ret = vsscanf_s(buffer, format, argList); - va_end(argList); - (void)argList; /* To clear e438 last value assigned not used , the compiler - will optimize this code */ + va_start(argList, format); + ret = vsscanf_s(buffer, format, argList); + va_end(argList); + (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */ - return ret; + return ret; } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(sscanf_s); #endif + + diff --git a/project/app/wifi_app/hisi_tools/securec/strcat_s.c b/project/app/wifi_app/hisi_tools/securec/strcat_s.c index 6d3fb09c6..d595e4dc1 100644 --- a/project/app/wifi_app/hisi_tools/securec/strcat_s.c +++ b/project/app/wifi_app/hisi_tools/securec/strcat_s.c @@ -10,46 +10,44 @@ /* * Befor this function, the basic parameter checking has been done */ -SECUREC_INLINE errno_t SecDoCat(char *strDest, size_t destMax, - const char *strSrc) { - size_t destLen; - size_t srcLen; - size_t maxSrcLen; - SECUREC_CALC_STR_LEN(strDest, destMax, &destLen); - /* Only optimize strSrc, do not apply this function to strDest */ - maxSrcLen = destMax - destLen; - SECUREC_CALC_STR_LEN_OPT(strSrc, maxSrcLen, &srcLen); +SECUREC_INLINE errno_t SecDoCat(char *strDest, size_t destMax, const char *strSrc) +{ + size_t destLen; + size_t srcLen; + size_t maxSrcLen; + SECUREC_CALC_STR_LEN(strDest, destMax, &destLen); + /* Only optimize strSrc, do not apply this function to strDest */ + maxSrcLen = destMax - destLen; + SECUREC_CALC_STR_LEN_OPT(strSrc, maxSrcLen, &srcLen); - if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) { - strDest[0] = '\0'; - if (strDest + destLen <= strSrc && destLen == destMax) { - SECUREC_ERROR_INVALID_PARAMTER("strcat_s"); - return EINVAL_AND_RESET; + if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) { + strDest[0] = '\0'; + if (strDest + destLen <= strSrc && destLen == destMax) { + SECUREC_ERROR_INVALID_PARAMTER("strcat_s"); + return EINVAL_AND_RESET; + } + SECUREC_ERROR_BUFFER_OVERLAP("strcat_s"); + return EOVERLAP_AND_RESET; } - SECUREC_ERROR_BUFFER_OVERLAP("strcat_s"); - return EOVERLAP_AND_RESET; - } - if (srcLen + destLen >= destMax || strDest == strSrc) { - strDest[0] = '\0'; - if (destLen == destMax) { - SECUREC_ERROR_INVALID_PARAMTER("strcat_s"); - return EINVAL_AND_RESET; + if (srcLen + destLen >= destMax || strDest == strSrc) { + strDest[0] = '\0'; + if (destLen == destMax) { + SECUREC_ERROR_INVALID_PARAMTER("strcat_s"); + return EINVAL_AND_RESET; + } + SECUREC_ERROR_INVALID_RANGE("strcat_s"); + return ERANGE_AND_RESET; } - SECUREC_ERROR_INVALID_RANGE("strcat_s"); - return ERANGE_AND_RESET; - } - SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, - srcLen + 1); /* Single character length include \0 */ - return EOK; + SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, srcLen + 1); /* Single character length include \0 */ + return EOK; } /* * - * The strcat_s function appends a copy of the string pointed to by strSrc - * (including the terminating null character) to the end of the string pointed - * to by strDest. The initial character of strSrc overwrites the terminating - * null character of strDest. strcat_s will return EOVERLAP_AND_RESET if the - * source and destination strings overlap. + * The strcat_s function appends a copy of the string pointed to by strSrc (including the terminating null character) + * to the end of the string pointed to by strDest. + * The initial character of strSrc overwrites the terminating null character of strDest. + * strcat_s will return EOVERLAP_AND_RESET if the source and destination strings overlap. * * Note that the second parameter is the total size of the buffer, not the * remaining size. @@ -64,34 +62,33 @@ SECUREC_INLINE errno_t SecDoCat(char *strDest, size_t destMax, * * * EOK Success - * EINVAL strDest is NULL and destMax != 0 and destMax <= - * SECUREC_STRING_MAX_LEN EINVAL_AND_RESET (strDest unterminated and all - * other parameters are valid)or (strDest != NULL and strSrc is NULL and destMax - * != 0 and destMax <= SECUREC_STRING_MAX_LEN) ERANGE destMax is 0 - * and destMax > SECUREC_STRING_MAX_LEN ERANGE_AND_RESET strDest have not - * enough space and all other parameters are valid and not overlap - * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all - * parameters are valid + * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN + * EINVAL_AND_RESET (strDest unterminated and all other parameters are valid)or + * (strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN) + * ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN + * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap + * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc) { - if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) { - SECUREC_ERROR_INVALID_RANGE("strcat_s"); - return ERANGE; - } - if (strDest == NULL || strSrc == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("strcat_s"); - if (strDest != NULL) { - strDest[0] = '\0'; - return EINVAL_AND_RESET; +errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc) +{ + if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) { + SECUREC_ERROR_INVALID_RANGE("strcat_s"); + return ERANGE; } - return EINVAL; - } - return SecDoCat(strDest, destMax, strSrc); + if (strDest == NULL || strSrc == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("strcat_s"); + if (strDest != NULL) { + strDest[0] = '\0'; + return EINVAL_AND_RESET; + } + return EINVAL; + } + return SecDoCat(strDest, destMax, strSrc); } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(strcat_s); #endif + diff --git a/project/app/wifi_app/hisi_tools/securec/strcpy_s.c b/project/app/wifi_app/hisi_tools/securec/strcpy_s.c index d00862d74..8459e7064 100644 --- a/project/app/wifi_app/hisi_tools/securec/strcpy_s.c +++ b/project/app/wifi_app/hisi_tools/securec/strcpy_s.c @@ -18,317 +18,282 @@ #if (SECUREC_IN_KERNEL == 0) && SECUREC_STRCPY_WITH_PERFORMANCE #ifndef SECUREC_STRCOPY_THRESHOLD_SIZE -#define SECUREC_STRCOPY_THRESHOLD_SIZE 32UL +#define SECUREC_STRCOPY_THRESHOLD_SIZE 32UL #endif + /* The purpose of converting to void is to clean up the alarm */ -#define SECUREC_SMALL_STR_COPY(strDest, strSrc, srcStrLen) \ - do { \ - if (SECUREC_ADDR_ALIGNED_8(strDest) && SECUREC_ADDR_ALIGNED_8(strSrc)) { \ - /* Use struct assignment */ \ - switch (srcStrLen) { \ - case 1: \ - *(SecStrBuf1 *)(void *)(strDest) = \ - *(const SecStrBuf1 *)(const void *)(strSrc); \ - break; \ - case 2: \ - *(SecStrBuf2 *)(void *)(strDest) = \ - *(const SecStrBuf2 *)(const void *)(strSrc); \ - break; \ - case 3: \ - *(SecStrBuf3 *)(void *)(strDest) = \ - *(const SecStrBuf3 *)(const void *)(strSrc); \ - break; \ - case 4: \ - *(SecStrBuf4 *)(void *)(strDest) = \ - *(const SecStrBuf4 *)(const void *)(strSrc); \ - break; \ - case 5: \ - *(SecStrBuf5 *)(void *)(strDest) = \ - *(const SecStrBuf5 *)(const void *)(strSrc); \ - break; \ - case 6: \ - *(SecStrBuf6 *)(void *)(strDest) = \ - *(const SecStrBuf6 *)(const void *)(strSrc); \ - break; \ - case 7: \ - *(SecStrBuf7 *)(void *)(strDest) = \ - *(const SecStrBuf7 *)(const void *)(strSrc); \ - break; \ - case 8: \ - *(SecStrBuf8 *)(void *)(strDest) = \ - *(const SecStrBuf8 *)(const void *)(strSrc); \ - break; \ - case 9: \ - *(SecStrBuf9 *)(void *)(strDest) = \ - *(const SecStrBuf9 *)(const void *)(strSrc); \ - break; \ - case 10: \ - *(SecStrBuf10 *)(void *)(strDest) = \ - *(const SecStrBuf10 *)(const void *)(strSrc); \ - break; \ - case 11: \ - *(SecStrBuf11 *)(void *)(strDest) = \ - *(const SecStrBuf11 *)(const void *)(strSrc); \ - break; \ - case 12: \ - *(SecStrBuf12 *)(void *)(strDest) = \ - *(const SecStrBuf12 *)(const void *)(strSrc); \ - break; \ - case 13: \ - *(SecStrBuf13 *)(void *)(strDest) = \ - *(const SecStrBuf13 *)(const void *)(strSrc); \ - break; \ - case 14: \ - *(SecStrBuf14 *)(void *)(strDest) = \ - *(const SecStrBuf14 *)(const void *)(strSrc); \ - break; \ - case 15: \ - *(SecStrBuf15 *)(void *)(strDest) = \ - *(const SecStrBuf15 *)(const void *)(strSrc); \ - break; \ - case 16: \ - *(SecStrBuf16 *)(void *)(strDest) = \ - *(const SecStrBuf16 *)(const void *)(strSrc); \ - break; \ - case 17: \ - *(SecStrBuf17 *)(void *)(strDest) = \ - *(const SecStrBuf17 *)(const void *)(strSrc); \ - break; \ - case 18: \ - *(SecStrBuf18 *)(void *)(strDest) = \ - *(const SecStrBuf18 *)(const void *)(strSrc); \ - break; \ - case 19: \ - *(SecStrBuf19 *)(void *)(strDest) = \ - *(const SecStrBuf19 *)(const void *)(strSrc); \ - break; \ - case 20: \ - *(SecStrBuf20 *)(void *)(strDest) = \ - *(const SecStrBuf20 *)(const void *)(strSrc); \ - break; \ - case 21: \ - *(SecStrBuf21 *)(void *)(strDest) = \ - *(const SecStrBuf21 *)(const void *)(strSrc); \ - break; \ - case 22: \ - *(SecStrBuf22 *)(void *)(strDest) = \ - *(const SecStrBuf22 *)(const void *)(strSrc); \ - break; \ - case 23: \ - *(SecStrBuf23 *)(void *)(strDest) = \ - *(const SecStrBuf23 *)(const void *)(strSrc); \ - break; \ - case 24: \ - *(SecStrBuf24 *)(void *)(strDest) = \ - *(const SecStrBuf24 *)(const void *)(strSrc); \ - break; \ - case 25: \ - *(SecStrBuf25 *)(void *)(strDest) = \ - *(const SecStrBuf25 *)(const void *)(strSrc); \ - break; \ - case 26: \ - *(SecStrBuf26 *)(void *)(strDest) = \ - *(const SecStrBuf26 *)(const void *)(strSrc); \ - break; \ - case 27: \ - *(SecStrBuf27 *)(void *)(strDest) = \ - *(const SecStrBuf27 *)(const void *)(strSrc); \ - break; \ - case 28: \ - *(SecStrBuf28 *)(void *)(strDest) = \ - *(const SecStrBuf28 *)(const void *)(strSrc); \ - break; \ - case 29: \ - *(SecStrBuf29 *)(void *)(strDest) = \ - *(const SecStrBuf29 *)(const void *)(strSrc); \ - break; \ - case 30: \ - *(SecStrBuf30 *)(void *)(strDest) = \ - *(const SecStrBuf30 *)(const void *)(strSrc); \ - break; \ - case 31: \ - *(SecStrBuf31 *)(void *)(strDest) = \ - *(const SecStrBuf31 *)(const void *)(strSrc); \ - break; \ - case 32: \ - *(SecStrBuf32 *)(void *)(strDest) = \ - *(const SecStrBuf32 *)(const void *)(strSrc); \ - break; \ - default: \ - break; \ - } /* END switch */ \ - } else { \ - char *tmpStrDest = (char *)(strDest); \ - const char *tmpStrSrc = (const char *)(strSrc); \ - switch (srcStrLen) { \ - case 32: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 31: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 30: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 29: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 28: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 27: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 26: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 25: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 24: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 23: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 22: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 21: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 20: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 19: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 18: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 17: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 16: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 15: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 14: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 13: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 12: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 11: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 10: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 9: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 8: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 7: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 6: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 5: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 4: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 3: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 2: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - case 1: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ - /* fall-through */ /* FALLTHRU */ \ - default: \ - break; \ - } \ - } \ - } \ - SECUREC_WHILE_ZERO +#define SECUREC_SMALL_STR_COPY(strDest, strSrc, srcStrLen) do { \ + if (SECUREC_ADDR_ALIGNED_8(strDest) && SECUREC_ADDR_ALIGNED_8(strSrc)) { \ + /* Use struct assignment */ \ + switch (srcStrLen) { \ + case 1: \ + *(SecStrBuf1 *)(void *)(strDest) = *(const SecStrBuf1 *)(const void *)(strSrc); \ + break; \ + case 2: \ + *(SecStrBuf2 *)(void *)(strDest) = *(const SecStrBuf2 *)(const void *)(strSrc); \ + break; \ + case 3: \ + *(SecStrBuf3 *)(void *)(strDest) = *(const SecStrBuf3 *)(const void *)(strSrc); \ + break; \ + case 4: \ + *(SecStrBuf4 *)(void *)(strDest) = *(const SecStrBuf4 *)(const void *)(strSrc); \ + break; \ + case 5: \ + *(SecStrBuf5 *)(void *)(strDest) = *(const SecStrBuf5 *)(const void *)(strSrc); \ + break; \ + case 6: \ + *(SecStrBuf6 *)(void *)(strDest) = *(const SecStrBuf6 *)(const void *)(strSrc); \ + break; \ + case 7: \ + *(SecStrBuf7 *)(void *)(strDest) = *(const SecStrBuf7 *)(const void *)(strSrc); \ + break; \ + case 8: \ + *(SecStrBuf8 *)(void *)(strDest) = *(const SecStrBuf8 *)(const void *)(strSrc); \ + break; \ + case 9: \ + *(SecStrBuf9 *)(void *)(strDest) = *(const SecStrBuf9 *)(const void *)(strSrc); \ + break; \ + case 10: \ + *(SecStrBuf10 *)(void *)(strDest) = *(const SecStrBuf10 *)(const void *)(strSrc); \ + break; \ + case 11: \ + *(SecStrBuf11 *)(void *)(strDest) = *(const SecStrBuf11 *)(const void *)(strSrc); \ + break; \ + case 12: \ + *(SecStrBuf12 *)(void *)(strDest) = *(const SecStrBuf12 *)(const void *)(strSrc); \ + break; \ + case 13: \ + *(SecStrBuf13 *)(void *)(strDest) = *(const SecStrBuf13 *)(const void *)(strSrc); \ + break; \ + case 14: \ + *(SecStrBuf14 *)(void *)(strDest) = *(const SecStrBuf14 *)(const void *)(strSrc); \ + break; \ + case 15: \ + *(SecStrBuf15 *)(void *)(strDest) = *(const SecStrBuf15 *)(const void *)(strSrc); \ + break; \ + case 16: \ + *(SecStrBuf16 *)(void *)(strDest) = *(const SecStrBuf16 *)(const void *)(strSrc); \ + break; \ + case 17: \ + *(SecStrBuf17 *)(void *)(strDest) = *(const SecStrBuf17 *)(const void *)(strSrc); \ + break; \ + case 18: \ + *(SecStrBuf18 *)(void *)(strDest) = *(const SecStrBuf18 *)(const void *)(strSrc); \ + break; \ + case 19: \ + *(SecStrBuf19 *)(void *)(strDest) = *(const SecStrBuf19 *)(const void *)(strSrc); \ + break; \ + case 20: \ + *(SecStrBuf20 *)(void *)(strDest) = *(const SecStrBuf20 *)(const void *)(strSrc); \ + break; \ + case 21: \ + *(SecStrBuf21 *)(void *)(strDest) = *(const SecStrBuf21 *)(const void *)(strSrc); \ + break; \ + case 22: \ + *(SecStrBuf22 *)(void *)(strDest) = *(const SecStrBuf22 *)(const void *)(strSrc); \ + break; \ + case 23: \ + *(SecStrBuf23 *)(void *)(strDest) = *(const SecStrBuf23 *)(const void *)(strSrc); \ + break; \ + case 24: \ + *(SecStrBuf24 *)(void *)(strDest) = *(const SecStrBuf24 *)(const void *)(strSrc); \ + break; \ + case 25: \ + *(SecStrBuf25 *)(void *)(strDest) = *(const SecStrBuf25 *)(const void *)(strSrc); \ + break; \ + case 26: \ + *(SecStrBuf26 *)(void *)(strDest) = *(const SecStrBuf26 *)(const void *)(strSrc); \ + break; \ + case 27: \ + *(SecStrBuf27 *)(void *)(strDest) = *(const SecStrBuf27 *)(const void *)(strSrc); \ + break; \ + case 28: \ + *(SecStrBuf28 *)(void *)(strDest) = *(const SecStrBuf28 *)(const void *)(strSrc); \ + break; \ + case 29: \ + *(SecStrBuf29 *)(void *)(strDest) = *(const SecStrBuf29 *)(const void *)(strSrc); \ + break; \ + case 30: \ + *(SecStrBuf30 *)(void *)(strDest) = *(const SecStrBuf30 *)(const void *)(strSrc); \ + break; \ + case 31: \ + *(SecStrBuf31 *)(void *)(strDest) = *(const SecStrBuf31 *)(const void *)(strSrc); \ + break; \ + case 32: \ + *(SecStrBuf32 *)(void *)(strDest) = *(const SecStrBuf32 *)(const void *)(strSrc); \ + break; \ + default: \ + break; \ + } /* END switch */ \ + } else { \ + char *tmpStrDest = (char *)(strDest); \ + const char *tmpStrSrc = (const char *)(strSrc); \ + switch (srcStrLen) { \ + case 32: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 31: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 30: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 29: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 28: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 27: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 26: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 25: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 24: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 23: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 22: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 21: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 20: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 19: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 18: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 17: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 16: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 15: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 14: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 13: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 12: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 11: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 10: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 9: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 8: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 7: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 6: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 5: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 4: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 3: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 2: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + case 1: \ + *(tmpStrDest++) = *(tmpStrSrc++); \ + /* fall-through */ /* FALLTHRU */ \ + default: \ + break; \ + } \ + } \ +} SECUREC_WHILE_ZERO #endif #if SECUREC_IN_KERNEL || (SECUREC_STRCPY_WITH_PERFORMANCE == 0) -#define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) \ - SECUREC_MEMCPY_WARP_OPT((dest), (src), (lenWithTerm)) +#define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) SECUREC_MEMCPY_WARP_OPT((dest), (src), (lenWithTerm)) #else /* * Performance optimization. lenWithTerm include '\0' */ -#define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) \ - do { \ - if ((lenWithTerm) > SECUREC_STRCOPY_THRESHOLD_SIZE) { \ - SECUREC_MEMCPY_WARP_OPT((dest), (src), (lenWithTerm)); \ - } else { \ - SECUREC_SMALL_STR_COPY((dest), (src), (lenWithTerm)); \ - } \ - } \ - SECUREC_WHILE_ZERO +#define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) do { \ + if ((lenWithTerm) > SECUREC_STRCOPY_THRESHOLD_SIZE) { \ + SECUREC_MEMCPY_WARP_OPT((dest), (src), (lenWithTerm)); \ + } else { \ + SECUREC_SMALL_STR_COPY((dest), (src), (lenWithTerm)); \ + } \ +} SECUREC_WHILE_ZERO #endif /* * Check Src Range */ -SECUREC_INLINE errno_t CheckSrcRange(char *strDest, size_t destMax, - const char *strSrc) { - size_t tmpDestMax = destMax; - const char *tmpSrc = strSrc; - /* Use destMax as boundary checker and destMax must be greater than zero */ - while (*(tmpSrc) != '\0' && tmpDestMax > 0) { - ++tmpSrc; - --tmpDestMax; - } - if (tmpDestMax == 0) { - strDest[0] = '\0'; - SECUREC_ERROR_INVALID_RANGE("strcpy_s"); - return ERANGE_AND_RESET; - } - return EOK; +SECUREC_INLINE errno_t CheckSrcRange(char *strDest, size_t destMax, const char *strSrc) +{ + size_t tmpDestMax = destMax; + const char *tmpSrc = strSrc; + /* Use destMax as boundary checker and destMax must be greater than zero */ + while (*(tmpSrc) != '\0' && tmpDestMax > 0) { + ++tmpSrc; + --tmpDestMax; + } + if (tmpDestMax == 0) { + strDest[0] = '\0'; + SECUREC_ERROR_INVALID_RANGE("strcpy_s"); + return ERANGE_AND_RESET; + } + return EOK; } /* * Handling errors */ -errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc) { - if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) { - SECUREC_ERROR_INVALID_RANGE("strcpy_s"); - return ERANGE; - } else if (strDest == NULL || strSrc == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("strcpy_s"); - if (strDest != NULL) { - strDest[0] = '\0'; - return EINVAL_AND_RESET; +errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc) +{ + if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) { + SECUREC_ERROR_INVALID_RANGE("strcpy_s"); + return ERANGE; + } else if (strDest == NULL || strSrc == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("strcpy_s"); + if (strDest != NULL) { + strDest[0] = '\0'; + return EINVAL_AND_RESET; + } + return EINVAL; } - return EINVAL; - } - return CheckSrcRange(strDest, destMax, strSrc); + return CheckSrcRange(strDest, destMax, strSrc); } /* * * The strcpy_s function copies the string pointed to strSrc - * (including the terminating null character) into the array pointed to - * by strDest The destination string must be large enough to hold the source - * string, including the terminating null character. strcpy_s will return - * EOVERLAP_AND_RESET if the source and destination strings overlap. + * (including the terminating null character) into the array pointed to by strDest + * The destination string must be large enough to hold the source string, + * including the terminating null character. strcpy_s will return EOVERLAP_AND_RESET + * if the source and destination strings overlap. * * * strDest Location of destination string buffer @@ -340,40 +305,38 @@ errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc) { * * * EOK Success - * EINVAL strDest is NULL and destMax != 0 and - * destMax <= SECUREC_STRING_MAX_LEN EINVAL_AND_RESET strDest != NULL and - * strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN ERANGE - * destMax is 0 and destMax > SECUREC_STRING_MAX_LEN ERANGE_AND_RESET strDest - * have not enough space and all other parameters are valid and not overlap - * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all - * parameters are valid + * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN + * EINVAL_AND_RESET strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN + * ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN + * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap + * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc) { - if ((destMax > 0 && destMax <= SECUREC_STRING_MAX_LEN && strDest != NULL && - strSrc != NULL && strDest != strSrc)) { - size_t srcStrLen; - SECUREC_CALC_STR_LEN(strSrc, destMax, &srcStrLen); - ++srcStrLen; /* The length include '\0' */ +errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc) +{ + if ((destMax > 0 && destMax <= SECUREC_STRING_MAX_LEN && strDest != NULL && strSrc != NULL && strDest != strSrc)) { + size_t srcStrLen; + SECUREC_CALC_STR_LEN(strSrc, destMax, &srcStrLen); + ++srcStrLen; /* The length include '\0' */ - if (srcStrLen <= destMax) { - /* Use mem overlap check include '\0' */ - if (SECUREC_MEMORY_NO_OVERLAP(strDest, strSrc, srcStrLen)) { - /* Performance optimization srcStrLen include '\0' */ - SECUREC_STRCPY_OPT(strDest, strSrc, srcStrLen); - return EOK; - } else { - strDest[0] = '\0'; - SECUREC_ERROR_BUFFER_OVERLAP("strcpy_s"); - return EOVERLAP_AND_RESET; - } + if (srcStrLen <= destMax) { + /* Use mem overlap check include '\0' */ + if (SECUREC_MEMORY_NO_OVERLAP(strDest, strSrc, srcStrLen)) { + /* Performance optimization srcStrLen include '\0' */ + SECUREC_STRCPY_OPT(strDest, strSrc, srcStrLen); + return EOK; + } else { + strDest[0] = '\0'; + SECUREC_ERROR_BUFFER_OVERLAP("strcpy_s"); + return EOVERLAP_AND_RESET; + } + } } - } - return strcpy_error(strDest, destMax, strSrc); + return strcpy_error(strDest, destMax, strSrc); } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(strcpy_s); #endif + diff --git a/project/app/wifi_app/hisi_tools/securec/strncat_s.c b/project/app/wifi_app/hisi_tools/securec/strncat_s.c index a62a12679..ef746b985 100644 --- a/project/app/wifi_app/hisi_tools/securec/strncat_s.c +++ b/project/app/wifi_app/hisi_tools/securec/strncat_s.c @@ -10,53 +10,52 @@ /* * Befor this function, the basic parameter checking has been done */ -SECUREC_INLINE errno_t SecDoCatLimit(char *strDest, size_t destMax, - const char *strSrc, size_t count) { - size_t destLen; - size_t srcLen; - SECUREC_CALC_STR_LEN(strDest, destMax, &destLen); - /* - * The strSrc is no longer optimized. The reason is that when count is small, - * the efficiency of strnlen is higher than that of self realization. - */ - SECUREC_CALC_STR_LEN(strSrc, count, &srcLen); +SECUREC_INLINE errno_t SecDoCatLimit(char *strDest, size_t destMax, const char *strSrc, size_t count) +{ + size_t destLen; + size_t srcLen; + SECUREC_CALC_STR_LEN(strDest, destMax, &destLen); + /* + * The strSrc is no longer optimized. The reason is that when count is small, + * the efficiency of strnlen is higher than that of self realization. + */ + SECUREC_CALC_STR_LEN(strSrc, count, &srcLen); - if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) { - strDest[0] = '\0'; - if (strDest + destLen <= strSrc && destLen == destMax) { - SECUREC_ERROR_INVALID_PARAMTER("strncat_s"); - return EINVAL_AND_RESET; + if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) { + strDest[0] = '\0'; + if (strDest + destLen <= strSrc && destLen == destMax) { + SECUREC_ERROR_INVALID_PARAMTER("strncat_s"); + return EINVAL_AND_RESET; + } + SECUREC_ERROR_BUFFER_OVERLAP("strncat_s"); + return EOVERLAP_AND_RESET; } - SECUREC_ERROR_BUFFER_OVERLAP("strncat_s"); - return EOVERLAP_AND_RESET; - } - if (srcLen + destLen >= destMax || strDest == strSrc) { - strDest[0] = '\0'; - if (destLen == destMax) { - SECUREC_ERROR_INVALID_PARAMTER("strncat_s"); - return EINVAL_AND_RESET; + if (srcLen + destLen >= destMax || strDest == strSrc) { + strDest[0] = '\0'; + if (destLen == destMax) { + SECUREC_ERROR_INVALID_PARAMTER("strncat_s"); + return EINVAL_AND_RESET; + } + SECUREC_ERROR_INVALID_RANGE("strncat_s"); + return ERANGE_AND_RESET; } - SECUREC_ERROR_INVALID_RANGE("strncat_s"); - return ERANGE_AND_RESET; - } - SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, - srcLen); /* No terminator */ - *(strDest + destLen + srcLen) = '\0'; - return EOK; + SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, srcLen); /* No terminator */ + *(strDest + destLen + srcLen) = '\0'; + return EOK; } /* * * The strncat_s function appends not more than n successive characters * (not including the terminating null character) - * from the array pointed to by strSrc to the end of the string pointed to - * by strDest The strncat_s function try to append the first D characters of - * strSrc to the end of strDest, where D is the lesser of count and the length - * of strSrc. If appending those D characters will fit within strDest (whose - * size is given as destMax) and still leave room for a null terminator, then - * those characters are appended, starting at the original terminating null of - * strDest, and a new terminating null is appended; otherwise, strDest[0] is set - * to the null character. + * from the array pointed to by strSrc to the end of the string pointed to by strDest + * The strncat_s function try to append the first D characters of strSrc to + * the end of strDest, where D is the lesser of count and the length of strSrc. + * If appending those D characters will fit within strDest (whose size is given + * as destMax) and still leave room for a null terminator, then those characters + * are appended, starting at the original terminating null of strDest, and a + * new terminating null is appended; otherwise, strDest[0] is set to the null + * character. * * * strDest Null-terminated destination string. @@ -69,47 +68,45 @@ SECUREC_INLINE errno_t SecDoCatLimit(char *strDest, size_t destMax, * * * EOK Success - * EINVAL strDest is NULL and destMax != 0 and destMax <= - * SECUREC_STRING_MAX_LEN EINVAL_AND_RESET (strDest unterminated and all - * other parameters are valid)or (strDest != NULL and strSrc is NULL and - * destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN) ERANGE destMax is 0 and - * destMax > SECUREC_STRING_MAX_LEN ERANGE_AND_RESET strDest have not - * enough space and all other parameters are valid and not overlap - * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all - * parameters are valid + * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN + * EINVAL_AND_RESET (strDest unterminated and all other parameters are valid)or + * (strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN) + * ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN + * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap + * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, - size_t count) { - if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) { - SECUREC_ERROR_INVALID_RANGE("strncat_s"); - return ERANGE; - } +errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count) +{ + if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) { + SECUREC_ERROR_INVALID_RANGE("strncat_s"); + return ERANGE; + } - if (strDest == NULL || strSrc == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("strncat_s"); - if (strDest != NULL) { - strDest[0] = '\0'; - return EINVAL_AND_RESET; - } - return EINVAL; - } - if (count > SECUREC_STRING_MAX_LEN) { -#ifdef SECUREC_COMPATIBLE_WIN_FORMAT - if (count == (size_t)(-1)) { - /* Windows internal functions may pass in -1 when calling this function */ - return SecDoCatLimit(strDest, destMax, strSrc, destMax); + if (strDest == NULL || strSrc == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("strncat_s"); + if (strDest != NULL) { + strDest[0] = '\0'; + return EINVAL_AND_RESET; + } + return EINVAL; } + if (count > SECUREC_STRING_MAX_LEN) { +#ifdef SECUREC_COMPATIBLE_WIN_FORMAT + if (count == (size_t)(-1)) { + /* Windows internal functions may pass in -1 when calling this function */ + return SecDoCatLimit(strDest, destMax, strSrc, destMax); + } #endif - strDest[0] = '\0'; - SECUREC_ERROR_INVALID_RANGE("strncat_s"); - return ERANGE_AND_RESET; - } - return SecDoCatLimit(strDest, destMax, strSrc, count); + strDest[0] = '\0'; + SECUREC_ERROR_INVALID_RANGE("strncat_s"); + return ERANGE_AND_RESET; + } + return SecDoCatLimit(strDest, destMax, strSrc, count); } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(strncat_s); #endif + diff --git a/project/app/wifi_app/hisi_tools/securec/strncpy_s.c b/project/app/wifi_app/hisi_tools/securec/strncpy_s.c index 7d902632a..faa697ed9 100644 --- a/project/app/wifi_app/hisi_tools/securec/strncpy_s.c +++ b/project/app/wifi_app/hisi_tools/securec/strncpy_s.c @@ -13,134 +13,124 @@ #include "securecutil.h" #if defined(SECUREC_COMPATIBLE_WIN_FORMAT) -#define SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count) \ - (((destMax) > 0 && (destMax) <= SECUREC_STRING_MAX_LEN && \ - (strDest) != NULL && (strSrc) != NULL && \ - ((count) <= SECUREC_STRING_MAX_LEN || (count) == ((size_t)(-1))) && \ - (count) > 0)) +#define SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count) \ + (((destMax) > 0 && (destMax) <= SECUREC_STRING_MAX_LEN && (strDest) != NULL && (strSrc) != NULL && \ + ((count) <= SECUREC_STRING_MAX_LEN || (count) == ((size_t)(-1))) && (count) > 0)) #else -#define SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count) \ - (((destMax) > 0 && (destMax) <= SECUREC_STRING_MAX_LEN && \ - (strDest) != NULL && (strSrc) != NULL && \ +#define SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count) \ + (((destMax) > 0 && (destMax) <= SECUREC_STRING_MAX_LEN && (strDest) != NULL && (strSrc) != NULL && \ (count) <= SECUREC_STRING_MAX_LEN && (count) > 0)) #endif /* * Check Src Count Range */ -SECUREC_INLINE errno_t CheckSrcCountRange(char *strDest, size_t destMax, - const char *strSrc, size_t count) { - size_t tmpDestMax = destMax; - size_t tmpCount = count; - const char *endPos = strSrc; +SECUREC_INLINE errno_t CheckSrcCountRange(char *strDest, size_t destMax, const char *strSrc, size_t count) +{ + size_t tmpDestMax = destMax; + size_t tmpCount = count; + const char *endPos = strSrc; - /* Use destMax and count as boundary checker and destMax must be greater than - * zero */ - while (*(endPos) != '\0' && tmpDestMax > 0 && tmpCount > 0) { - ++endPos; - --tmpCount; - --tmpDestMax; - } - if (tmpDestMax == 0) { - strDest[0] = '\0'; - SECUREC_ERROR_INVALID_RANGE("strncpy_s"); - return ERANGE_AND_RESET; - } - return EOK; + /* Use destMax and count as boundary checker and destMax must be greater than zero */ + while (*(endPos) != '\0' && tmpDestMax > 0 && tmpCount > 0) { + ++endPos; + --tmpCount; + --tmpDestMax; + } + if (tmpDestMax == 0) { + strDest[0] = '\0'; + SECUREC_ERROR_INVALID_RANGE("strncpy_s"); + return ERANGE_AND_RESET; + } + return EOK; } /* * Handling errors, when dest euqal src return EOK */ -errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, - size_t count) { - if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) { - SECUREC_ERROR_INVALID_RANGE("strncpy_s"); - return ERANGE; - } else if (strDest == NULL || strSrc == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("strncpy_s"); - if (strDest != NULL) { - strDest[0] = '\0'; - return EINVAL_AND_RESET; +errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count) +{ + if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) { + SECUREC_ERROR_INVALID_RANGE("strncpy_s"); + return ERANGE; + } else if (strDest == NULL || strSrc == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("strncpy_s"); + if (strDest != NULL) { + strDest[0] = '\0'; + return EINVAL_AND_RESET; + } + return EINVAL; + } else if (count > SECUREC_STRING_MAX_LEN) { + strDest[0] = '\0'; /* Clear dest string */ + SECUREC_ERROR_INVALID_RANGE("strncpy_s"); + return ERANGE_AND_RESET; + } else if (count == 0) { + strDest[0] = '\0'; + return EOK; } - return EINVAL; - } else if (count > SECUREC_STRING_MAX_LEN) { - strDest[0] = '\0'; /* Clear dest string */ - SECUREC_ERROR_INVALID_RANGE("strncpy_s"); - return ERANGE_AND_RESET; - } else if (count == 0) { - strDest[0] = '\0'; - return EOK; - } - return CheckSrcCountRange(strDest, destMax, strSrc, count); + return CheckSrcCountRange(strDest, destMax, strSrc, count); } /* * - * The strncpy_s function copies not more than n successive characters (not - * including the terminating null character) from the array pointed to by strSrc - * to the array pointed to by strDest. + * The strncpy_s function copies not more than n successive characters (not including the terminating null character) + * from the array pointed to by strSrc to the array pointed to by strDest. * * * strDest Destination string. - * destMax The size of the destination string, in - * characters. strSrc Source string. count Number of - * characters to be copied. + * destMax The size of the destination string, in characters. + * strSrc Source string. + * count Number of characters to be copied. * * * strDest is updated * * * EOK Success - * EINVAL strDest is NULL and destMax != 0 and - * destMax <= SECUREC_STRING_MAX_LEN EINVAL_AND_RESET strDest != NULL and - * strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN ERANGE - * destMax is 0 and destMax > SECUREC_STRING_MAX_LEN ERANGE_AND_RESET strDest - * have not enough space and all other parameters are valid and not overlap - * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all - * parameters are valid + * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN + * EINVAL_AND_RESET strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN + * ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN + * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap + * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, - size_t count) { - if (SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count)) { - size_t minCpLen; /* Use it to store the maxi length limit */ - if (count < destMax) { - SECUREC_CALC_STR_LEN(strSrc, count, &minCpLen); /* No ending terminator */ - } else { - size_t tmpCount = destMax; -#ifdef SECUREC_COMPATIBLE_WIN_FORMAT - if (count == ((size_t)(-1))) { - tmpCount = destMax - 1; - } +errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count) +{ + if (SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count)) { + size_t minCpLen; /* Use it to store the maxi length limit */ + if (count < destMax) { + SECUREC_CALC_STR_LEN(strSrc, count, &minCpLen); /* No ending terminator */ + } else { + size_t tmpCount = destMax; +#ifdef SECUREC_COMPATIBLE_WIN_FORMAT + if (count == ((size_t)(-1))) { + tmpCount = destMax - 1; + } #endif - SECUREC_CALC_STR_LEN(strSrc, tmpCount, - &minCpLen); /* No ending terminator */ - if (minCpLen == destMax) { - strDest[0] = '\0'; - SECUREC_ERROR_INVALID_RANGE("strncpy_s"); - return ERANGE_AND_RESET; - } + SECUREC_CALC_STR_LEN(strSrc, tmpCount, &minCpLen); /* No ending terminator */ + if (minCpLen == destMax) { + strDest[0] = '\0'; + SECUREC_ERROR_INVALID_RANGE("strncpy_s"); + return ERANGE_AND_RESET; + } + } + if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, minCpLen) || strDest == strSrc) { + /* Not overlap */ + SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, minCpLen); /* Copy string without terminator */ + strDest[minCpLen] = '\0'; + return EOK; + } else { + strDest[0] = '\0'; + SECUREC_ERROR_BUFFER_OVERLAP("strncpy_s"); + return EOVERLAP_AND_RESET; + } } - if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, minCpLen) || - strDest == strSrc) { - /* Not overlap */ - SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, - minCpLen); /* Copy string without terminator */ - strDest[minCpLen] = '\0'; - return EOK; - } else { - strDest[0] = '\0'; - SECUREC_ERROR_BUFFER_OVERLAP("strncpy_s"); - return EOVERLAP_AND_RESET; - } - } - return strncpy_error(strDest, destMax, strSrc, count); + return strncpy_error(strDest, destMax, strSrc, count); } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(strncpy_s); #endif + diff --git a/project/app/wifi_app/hisi_tools/securec/strtok_s.c b/project/app/wifi_app/hisi_tools/securec/strtok_s.c index afea2e80d..3e740175e 100644 --- a/project/app/wifi_app/hisi_tools/securec/strtok_s.c +++ b/project/app/wifi_app/hisi_tools/securec/strtok_s.c @@ -7,103 +7,106 @@ #include "securecutil.h" -SECUREC_INLINE int SecIsInDelimit(char ch, const char *strDelimit) { - const char *ctl = strDelimit; - while (*ctl != '\0' && *ctl != ch) { - ++ctl; - } - return (int)(*ctl != '\0'); + +SECUREC_INLINE int SecIsInDelimit(char ch, const char *strDelimit) +{ + const char *ctl = strDelimit; + while (*ctl != '\0' && *ctl != ch) { + ++ctl; + } + return (int)(*ctl != '\0'); } /* * Find beginning of token (skip over leading delimiters). - * Note that there is no token if this loop sets string to point to the terminal - * null. + * Note that there is no token if this loop sets string to point to the terminal null. */ -SECUREC_INLINE char *SecFindBegin(char *strToken, const char *strDelimit) { - char *token = strToken; - while (*token != '\0') { - if (SecIsInDelimit(*token, strDelimit)) { - ++token; - continue; +SECUREC_INLINE char *SecFindBegin(char *strToken, const char *strDelimit) +{ + char *token = strToken; + while (*token != '\0') { + if (SecIsInDelimit(*token, strDelimit)) { + ++token; + continue; + } + /* Don't find any delimiter in string header, break the loop */ + break; } - /* Don't find any delimiter in string header, break the loop */ - break; - } - return token; + return token; } /* * Find rest of token */ -SECUREC_INLINE char *SecFindRest(char *strToken, const char *strDelimit) { - /* Find the rest of the token. If it is not the end of the string, put a null - * there */ - char *token = strToken; - while (*token != '\0') { - if (SecIsInDelimit(*token, strDelimit)) { - /* Find a delimiter, set string termintor */ - *token = '\0'; - ++token; - break; +SECUREC_INLINE char *SecFindRest(char *strToken, const char *strDelimit) +{ + /* Find the rest of the token. If it is not the end of the string, put a null there */ + char *token = strToken; + while (*token != '\0') { + if (SecIsInDelimit(*token, strDelimit)) { + /* Find a delimiter, set string termintor */ + *token = '\0'; + ++token; + break; + } + ++token; } - ++token; - } - return token; + return token; } /* * Find the final position pointer */ -SECUREC_INLINE char *SecUpdateToken(char *strToken, const char *strDelimit, - char **context) { - /* Point to updated position */ - char *token = SecFindRest(strToken, strDelimit); - /* Record string position for next search in the context */ - *context = token; - /* Determine if a token has been found. */ - if (token == strToken) { - return NULL; - } - return strToken; +SECUREC_INLINE char *SecUpdateToken(char *strToken, const char *strDelimit, char **context) +{ + /* Point to updated position */ + char *token = SecFindRest(strToken, strDelimit); + /* Record string position for next search in the context */ + *context = token; + /* Determine if a token has been found. */ + if (token == strToken) { + return NULL; + } + return strToken; } /* * * The strtok_s function parses a string into a sequence of strToken, - * replace all characters in strToken string that match to strDelimit set - * with 0. On the first call to strtok_s the string to be parsed should be - * specified in strToken. In each subsequent call that should parse the same - * string, strToken should be NULL strToken String - * containing token or tokens. strDelimit Set of delimiter characters. + * replace all characters in strToken string that match to strDelimit set with 0. + * On the first call to strtok_s the string to be parsed should be specified in strToken. + * In each subsequent call that should parse the same string, strToken should be NULL + * + * strToken String containing token or tokens. + * strDelimit Set of delimiter characters. * context Used to store position information between calls * to strtok_s * * context is updated * - * On the first call returns the address of the first non \0 character, - * otherwise NULL is returned. In subsequent calls, the strtoken is set to NULL, - * and the context set is the same as the previous call, return NULL if the - * *context string length is equal 0, otherwise return *context. + * On the first call returns the address of the first non \0 character, otherwise NULL is returned. + * In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call, + * return NULL if the *context string length is equal 0, otherwise return *context. */ -char *strtok_s(char *strToken, const char *strDelimit, char **context) { - char *orgToken = strToken; - /* Validate delimiter and string context */ - if (context == NULL || strDelimit == NULL) { - return NULL; - } - /* Valid input string and string pointer from where to search */ - if (orgToken == NULL && *context == NULL) { - return NULL; - } - /* If string is null, continue searching from previous string position stored - * in context */ - if (orgToken == NULL) { - orgToken = *context; - } - orgToken = SecFindBegin(orgToken, strDelimit); - return SecUpdateToken(orgToken, strDelimit, context); +char *strtok_s(char *strToken, const char *strDelimit, char **context) +{ + char *orgToken = strToken; + /* Validate delimiter and string context */ + if (context == NULL || strDelimit == NULL) { + return NULL; + } + /* Valid input string and string pointer from where to search */ + if (orgToken == NULL && *context == NULL) { + return NULL; + } + /* If string is null, continue searching from previous string position stored in context */ + if (orgToken == NULL) { + orgToken = *context; + } + orgToken = SecFindBegin(orgToken, strDelimit); + return SecUpdateToken(orgToken, strDelimit, context); } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(strtok_s); #endif + diff --git a/project/app/wifi_app/hisi_tools/securec/swprintf_s.c b/project/app/wifi_app/hisi_tools/securec/swprintf_s.c index 086aa4f18..3781b338c 100644 --- a/project/app/wifi_app/hisi_tools/securec/swprintf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/swprintf_s.c @@ -9,8 +9,7 @@ /* * - * The swprintf_s function is the wide-character equivalent of the - * sprintf_s function + * The swprintf_s function is the wide-character equivalent of the sprintf_s function * * * strDest Storage location for the output. @@ -22,21 +21,22 @@ * strDest is updated * * - * return the number of wide characters stored in strDest, not counting the - * terminating null wide character. return -1 if an error occurred. + * return the number of wide characters stored in strDest, not counting the terminating null wide character. + * return -1 if an error occurred. * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...) { - int ret; /* If initialization causes e838 */ - va_list argList; +int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...) +{ + int ret; /* If initialization causes e838 */ + va_list argList; - va_start(argList, format); - ret = vswprintf_s(strDest, destMax, format, argList); - va_end(argList); - (void)argList; /* To clear e438 last value assigned not used , the compiler - will optimize this code */ + va_start(argList, format); + ret = vswprintf_s(strDest, destMax, format, argList); + va_end(argList); + (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */ - return ret; + return ret; } + + diff --git a/project/app/wifi_app/hisi_tools/securec/swscanf_s.c b/project/app/wifi_app/hisi_tools/securec/swscanf_s.c index f1841586b..cd0f474d5 100644 --- a/project/app/wifi_app/hisi_tools/securec/swscanf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/swscanf_s.c @@ -9,13 +9,13 @@ /* * - * The swscanf_s function is the wide-character equivalent of the - * sscanf_s function The swscanf_s function reads data from buffer into the - * location given by each argument. Every argument must be a pointer to a - * variable with a type that corresponds to a type specifier in format. The - * format argument controls the interpretation of the input fields and has the - * same form and function as the format argument for the scanf function. If - * copying takes place between strings that overlap, the behavior is undefined. + * The swscanf_s function is the wide-character equivalent of the sscanf_s function + * The swscanf_s function reads data from buffer into the location given by + * each argument. Every argument must be a pointer to a variable with a type + * that corresponds to a type specifier in format. The format argument controls + * the interpretation of the input fields and has the same form and function + * as the format argument for the scanf function. If copying takes place between + * strings that overlap, the behavior is undefined. * * * buffer Stored data. @@ -26,20 +26,23 @@ * ... the converted value stored in user assigned address * * - * Each of these functions returns the number of fields successfully - * converted and assigned; The return value does not include fields that were - * read but not assigned. A return value of 0 indicates that no fields were - * assigned. return -1 if an error occurs. + * Each of these functions returns the number of fields successfully converted + * and assigned; The return value does not include fields that were read but not + * assigned. + * A return value of 0 indicates that no fields were assigned. + * return -1 if an error occurs. */ -int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...) { - int ret; /* If initialization causes e838 */ - va_list argList; +int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...) +{ + int ret; /* If initialization causes e838 */ + va_list argList; - va_start(argList, format); - ret = vswscanf_s(buffer, format, argList); - va_end(argList); - (void)argList; /* To clear e438 last value assigned not used , the compiler - will optimize this code */ + va_start(argList, format); + ret = vswscanf_s(buffer, format, argList); + va_end(argList); + (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */ - return ret; + return ret; } + + diff --git a/project/app/wifi_app/hisi_tools/securec/vfscanf_s.c b/project/app/wifi_app/hisi_tools/securec/vfscanf_s.c index ed2e98f5d..9374beecc 100644 --- a/project/app/wifi_app/hisi_tools/securec/vfscanf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/vfscanf_s.c @@ -10,12 +10,12 @@ /* * - * The vfscanf_s function is equivalent to fscanf_s, with the variable - * argument list replaced by argList The vfscanf_s function reads data from the - * current position of stream into the locations given by argument (if any). - * Each argument must be a pointer to a variable of a type that corresponds to a - * type specifier in format. format controls the interpretation of the input - * fields and has the same form and function as the format argument for scanf. + * The vfscanf_s function is equivalent to fscanf_s, with the variable argument list replaced by argList + * The vfscanf_s function reads data from the current position of stream into + * the locations given by argument (if any). Each argument must be a pointer + * to a variable of a type that corresponds to a type specifier in format. + * format controls the interpretation of the input fields and has the same + * form and function as the format argument for scanf. * * * stream Pointer to FILE structure. @@ -26,31 +26,34 @@ * argList the converted value stored in user assigned address * * - * Each of these functions returns the number of fields successfully - * converted and assigned; the return value does not include fields that were - * read but not assigned. A return value of 0 indicates that no fields were - * assigned. return -1 if an error occurs. + * Each of these functions returns the number of fields successfully converted + * and assigned; the return value does not include fields that were read but + * not assigned. A return value of 0 indicates that no fields were assigned. + * return -1 if an error occurs. */ -int vfscanf_s(FILE *stream, const char *format, va_list argList) { - int retVal; /* If initialization causes e838 */ - SecFileStream fStr; +int vfscanf_s(FILE *stream, const char *format, va_list argList) +{ + int retVal; /* If initialization causes e838 */ + SecFileStream fStr; - if (stream == NULL || format == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("vfscanf_s"); - return SECUREC_SCANF_EINVAL; - } - if (stream == SECUREC_STREAM_STDIN) { - return vscanf_s(format, argList); - } + if (stream == NULL || format == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("vfscanf_s"); + return SECUREC_SCANF_EINVAL; + } + if (stream == SECUREC_STREAM_STDIN) { + return vscanf_s(format, argList); + } - SECUREC_LOCK_FILE(stream); - SecInitFileStreamFromFile(&fStr, stream); - retVal = SecInputS(&fStr, format, argList); - SECUREC_UNLOCK_FILE(stream); - if (retVal < 0) { - SECUREC_ERROR_INVALID_PARAMTER("vfscanf_s"); - return SECUREC_SCANF_EINVAL; - } + SECUREC_LOCK_FILE(stream); + SecInitFileStreamFromFile(&fStr, stream); + retVal = SecInputS(&fStr, format, argList); + SECUREC_UNLOCK_FILE(stream); + if (retVal < 0) { + SECUREC_ERROR_INVALID_PARAMTER("vfscanf_s"); + return SECUREC_SCANF_EINVAL; + } - return retVal; + return retVal; } + + diff --git a/project/app/wifi_app/hisi_tools/securec/vfwscanf_s.c b/project/app/wifi_app/hisi_tools/securec/vfwscanf_s.c index 71319982e..7e478a880 100644 --- a/project/app/wifi_app/hisi_tools/securec/vfwscanf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/vfwscanf_s.c @@ -10,12 +10,12 @@ /* * - * The vfwscanf_s function is the wide-character equivalent of the - * vfscanf_s function The vfwscanf_s function reads data from the current - * position of stream into the locations given by argument (if any). Each - * argument must be a pointer to a variable of a type that corresponds to a type - * specifier in format. format controls the interpretation of the input fields - * and has the same form and function as the format argument for scanf. + * The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function + * The vfwscanf_s function reads data from the current position of stream into + * the locations given by argument (if any). Each argument must be a pointer + * to a variable of a type that corresponds to a type specifier in format. + * format controls the interpretation of the input fields and has the same form + * and function as the format argument for scanf. * * * stream Pointer to FILE structure. @@ -26,30 +26,33 @@ * argList the converted value stored in user assigned address * * - * Each of these functions returns the number of fields successfully - * converted and assigned; the return value does not include fields that were - * read but not assigned. A return value of 0 indicates that no fields were - * assigned. return -1 if an error occurs. + * Each of these functions returns the number of fields successfully converted + * and assigned; the return value does not include fields that were read but + * not assigned. A return value of 0 indicates that no fields were assigned. + * return -1 if an error occurs. */ -int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList) { - int retVal; /* If initialization causes e838 */ - SecFileStream fStr; +int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList) +{ + int retVal; /* If initialization causes e838 */ + SecFileStream fStr; - if (stream == NULL || format == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s"); - return SECUREC_SCANF_EINVAL; - } - if (stream == SECUREC_STREAM_STDIN) { - return vwscanf_s(format, argList); - } + if (stream == NULL || format == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s"); + return SECUREC_SCANF_EINVAL; + } + if (stream == SECUREC_STREAM_STDIN) { + return vwscanf_s(format, argList); + } - SECUREC_LOCK_FILE(stream); - SecInitFileStreamFromFile(&fStr, stream); - retVal = SecInputSW(&fStr, format, argList); - SECUREC_UNLOCK_FILE(stream); - if (retVal < 0) { - SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s"); - return SECUREC_SCANF_EINVAL; - } - return retVal; + SECUREC_LOCK_FILE(stream); + SecInitFileStreamFromFile(&fStr, stream); + retVal = SecInputSW(&fStr, format, argList); + SECUREC_UNLOCK_FILE(stream); + if (retVal < 0) { + SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s"); + return SECUREC_SCANF_EINVAL; + } + return retVal; } + + diff --git a/project/app/wifi_app/hisi_tools/securec/vscanf_s.c b/project/app/wifi_app/hisi_tools/securec/vscanf_s.c index a58403751..bc5968e98 100644 --- a/project/app/wifi_app/hisi_tools/securec/vscanf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/vscanf_s.c @@ -10,12 +10,12 @@ /* * - * The vscanf_s function is equivalent to scanf_s, with the variable - * argument list replaced by argList, The vscanf_s function reads data from the - * standard input stream stdin and writes the data into the location that's - * given by argument. Each argument must be a pointer to a variable of a type - * that corresponds to a type specifier in format. If copying occurs between - * strings that overlap, the behavior is undefined. + * The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList, + * The vscanf_s function reads data from the standard input stream stdin and + * writes the data into the location that's given by argument. Each argument + * must be a pointer to a variable of a type that corresponds to a type specifier + * in format. If copying occurs between strings that overlap, the behavior is + * undefined. * * * format Format control string. @@ -30,29 +30,31 @@ * A return value of 0 indicates that no fields were assigned. * return -1 if an error occurs. */ -int vscanf_s(const char *format, va_list argList) { - int retVal; /* If initialization causes e838 */ - SecFileStream fStr; - SecInitFileStreamFromStdin(&fStr); - /* - * The "va_list" has different definition on different platform, so we can't - * use argList == NULL To determine it's invalid. If you has fixed platform, - * you can check some fields to validate it, such as "argList == NULL" or - * argList.xxx != NULL or *(size_t *)&argList != 0. - */ - if (format == NULL || fStr.pf == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("vscanf_s"); - return SECUREC_SCANF_EINVAL; - } +int vscanf_s(const char *format, va_list argList) +{ + int retVal; /* If initialization causes e838 */ + SecFileStream fStr; + SecInitFileStreamFromStdin(&fStr); + /* + * The "va_list" has different definition on different platform, so we can't use argList == NULL + * To determine it's invalid. If you has fixed platform, you can check some fields to validate it, + * such as "argList == NULL" or argList.xxx != NULL or *(size_t *)&argList != 0. + */ + if (format == NULL || fStr.pf == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("vscanf_s"); + return SECUREC_SCANF_EINVAL; + } - SECUREC_LOCK_STDIN(0, fStr.pf); + SECUREC_LOCK_STDIN(0, fStr.pf); - retVal = SecInputS(&fStr, format, argList); + retVal = SecInputS(&fStr, format, argList); - SECUREC_UNLOCK_STDIN(0, fStr.pf); - if (retVal < 0) { - SECUREC_ERROR_INVALID_PARAMTER("vscanf_s"); - return SECUREC_SCANF_EINVAL; - } - return retVal; + SECUREC_UNLOCK_STDIN(0, fStr.pf); + if (retVal < 0) { + SECUREC_ERROR_INVALID_PARAMTER("vscanf_s"); + return SECUREC_SCANF_EINVAL; + } + return retVal; } + + diff --git a/project/app/wifi_app/hisi_tools/securec/vsnprintf_s.c b/project/app/wifi_app/hisi_tools/securec/vsnprintf_s.c index 7676d3de6..bc468e8b3 100644 --- a/project/app/wifi_app/hisi_tools/securec/vsnprintf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/vsnprintf_s.c @@ -11,69 +11,67 @@ /* * * The vsnprintf_s function is equivalent to the vsnprintf function - * except for the parameter destMax/count and the explicit - * runtime-constraints violation The vsnprintf_s function takes a pointer to an - * argument list, then formats and writes up to count characters of the given - * data to the memory pointed to by strDest and appends a terminating null. + * except for the parameter destMax/count and the explicit runtime-constraints violation + * The vsnprintf_s function takes a pointer to an argument list, then formats + * and writes up to count characters of the given data to the memory pointed + * to by strDest and appends a terminating null. * * * strDest Storage location for the output. * destMax The size of the strDest for output. - * count Maximum number of character to write(not - * including the terminating NULL) format Format-control - * string. argList pointer to list of arguments. + * count Maximum number of character to write(not including + * the terminating NULL) + * format Format-control string. + * argList pointer to list of arguments. * * * strDest is updated * * - * return the number of characters written, not including the terminating - * null return -1 if an error occurs. return -1 if count < destMax and the - * output string has been truncated + * return the number of characters written, not including the terminating null + * return -1 if an error occurs. + * return -1 if count < destMax and the output string has been truncated * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format, - va_list argList) { - int retVal; +int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format, va_list argList) +{ + int retVal; - if (SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, - SECUREC_STRING_MAX_LEN)) { - SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN); - SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_s"); - return -1; - } - - if (destMax > count) { - retVal = SecVsnprintfImpl(strDest, count + 1, format, argList); - if (retVal == SECUREC_PRINTF_TRUNCATE) { /* To keep dest buffer not - destroyed 2014.2.18 */ - /* The string has been truncated, return -1 */ - return -1; /* To skip error handler, return strlen(strDest) or -1 */ + if (SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, SECUREC_STRING_MAX_LEN)) { + SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN); + SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_s"); + return -1; } - } else { - retVal = SecVsnprintfImpl(strDest, destMax, format, argList); + + if (destMax > count) { + retVal = SecVsnprintfImpl(strDest, count + 1, format, argList); + if (retVal == SECUREC_PRINTF_TRUNCATE) { /* To keep dest buffer not destroyed 2014.2.18 */ + /* The string has been truncated, return -1 */ + return -1; /* To skip error handler, return strlen(strDest) or -1 */ + } + } else { + retVal = SecVsnprintfImpl(strDest, destMax, format, argList); #ifdef SECUREC_COMPATIBLE_WIN_FORMAT - if (retVal == SECUREC_PRINTF_TRUNCATE && count == (size_t)(-1)) { - return -1; - } + if (retVal == SECUREC_PRINTF_TRUNCATE && count == (size_t)(-1)) { + return -1; + } #endif - } - - if (retVal < 0) { - strDest[0] = '\0'; /* Empty the dest strDest */ - - if (retVal == SECUREC_PRINTF_TRUNCATE) { - /* Buffer too small */ - SECUREC_ERROR_INVALID_RANGE("vsnprintf_s"); } - SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_s"); - return -1; - } + if (retVal < 0) { + strDest[0] = '\0'; /* Empty the dest strDest */ - return retVal; + if (retVal == SECUREC_PRINTF_TRUNCATE) { + /* Buffer too small */ + SECUREC_ERROR_INVALID_RANGE("vsnprintf_s"); + } + + SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_s"); + return -1; + } + + return retVal; } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(vsnprintf_s); @@ -84,11 +82,10 @@ EXPORT_SYMBOL(vsnprintf_s); /* * * The vsnprintf_truncated_s function is equivalent to the vsnprintf function - * except for the parameter destMax/count and the explicit - * runtime-constraints violation The vsnprintf_truncated_s function takes a - * pointer to an argument list, then formats and writes up to count characters - * of the given data to the memory pointed to by strDest and appends a - * terminating null. + * except for the parameter destMax/count and the explicit runtime-constraints violation + * The vsnprintf_truncated_s function takes a pointer to an argument list, then formats + * and writes up to count characters of the given data to the memory pointed + * to by strDest and appends a terminating null. * * * strDest Storage location for the output. @@ -101,38 +98,37 @@ EXPORT_SYMBOL(vsnprintf_s); * strDest is updated * * - * return the number of characters written, not including the terminating - * null return -1 if an error occurs. return destMax-1 if output string has - * been truncated + * return the number of characters written, not including the terminating null + * return -1 if an error occurs. + * return destMax-1 if output string has been truncated * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format, - va_list argList) { - int retVal; +int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format, va_list argList) +{ + int retVal; - if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, - SECUREC_STRING_MAX_LEN)) { - SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN); - SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_truncated_s"); - return -1; - } - - retVal = SecVsnprintfImpl(strDest, destMax, format, argList); - if (retVal < 0) { - if (retVal == SECUREC_PRINTF_TRUNCATE) { - return (int)(destMax - - 1); /* To skip error handler, return strlen(strDest) */ + if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_STRING_MAX_LEN)) { + SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN); + SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_truncated_s"); + return -1; } - strDest[0] = '\0'; /* Empty the dest strDest */ - SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_truncated_s"); - return -1; - } - return retVal; + retVal = SecVsnprintfImpl(strDest, destMax, format, argList); + if (retVal < 0) { + if (retVal == SECUREC_PRINTF_TRUNCATE) { + return (int)(destMax - 1); /* To skip error handler, return strlen(strDest) */ + } + strDest[0] = '\0'; /* Empty the dest strDest */ + SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_truncated_s"); + return -1; + } + + return retVal; } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(vsnprintf_truncated_s); #endif #endif + + diff --git a/project/app/wifi_app/hisi_tools/securec/vsprintf_s.c b/project/app/wifi_app/hisi_tools/securec/vsprintf_s.c index c74f530c7..e54a7ed16 100644 --- a/project/app/wifi_app/hisi_tools/securec/vsprintf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/vsprintf_s.c @@ -10,9 +10,9 @@ /* * * The vsprintf_s function is equivalent to the vsprintf function - * except for the parameter destMax and the explicit runtime-constraints - * violation The vsprintf_s function takes a pointer to an argument list, and - * then formats and writes the given data to the memory pointed to by strDest. + * except for the parameter destMax and the explicit runtime-constraints violation + * The vsprintf_s function takes a pointer to an argument list, and then formats + * and writes the given data to the memory pointed to by strDest. * The function differ from the non-secure versions only in that the secure * versions support positional parameters. * @@ -26,36 +26,36 @@ * strDest is updated * * - * return the number of characters written, not including the terminating - * null character, return -1 if an error occurs. + * return the number of characters written, not including the terminating null character, + * return -1 if an error occurs. * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -int vsprintf_s(char *strDest, size_t destMax, const char *format, - va_list argList) { - int retVal; /* If initialization causes e838 */ +int vsprintf_s(char *strDest, size_t destMax, const char *format, va_list argList) +{ + int retVal; /* If initialization causes e838 */ - if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, - SECUREC_STRING_MAX_LEN)) { - SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN); - SECUREC_ERROR_INVALID_PARAMTER("vsprintf_s"); - return -1; - } - - retVal = SecVsnprintfImpl(strDest, destMax, format, argList); - if (retVal < 0) { - strDest[0] = '\0'; - if (retVal == SECUREC_PRINTF_TRUNCATE) { - /* Buffer is too small */ - SECUREC_ERROR_INVALID_RANGE("vsprintf_s"); + if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_STRING_MAX_LEN)) { + SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN); + SECUREC_ERROR_INVALID_PARAMTER("vsprintf_s"); + return -1; } - SECUREC_ERROR_INVALID_PARAMTER("vsprintf_s"); - return -1; - } - return retVal; + retVal = SecVsnprintfImpl(strDest, destMax, format, argList); + if (retVal < 0) { + strDest[0] = '\0'; + if (retVal == SECUREC_PRINTF_TRUNCATE) { + /* Buffer is too small */ + SECUREC_ERROR_INVALID_RANGE("vsprintf_s"); + } + SECUREC_ERROR_INVALID_PARAMTER("vsprintf_s"); + return -1; + } + + return retVal; } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(vsprintf_s); #endif + + diff --git a/project/app/wifi_app/hisi_tools/securec/vsscanf_s.c b/project/app/wifi_app/hisi_tools/securec/vsscanf_s.c index ba7d44be1..e7dff1f6b 100644 --- a/project/app/wifi_app/hisi_tools/securec/vsscanf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/vsscanf_s.c @@ -7,7 +7,7 @@ #define SECUREC_INLINE_INIT_FILE_STREAM_STR 1 #include "secinput.h" -#if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL && \ +#if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL && \ (!defined(SECUREC_SYSAPI4VXWORKS) && !defined(SECUREC_CTYPE_MACRO_ADAPT)) #include #endif @@ -18,14 +18,13 @@ * * * - * The vsscanf_s function is equivalent to sscanf_s, with the variable - * argument list replaced by argList The vsscanf_s function reads data from - * buffer into the location given by each argument. Every argument must be a - * pointer to a variable with a type that corresponds to a type specifier in - * format. The format argument controls the interpretation of the input fields - * and has the same form and function as the format argument for the scanf - * function. If copying takes place between strings that overlap, the behavior - * is undefined. + * The vsscanf_s function is equivalent to sscanf_s, with the variable argument list replaced by argList + * The vsscanf_s function reads data from buffer into the location given by + * each argument. Every argument must be a pointer to a variable with a type + * that corresponds to a type specifier in format. The format argument controls + * the interpretation of the input fields and has the same form and function + * as the format argument for the scanf function. + * If copying takes place between strings that overlap, the behavior is undefined. * * * buffer Stored data @@ -36,46 +35,47 @@ * argList the converted value stored in user assigned address * * - * Each of these functions returns the number of fields successfully - * converted and assigned; the return value does not include fields that were - * read but not assigned. A return value of 0 indicates that no fields were - * assigned. return -1 if an error occurs. + * Each of these functions returns the number of fields successfully converted + * and assigned; the return value does not include fields that were read but + * not assigned. A return value of 0 indicates that no fields were assigned. + * return -1 if an error occurs. */ -int vsscanf_s(const char *buffer, const char *format, va_list argList) { - size_t count; /* If initialization causes e838 */ - int retVal; - SecFileStream fStr; +int vsscanf_s(const char *buffer, const char *format, va_list argList) +{ + size_t count; /* If initialization causes e838 */ + int retVal; + SecFileStream fStr; - /* Validation section */ - if (buffer == NULL || format == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s"); - return SECUREC_SCANF_EINVAL; - } - count = strlen(buffer); - if (count == 0 || count > SECUREC_STRING_MAX_LEN) { - SecClearDestBuf(buffer, format, argList); - SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s"); - return SECUREC_SCANF_EINVAL; - } + /* Validation section */ + if (buffer == NULL || format == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s"); + return SECUREC_SCANF_EINVAL; + } + count = strlen(buffer); + if (count == 0 || count > SECUREC_STRING_MAX_LEN) { + SecClearDestBuf(buffer, format, argList); + SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s"); + return SECUREC_SCANF_EINVAL; + } #if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL - /* - * On vxworks platform when buffer is white string, will set first %s argument - * tu zero.like following useage: " \v\f\t\r\n", "%s", str, strSize Do not - * check all character, just first and last character then consider it is - * white string - */ - if (isspace((int)buffer[0]) && isspace((int)buffer[count - 1])) { - SecClearDestBuf(buffer, format, argList); - } + /* + * On vxworks platform when buffer is white string, will set first %s argument tu zero.like following useage: + * " \v\f\t\r\n", "%s", str, strSize + * Do not check all character, just first and last character then consider it is white string + */ + if (isspace((int)buffer[0]) && isspace((int)buffer[count - 1])) { + SecClearDestBuf(buffer, format, argList); + } #endif - SecInitFileStreamFromString(&fStr, buffer, (int)count); - retVal = SecInputS(&fStr, format, argList); - if (retVal < 0) { - SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s"); - return SECUREC_SCANF_EINVAL; - } - return retVal; + SecInitFileStreamFromString(&fStr, buffer, (int)count); + retVal = SecInputS(&fStr, format, argList); + if (retVal < 0) { + SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s"); + return SECUREC_SCANF_EINVAL; + } + return retVal; } #if SECUREC_IN_KERNEL EXPORT_SYMBOL(vsscanf_s); #endif + diff --git a/project/app/wifi_app/hisi_tools/securec/vswprintf_s.c b/project/app/wifi_app/hisi_tools/securec/vswprintf_s.c index 5e01bc2f7..bd6c3ad79 100644 --- a/project/app/wifi_app/hisi_tools/securec/vswprintf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/vswprintf_s.c @@ -7,10 +7,10 @@ #include "secureprintoutput.h" + /* * - * The vswprintf_s function is the wide-character equivalent of the - * vsprintf_s function + * The vswprintf_s function is the wide-character equivalent of the vsprintf_s function * * * strDest Storage location for the output. @@ -22,32 +22,32 @@ * strDest is updated * * - * return the number of wide characters stored in strDest, not counting the - * terminating null wide character. return -1 if an error occurred. + * return the number of wide characters stored in strDest, not counting the terminating null wide character. + * return -1 if an error occurred. * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, - va_list argList) { - int retVal; /* If initialization causes e838 */ - if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, - SECUREC_WCHAR_STRING_MAX_LEN)) { - SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN); - SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s"); - return -1; - } - - retVal = SecVswprintfImpl(strDest, destMax, format, argList); - if (retVal < 0) { - strDest[0] = '\0'; - if (retVal == SECUREC_PRINTF_TRUNCATE) { - /* Buffer too small */ - SECUREC_ERROR_INVALID_RANGE("vswprintf_s"); +int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList) +{ + int retVal; /* If initialization causes e838 */ + if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN)) { + SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN); + SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s"); + return -1; } - SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s"); - return -1; - } - return retVal; + retVal = SecVswprintfImpl(strDest, destMax, format, argList); + if (retVal < 0) { + strDest[0] = '\0'; + if (retVal == SECUREC_PRINTF_TRUNCATE) { + /* Buffer too small */ + SECUREC_ERROR_INVALID_RANGE("vswprintf_s"); + } + SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s"); + return -1; + } + + return retVal; } + + diff --git a/project/app/wifi_app/hisi_tools/securec/vswscanf_s.c b/project/app/wifi_app/hisi_tools/securec/vswscanf_s.c index 141b9e568..4c6bd1297 100644 --- a/project/app/wifi_app/hisi_tools/securec/vswscanf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/vswscanf_s.c @@ -8,23 +8,24 @@ #define SECUREC_INLINE_INIT_FILE_STREAM_STR 1 #include "secinput.h" -SECUREC_INLINE size_t SecWcslen(const wchar_t *s) { - const wchar_t *end = s; - while (*end != L'\0') { - ++end; - } - return ((size_t)((end - s))); +SECUREC_INLINE size_t SecWcslen(const wchar_t *s) +{ + const wchar_t *end = s; + while (*end != L'\0') { + ++end; + } + return ((size_t)((end - s))); } /* * - * The vswscanf_s function is the wide-character equivalent of the - * vsscanf_s function The vsscanf_s function reads data from buffer into the - * location given by each argument. Every argument must be a pointer to a - * variable with a type that corresponds to a type specifier in format. The - * format argument controls the interpretation of the input fields and has the - * same form and function as the format argument for the scanf function. If - * copying takes place between strings that overlap, the behavior is undefined. + * The vswscanf_s function is the wide-character equivalent of the vsscanf_s function + * The vsscanf_s function reads data from buffer into the location given by + * each argument. Every argument must be a pointer to a variable with a type + * that corresponds to a type specifier in format. + * The format argument controls the interpretation of the input fields and + * has the same form and function as the format argument for the scanf function. + * If copying takes place between strings that overlap, the behavior is undefined. * * * buffer Stored data @@ -35,33 +36,35 @@ SECUREC_INLINE size_t SecWcslen(const wchar_t *s) { * argList the converted value stored in user assigned address * * - * Each of these functions returns the number of fields successfully - * converted and assigned; the return value does not include fields that were - * read but not assigned. A return value of 0 indicates that no fields were - * assigned. return -1 if an error occurs. + * Each of these functions returns the number of fields successfully converted + * and assigned; the return value does not include fields that were read but + * not assigned. A return value of 0 indicates that no fields were assigned. + * return -1 if an error occurs. */ -int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList) { - size_t count; /* If initialization causes e838 */ - SecFileStream fStr; - int retVal; +int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList) +{ + size_t count; /* If initialization causes e838 */ + SecFileStream fStr; + int retVal; - /* Validation section */ - if (buffer == NULL || format == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s"); - return SECUREC_SCANF_EINVAL; - } - count = SecWcslen(buffer); - if (count == 0 || count > SECUREC_WCHAR_STRING_MAX_LEN) { - SecClearDestBufW(buffer, format, argList); - SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s"); - return SECUREC_SCANF_EINVAL; - } - SecInitFileStreamFromString(&fStr, (const char *)buffer, - (int)count * ((int)sizeof(wchar_t))); - retVal = SecInputSW(&fStr, format, argList); - if (retVal < 0) { - SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s"); - return SECUREC_SCANF_EINVAL; - } - return retVal; + /* Validation section */ + if (buffer == NULL || format == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s"); + return SECUREC_SCANF_EINVAL; + } + count = SecWcslen(buffer); + if (count == 0 || count > SECUREC_WCHAR_STRING_MAX_LEN) { + SecClearDestBufW(buffer, format, argList); + SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s"); + return SECUREC_SCANF_EINVAL; + } + SecInitFileStreamFromString(&fStr, (const char *)buffer, (int)count * ((int)sizeof(wchar_t))); + retVal = SecInputSW(&fStr, format, argList); + if (retVal < 0) { + SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s"); + return SECUREC_SCANF_EINVAL; + } + return retVal; } + + diff --git a/project/app/wifi_app/hisi_tools/securec/vwscanf_s.c b/project/app/wifi_app/hisi_tools/securec/vwscanf_s.c index bc6580cf2..f3dcf83d7 100644 --- a/project/app/wifi_app/hisi_tools/securec/vwscanf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/vwscanf_s.c @@ -10,13 +10,13 @@ /* * - * The vwscanf_s function is the wide-character equivalent of the - * vscanf_s function The vwscanf_s function is the wide-character version of - * vscanf_s. The function reads data from the standard input stream stdin and - * writes the data into the location that's given by argument. Each argument - * must be a pointer to a variable of a type that corresponds to a type - * specifier in format. If copying occurs between strings that overlap, the - * behavior is undefined. + * The vwscanf_s function is the wide-character equivalent of the vscanf_s function + * The vwscanf_s function is the wide-character version of vscanf_s. The + * function reads data from the standard input stream stdin and writes the + * data into the location that's given by argument. Each argument must be a + * pointer to a variable of a type that corresponds to a type specifier in + * format. If copying occurs between strings that overlap, the behavior is + * undefined. * * * format Format control string. @@ -31,26 +31,29 @@ * A return value of 0 indicates that no fields were assigned. * return -1 if an error occurs. */ -int vwscanf_s(const wchar_t *format, va_list argList) { - int retVal; /* If initialization causes e838 */ - SecFileStream fStr; +int vwscanf_s(const wchar_t *format, va_list argList) +{ + int retVal; /* If initialization causes e838 */ + SecFileStream fStr; - SecInitFileStreamFromStdin(&fStr); - if (format == NULL || fStr.pf == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s"); - return SECUREC_SCANF_EINVAL; - } + SecInitFileStreamFromStdin(&fStr); + if (format == NULL || fStr.pf == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s"); + return SECUREC_SCANF_EINVAL; + } - SECUREC_LOCK_STDIN(0, fStr.pf); + SECUREC_LOCK_STDIN(0, fStr.pf); - retVal = SecInputSW(&fStr, format, argList); + retVal = SecInputSW(&fStr, format, argList); - SECUREC_UNLOCK_STDIN(0, fStr.pf); + SECUREC_UNLOCK_STDIN(0, fStr.pf); - if (retVal < 0) { - SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s"); - return SECUREC_SCANF_EINVAL; - } + if (retVal < 0) { + SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s"); + return SECUREC_SCANF_EINVAL; + } - return retVal; + return retVal; } + + diff --git a/project/app/wifi_app/hisi_tools/securec/wcscat_s.c b/project/app/wifi_app/hisi_tools/securec/wcscat_s.c index a0f77c1af..79ccc2d85 100644 --- a/project/app/wifi_app/hisi_tools/securec/wcscat_s.c +++ b/project/app/wifi_app/hisi_tools/securec/wcscat_s.c @@ -10,53 +10,51 @@ /* * Befor this function, the basic parameter checking has been done */ -SECUREC_INLINE errno_t SecDoCatW(wchar_t *strDest, size_t destMax, - const wchar_t *strSrc) { - size_t destLen; - size_t srcLen; - size_t maxCount; /* Store the maximum available count */ +SECUREC_INLINE errno_t SecDoCatW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) +{ + size_t destLen; + size_t srcLen; + size_t maxCount; /* Store the maximum available count */ - /* To calculate the length of a wide character, the parameter must be a wide - * character */ - SECUREC_CALC_WSTR_LEN(strDest, destMax, &destLen); - maxCount = destMax - destLen; - SECUREC_CALC_WSTR_LEN(strSrc, maxCount, &srcLen); + /* To calculate the length of a wide character, the parameter must be a wide character */ + SECUREC_CALC_WSTR_LEN(strDest, destMax, &destLen); + maxCount = destMax - destLen; + SECUREC_CALC_WSTR_LEN(strSrc, maxCount, &srcLen); - if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) { - strDest[0] = L'\0'; - if (strDest + destLen <= strSrc && destLen == destMax) { - SECUREC_ERROR_INVALID_PARAMTER("wcscat_s"); - return EINVAL_AND_RESET; + if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) { + strDest[0] = L'\0'; + if (strDest + destLen <= strSrc && destLen == destMax) { + SECUREC_ERROR_INVALID_PARAMTER("wcscat_s"); + return EINVAL_AND_RESET; + } + SECUREC_ERROR_BUFFER_OVERLAP("wcscat_s"); + return EOVERLAP_AND_RESET; } - SECUREC_ERROR_BUFFER_OVERLAP("wcscat_s"); - return EOVERLAP_AND_RESET; - } - if (srcLen + destLen >= destMax || strDest == strSrc) { - strDest[0] = L'\0'; - if (destLen == destMax) { - SECUREC_ERROR_INVALID_PARAMTER("wcscat_s"); - return EINVAL_AND_RESET; + if (srcLen + destLen >= destMax || strDest == strSrc) { + strDest[0] = L'\0'; + if (destLen == destMax) { + SECUREC_ERROR_INVALID_PARAMTER("wcscat_s"); + return EINVAL_AND_RESET; + } + SECUREC_ERROR_INVALID_RANGE("wcscat_s"); + return ERANGE_AND_RESET; } - SECUREC_ERROR_INVALID_RANGE("wcscat_s"); - return ERANGE_AND_RESET; - } - /* Copy single character length include \0 */ - SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, - (srcLen + 1) * sizeof(wchar_t)); - return EOK; + /* Copy single character length include \0 */ + SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, (srcLen + 1) * sizeof(wchar_t)); + return EOK; } /* * - * The wcscat_s function appends a copy of the wide string pointed to by - * strSrc (including the terminating null wide character) to the end of the wide - * string pointed to by strDest. The arguments and return value of wcscat_s are - * wide-character strings. + * The wcscat_s function appends a copy of the wide string pointed to by strSrc +* (including the terminating null wide character) + * to the end of the wide string pointed to by strDest. + * The arguments and return value of wcscat_s are wide-character strings. * - * The wcscat_s function appends strSrc to strDest and terminates the - * resulting string with a null character. The initial character of strSrc - * overwrites the terminating null character of strDest. wcscat_s will return - * EOVERLAP_AND_RESET if the source and destination strings overlap. + * The wcscat_s function appends strSrc to strDest and terminates the resulting + * string with a null character. The initial character of strSrc overwrites the + * terminating null character of strDest. wcscat_s will return EOVERLAP_AND_RESET if the + * source and destination strings overlap. * * Note that the second parameter is the total size of the buffer, not the * remaining size. @@ -71,32 +69,33 @@ SECUREC_INLINE errno_t SecDoCatW(wchar_t *strDest, size_t destMax, * * * EOK Success - * EINVAL strDest is NULL and destMax != 0 and destMax <= - * SECUREC_WCHAR_STRING_MAX_LEN EINVAL_AND_RESET (strDest unterminated and - * all other parameters are valid) or (strDest != NULL and strSrc is NULLL and - * destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN) ERANGE destMax > - * SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0 ERANGE_AND_RESET strDest - * have not enough space and all other parameters are valid and not overlap - * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and - * all parameters are valid + * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN + * EINVAL_AND_RESET (strDest unterminated and all other parameters are valid) or + * (strDest != NULL and strSrc is NULLL and destMax != 0 + * and destMax <= SECUREC_WCHAR_STRING_MAX_LEN) + * ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0 + * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap + * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) { - if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) { - SECUREC_ERROR_INVALID_RANGE("wcscat_s"); - return ERANGE; - } - - if (strDest == NULL || strSrc == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("wcscat_s"); - if (strDest != NULL) { - strDest[0] = L'\0'; - return EINVAL_AND_RESET; +errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) +{ + if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) { + SECUREC_ERROR_INVALID_RANGE("wcscat_s"); + return ERANGE; } - return EINVAL; - } - return SecDoCatW(strDest, destMax, strSrc); + if (strDest == NULL || strSrc == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("wcscat_s"); + if (strDest != NULL) { + strDest[0] = L'\0'; + return EINVAL_AND_RESET; + } + return EINVAL; + } + + return SecDoCatW(strDest, destMax, strSrc); } + + diff --git a/project/app/wifi_app/hisi_tools/securec/wcscpy_s.c b/project/app/wifi_app/hisi_tools/securec/wcscpy_s.c index 0cb1269dd..fa7b778c6 100644 --- a/project/app/wifi_app/hisi_tools/securec/wcscpy_s.c +++ b/project/app/wifi_app/hisi_tools/securec/wcscpy_s.c @@ -7,37 +7,35 @@ #include "securecutil.h" -SECUREC_INLINE errno_t SecDoCpyW(wchar_t *strDest, size_t destMax, - const wchar_t *strSrc) { - size_t srcStrLen; - SECUREC_CALC_WSTR_LEN(strSrc, destMax, &srcStrLen); +SECUREC_INLINE errno_t SecDoCpyW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) +{ + size_t srcStrLen; + SECUREC_CALC_WSTR_LEN(strSrc, destMax, &srcStrLen); - if (srcStrLen == destMax) { - strDest[0] = '\0'; - SECUREC_ERROR_INVALID_RANGE("wcscpy_s"); - return ERANGE_AND_RESET; - } - if (strDest == strSrc) { - return EOK; - } + if (srcStrLen == destMax) { + strDest[0] = '\0'; + SECUREC_ERROR_INVALID_RANGE("wcscpy_s"); + return ERANGE_AND_RESET; + } + if (strDest == strSrc) { + return EOK; + } - if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, srcStrLen)) { - /* Performance optimization, srcStrLen is single character length include - * '\0' */ - SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, (srcStrLen + 1) * sizeof(wchar_t)); - return EOK; - } else { - strDest[0] = L'\0'; - SECUREC_ERROR_BUFFER_OVERLAP("wcscpy_s"); - return EOVERLAP_AND_RESET; - } + if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, srcStrLen)) { + /* Performance optimization, srcStrLen is single character length include '\0' */ + SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, (srcStrLen + 1) * sizeof(wchar_t)); + return EOK; + } else { + strDest[0] = L'\0'; + SECUREC_ERROR_BUFFER_OVERLAP("wcscpy_s"); + return EOVERLAP_AND_RESET; + } } /* * * The wcscpy_s function copies the wide string pointed to by strSrc - * (including theterminating null wide character) into the array pointed to by - strDest + * (including theterminating null wide character) into the array pointed to by strDest * * strDest Destination string buffer @@ -49,38 +47,34 @@ SECUREC_INLINE errno_t SecDoCpyW(wchar_t *strDest, size_t destMax, * * * EOK Success - * EINVAL strDest is NULL and destMax != 0 and destMax <= - SECUREC_WCHAR_STRING_MAX_LEN + * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN * EINVAL_AND_RESET strDest != NULL and strSrc is NULLL and destMax != 0 * and destMax <= SECUREC_WCHAR_STRING_MAX_LEN - * ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is - 0 + * ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0 * ERANGE_AND_RESET destMax <= length of strSrc and strDest != strSrc - * and strDest != NULL and strSrc != NULL and destMax - != 0 - * and destMax <= SECUREC_WCHAR_STRING_MAX_LEN and not - overlap - * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and - destMax != 0 + * and strDest != NULL and strSrc != NULL and destMax != 0 + * and destMax <= SECUREC_WCHAR_STRING_MAX_LEN and not overlap + * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and destMax != 0 * and destMax <= SECUREC_WCHAR_STRING_MAX_LEN - * and strDest != NULL and strSrc !=NULL and strDest != - strSrc + * and strDest != NULL and strSrc !=NULL and strDest != strSrc * - * If there is a runtime-constraint violation, strDest[0] will be set to the - '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) { - if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) { - SECUREC_ERROR_INVALID_RANGE("wcscpy_s"); - return ERANGE; - } - if (strDest == NULL || strSrc == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("wcscpy_s"); - if (strDest != NULL) { - strDest[0] = L'\0'; - return EINVAL_AND_RESET; +errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) +{ + if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) { + SECUREC_ERROR_INVALID_RANGE("wcscpy_s"); + return ERANGE; } - return EINVAL; - } - return SecDoCpyW(strDest, destMax, strSrc); + if (strDest == NULL || strSrc == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("wcscpy_s"); + if (strDest != NULL) { + strDest[0] = L'\0'; + return EINVAL_AND_RESET; + } + return EINVAL; + } + return SecDoCpyW(strDest, destMax, strSrc); } + + diff --git a/project/app/wifi_app/hisi_tools/securec/wcsncat_s.c b/project/app/wifi_app/hisi_tools/securec/wcsncat_s.c index 8aef81b35..4dc1f1ab9 100644 --- a/project/app/wifi_app/hisi_tools/securec/wcsncat_s.c +++ b/project/app/wifi_app/hisi_tools/securec/wcsncat_s.c @@ -10,50 +10,47 @@ /* * Befor this function, the basic parameter checking has been done */ -SECUREC_INLINE errno_t SecDoCatLimitW(wchar_t *strDest, size_t destMax, - const wchar_t *strSrc, size_t count) { - /* To calculate the length of a wide character, the parameter must be a wide - * character */ - size_t destLen; - size_t srcLen; - SECUREC_CALC_WSTR_LEN(strDest, destMax, &destLen); - SECUREC_CALC_WSTR_LEN(strSrc, count, &srcLen); +SECUREC_INLINE errno_t SecDoCatLimitW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count) +{ + /* To calculate the length of a wide character, the parameter must be a wide character */ + size_t destLen; + size_t srcLen; + SECUREC_CALC_WSTR_LEN(strDest, destMax, &destLen); + SECUREC_CALC_WSTR_LEN(strSrc, count, &srcLen); - if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) { - strDest[0] = L'\0'; - if (strDest + destLen <= strSrc && destLen == destMax) { - SECUREC_ERROR_INVALID_PARAMTER("wcsncat_s"); - return EINVAL_AND_RESET; + if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) { + strDest[0] = L'\0'; + if (strDest + destLen <= strSrc && destLen == destMax) { + SECUREC_ERROR_INVALID_PARAMTER("wcsncat_s"); + return EINVAL_AND_RESET; + } + SECUREC_ERROR_BUFFER_OVERLAP("wcsncat_s"); + return EOVERLAP_AND_RESET; } - SECUREC_ERROR_BUFFER_OVERLAP("wcsncat_s"); - return EOVERLAP_AND_RESET; - } - if (srcLen + destLen >= destMax || strDest == strSrc) { - strDest[0] = L'\0'; - if (destLen == destMax) { - SECUREC_ERROR_INVALID_PARAMTER("wcsncat_s"); - return EINVAL_AND_RESET; + if (srcLen + destLen >= destMax || strDest == strSrc) { + strDest[0] = L'\0'; + if (destLen == destMax) { + SECUREC_ERROR_INVALID_PARAMTER("wcsncat_s"); + return EINVAL_AND_RESET; + } + SECUREC_ERROR_INVALID_RANGE("wcsncat_s"); + return ERANGE_AND_RESET; } - SECUREC_ERROR_INVALID_RANGE("wcsncat_s"); - return ERANGE_AND_RESET; - } - SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, - srcLen * sizeof(wchar_t)); /* no terminator */ - *(strDest + destLen + srcLen) = L'\0'; - return EOK; + SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, srcLen * sizeof(wchar_t)); /* no terminator */ + *(strDest + destLen + srcLen) = L'\0'; + return EOK; } /* * * The wcsncat_s function appends not more than n successive wide characters * (not including the terminating null wide character) - * from the array pointed to by strSrc to the end of the wide string pointed - * to by strDest. + * from the array pointed to by strSrc to the end of the wide string pointed to by strDest. * * The wcsncat_s function try to append the first D characters of strSrc to - * the end of strDest, where D is the lesser of count and the length of - * strSrc. If appending those D characters will fit within strDest (whose size - * is given as destMax) and still leave room for a null terminator, then those + * the end of strDest, where D is the lesser of count and the length of strSrc. + * If appending those D characters will fit within strDest (whose size is + * given as destMax) and still leave room for a null terminator, then those * characters are appended, starting at the original terminating null of * strDest, and a new terminating null is appended; otherwise, strDest[0] is * set to the null character. @@ -69,42 +66,41 @@ SECUREC_INLINE errno_t SecDoCatLimitW(wchar_t *strDest, size_t destMax, * * * EOK Success - * EINVAL strDest is NULL and destMax != 0 and destMax <= - * SECUREC_WCHAR_STRING_MAX_LEN EINVAL_AND_RESET (strDest unterminated and - * all other parameters are valid) or (strDest != NULL and strSrc is NULLL and - * destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN) ERANGE destMax > - * SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0 ERANGE_AND_RESET strDest - * have not enough space and all other parameters are valid and not overlap - * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and - * all parameters are valid + * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN + * EINVAL_AND_RESET (strDest unterminated and all other parameters are valid) or + * (strDest != NULL and strSrc is NULLL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN) + * ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0 + * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap + * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, - size_t count) { - if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) { - SECUREC_ERROR_INVALID_RANGE("wcsncat_s"); - return ERANGE; - } - if (strDest == NULL || strSrc == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("wcsncat_s"); - if (strDest != NULL) { - strDest[0] = L'\0'; - return EINVAL_AND_RESET; +errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count) +{ + if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) { + SECUREC_ERROR_INVALID_RANGE("wcsncat_s"); + return ERANGE; } - return EINVAL; - } - if (count > SECUREC_WCHAR_STRING_MAX_LEN) { -#ifdef SECUREC_COMPATIBLE_WIN_FORMAT - if (count == ((size_t)-1)) { - /* Windows internal functions may pass in -1 when calling this function */ - return SecDoCatLimitW(strDest, destMax, strSrc, destMax); + if (strDest == NULL || strSrc == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("wcsncat_s"); + if (strDest != NULL) { + strDest[0] = L'\0'; + return EINVAL_AND_RESET; + } + return EINVAL; } + if (count > SECUREC_WCHAR_STRING_MAX_LEN) { +#ifdef SECUREC_COMPATIBLE_WIN_FORMAT + if (count == ((size_t)-1)) { + /* Windows internal functions may pass in -1 when calling this function */ + return SecDoCatLimitW(strDest, destMax, strSrc, destMax); + } #endif - strDest[0] = L'\0'; - SECUREC_ERROR_INVALID_RANGE("wcsncat_s"); - return ERANGE_AND_RESET; - } - return SecDoCatLimitW(strDest, destMax, strSrc, count); + strDest[0] = L'\0'; + SECUREC_ERROR_INVALID_RANGE("wcsncat_s"); + return ERANGE_AND_RESET; + } + return SecDoCatLimitW(strDest, destMax, strSrc, count); } + + diff --git a/project/app/wifi_app/hisi_tools/securec/wcsncpy_s.c b/project/app/wifi_app/hisi_tools/securec/wcsncpy_s.c index 6cb4a5890..ea3cfe8f1 100644 --- a/project/app/wifi_app/hisi_tools/securec/wcsncpy_s.c +++ b/project/app/wifi_app/hisi_tools/securec/wcsncpy_s.c @@ -7,32 +7,32 @@ #include "securecutil.h" -SECUREC_INLINE errno_t SecDoCpyLimitW(wchar_t *strDest, size_t destMax, - const wchar_t *strSrc, size_t count) { - size_t srcStrLen; - if (count < destMax) { - SECUREC_CALC_WSTR_LEN(strSrc, count, &srcStrLen); - } else { - SECUREC_CALC_WSTR_LEN(strSrc, destMax, &srcStrLen); - } - if (srcStrLen == destMax) { - strDest[0] = '\0'; - SECUREC_ERROR_INVALID_RANGE("wcsncpy_s"); - return ERANGE_AND_RESET; - } - if (strDest == strSrc) { - return EOK; - } - if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, srcStrLen)) { - /* Performance optimization srcStrLen not include '\0' */ - SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, srcStrLen * sizeof(wchar_t)); - *(strDest + srcStrLen) = L'\0'; - return EOK; - } else { - strDest[0] = L'\0'; - SECUREC_ERROR_BUFFER_OVERLAP("wcsncpy_s"); - return EOVERLAP_AND_RESET; - } +SECUREC_INLINE errno_t SecDoCpyLimitW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count) +{ + size_t srcStrLen; + if (count < destMax) { + SECUREC_CALC_WSTR_LEN(strSrc, count, &srcStrLen); + } else { + SECUREC_CALC_WSTR_LEN(strSrc, destMax, &srcStrLen); + } + if (srcStrLen == destMax) { + strDest[0] = '\0'; + SECUREC_ERROR_INVALID_RANGE("wcsncpy_s"); + return ERANGE_AND_RESET; + } + if (strDest == strSrc) { + return EOK; + } + if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, srcStrLen)) { + /* Performance optimization srcStrLen not include '\0' */ + SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, srcStrLen * sizeof(wchar_t)); + *(strDest + srcStrLen) = L'\0'; + return EOK; + } else { + strDest[0] = L'\0'; + SECUREC_ERROR_BUFFER_OVERLAP("wcsncpy_s"); + return EOVERLAP_AND_RESET; + } } /* @@ -52,49 +52,49 @@ SECUREC_INLINE errno_t SecDoCpyLimitW(wchar_t *strDest, size_t destMax, * * * EOK Success - * EINVAL strDest is NULL and destMax != 0 and destMax <= - * SECUREC_WCHAR_STRING_MAX_LEN EINVAL_AND_RESET strDest != NULL and strSrc - * is NULLL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN ERANGE - * destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0 ERANGE_AND_RESET count - * > SECUREC_WCHAR_STRING_MAX_LEN or (destMax <= length of strSrc and destMax <= - * count and strDest != strSrc and strDest != NULL and strSrc != NULL and - * destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN and not overlap) - * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and - * all parameters are valid + * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN + * EINVAL_AND_RESET strDest != NULL and strSrc is NULLL and destMax != 0 + * and destMax <= SECUREC_WCHAR_STRING_MAX_LEN + * ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0 + * ERANGE_AND_RESET count > SECUREC_WCHAR_STRING_MAX_LEN or + * (destMax <= length of strSrc and destMax <= count and strDest != strSrc + * and strDest != NULL and strSrc != NULL and destMax != 0 and + * destMax <= SECUREC_WCHAR_STRING_MAX_LEN and not overlap) + * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid * * - * If there is a runtime-constraint violation, strDest[0] will be set to the - * '\0' when strDest and destMax valid + * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid */ -errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, - size_t count) { - if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) { - SECUREC_ERROR_INVALID_RANGE("wcsncpy_s"); - return ERANGE; - } - if (strDest == NULL || strSrc == NULL) { - SECUREC_ERROR_INVALID_PARAMTER("wcsncpy_s"); - if (strDest != NULL) { - strDest[0] = '\0'; - return EINVAL_AND_RESET; +errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count) +{ + if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) { + SECUREC_ERROR_INVALID_RANGE("wcsncpy_s"); + return ERANGE; } - return EINVAL; - } - if (count > SECUREC_WCHAR_STRING_MAX_LEN) { + if (strDest == NULL || strSrc == NULL) { + SECUREC_ERROR_INVALID_PARAMTER("wcsncpy_s"); + if (strDest != NULL) { + strDest[0] = '\0'; + return EINVAL_AND_RESET; + } + return EINVAL; + } + if (count > SECUREC_WCHAR_STRING_MAX_LEN) { #ifdef SECUREC_COMPATIBLE_WIN_FORMAT - if (count == (size_t)(-1)) { - return SecDoCpyLimitW(strDest, destMax, strSrc, destMax - 1); - } + if (count == (size_t)(-1)) { + return SecDoCpyLimitW(strDest, destMax, strSrc, destMax - 1); + } #endif - strDest[0] = '\0'; /* Clear dest string */ - SECUREC_ERROR_INVALID_RANGE("wcsncpy_s"); - return ERANGE_AND_RESET; - } + strDest[0] = '\0'; /* Clear dest string */ + SECUREC_ERROR_INVALID_RANGE("wcsncpy_s"); + return ERANGE_AND_RESET; + } - if (count == 0) { - strDest[0] = '\0'; - return EOK; - } + if (count == 0) { + strDest[0] = '\0'; + return EOK; + } - return SecDoCpyLimitW(strDest, destMax, strSrc, count); + return SecDoCpyLimitW(strDest, destMax, strSrc, count); } + diff --git a/project/app/wifi_app/hisi_tools/securec/wcstok_s.c b/project/app/wifi_app/hisi_tools/securec/wcstok_s.c index 2dc79dad4..acff3e76e 100644 --- a/project/app/wifi_app/hisi_tools/securec/wcstok_s.c +++ b/project/app/wifi_app/hisi_tools/securec/wcstok_s.c @@ -7,67 +7,66 @@ #include "securecutil.h" -SECUREC_INLINE int SecIsInDelimitW(wchar_t ch, const wchar_t *strDelimit) { - const wchar_t *ctl = strDelimit; - while (*ctl != L'\0' && *ctl != ch) { - ++ctl; - } - return (int)(*ctl != L'\0'); + +SECUREC_INLINE int SecIsInDelimitW(wchar_t ch, const wchar_t *strDelimit) +{ + const wchar_t *ctl = strDelimit; + while (*ctl != L'\0' && *ctl != ch) { + ++ctl; + } + return (int)(*ctl != L'\0'); } /* * Find beginning of token (skip over leading delimiters). - * Note that there is no token if this loop sets string to point to the terminal - * null. + * Note that there is no token if this loop sets string to point to the terminal null. */ -SECUREC_INLINE wchar_t *SecFindBeginW(wchar_t *strToken, - const wchar_t *strDelimit) { - wchar_t *token = strToken; - while (*token != L'\0') { - if (SecIsInDelimitW(*token, strDelimit)) { - ++token; - continue; +SECUREC_INLINE wchar_t *SecFindBeginW(wchar_t *strToken, const wchar_t *strDelimit) +{ + wchar_t *token = strToken; + while (*token != L'\0') { + if (SecIsInDelimitW(*token, strDelimit)) { + ++token; + continue; + } + /* Don't find any delimiter in string header, break the loop */ + break; } - /* Don't find any delimiter in string header, break the loop */ - break; - } - return token; + return token; } /* - * Find the end of the token. If it is not the end of the string, put a null - * there. + * Find the end of the token. If it is not the end of the string, put a null there. */ -SECUREC_INLINE wchar_t *SecFindRestW(wchar_t *strToken, - const wchar_t *strDelimit) { - wchar_t *token = strToken; - while (*token != L'\0') { - if (SecIsInDelimitW(*token, strDelimit)) { - /* Find a delimiter, set string termintor */ - *token = L'\0'; - ++token; - break; +SECUREC_INLINE wchar_t *SecFindRestW(wchar_t *strToken, const wchar_t *strDelimit) +{ + wchar_t *token = strToken; + while (*token != L'\0') { + if (SecIsInDelimitW(*token, strDelimit)) { + /* Find a delimiter, set string termintor */ + *token = L'\0'; + ++token; + break; + } + ++token; } - ++token; - } - return token; + return token; } /* * Update Token wide character function */ -SECUREC_INLINE wchar_t *SecUpdateTokenW(wchar_t *strToken, - const wchar_t *strDelimit, - wchar_t **context) { - /* Point to updated position */ - wchar_t *token = SecFindRestW(strToken, strDelimit); - /* Update the context */ - *context = token; - /* Determine if a token has been found. */ - if (token == strToken) { - return NULL; - } - return strToken; +SECUREC_INLINE wchar_t *SecUpdateTokenW(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context) +{ + /* Point to updated position */ + wchar_t *token = SecFindRestW(strToken, strDelimit); + /* Update the context */ + *context = token; + /* Determine if a token has been found. */ + if (token == strToken) { + return NULL; + } + return strToken; } /* @@ -76,8 +75,7 @@ SECUREC_INLINE wchar_t *SecUpdateTokenW(wchar_t *strToken, * * * - * The wcstok_s function is the wide-character equivalent of the - * strtok_s function + * The wcstok_s function is the wide-character equivalent of the strtok_s function * * * strToken String containing token or tokens. @@ -88,23 +86,23 @@ SECUREC_INLINE wchar_t *SecUpdateTokenW(wchar_t *strToken, * * context is updated * - * The wcstok_s function is the wide-character equivalent of the - * strtok_s function + * The wcstok_s function is the wide-character equivalent of the strtok_s function */ -wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, - wchar_t **context) { - wchar_t *orgToken = strToken; - /* Validation section */ - if (context == NULL || strDelimit == NULL) { - return NULL; - } - if (orgToken == NULL && *context == NULL) { - return NULL; - } - /* If string==NULL, continue with previous string */ - if (orgToken == NULL) { - orgToken = *context; - } - orgToken = SecFindBeginW(orgToken, strDelimit); - return SecUpdateTokenW(orgToken, strDelimit, context); +wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context) +{ + wchar_t *orgToken = strToken; + /* Validation section */ + if (context == NULL || strDelimit == NULL) { + return NULL; + } + if (orgToken == NULL && *context == NULL) { + return NULL; + } + /* If string==NULL, continue with previous string */ + if (orgToken == NULL) { + orgToken = *context; + } + orgToken = SecFindBeginW(orgToken, strDelimit); + return SecUpdateTokenW(orgToken, strDelimit, context); } + diff --git a/project/app/wifi_app/hisi_tools/securec/wmemcpy_s.c b/project/app/wifi_app/hisi_tools/securec/wmemcpy_s.c index f2ee3166f..8b74f52a6 100644 --- a/project/app/wifi_app/hisi_tools/securec/wmemcpy_s.c +++ b/project/app/wifi_app/hisi_tools/securec/wmemcpy_s.c @@ -6,9 +6,8 @@ */ /* * [Standardize-exceptions] Use unsafe function: Portability - * [reason] Use unsafe function to implement security function to maintain - * platform compatibility. And sufficient input validation is performed before - * calling + * [reason] Use unsafe function to implement security function to maintain platform compatibility. + * And sufficient input validation is performed before calling */ #include "securecutil.h" @@ -29,36 +28,37 @@ * * * EOK Success - * EINVAL dest is NULL and destMax != 0 and count <= - * destMax and destMax <= SECUREC_WCHAR_MEM_MAX_LEN EINVAL_AND_RESET dest - * != NULL and src is NULLL and destMax != 0 and destMax <= - * SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax ERANGE destMax - * > SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or (count > destMax and dest is - * NULL and destMax != 0 and destMax <= SECUREC_WCHAR_MEM_MAX_LEN) + * EINVAL dest is NULL and destMax != 0 and count <= destMax + * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN + * EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 + * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax + * ERANGE destMax > SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or + * (count > destMax and dest is NULL and destMax != 0 + * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN) * ERANGE_AND_RESET count > destMax and dest != NULL and destMax != 0 * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and - * count <= destMax destMax != 0 and destMax <= - * SECUREC_WCHAR_MEM_MAX_LEN and dest != NULL and src != NULL and dest != src + * count <= destMax destMax != 0 and destMax <= SECUREC_WCHAR_MEM_MAX_LEN + * and dest != NULL and src != NULL and dest != src * - * if an error occured, dest will be filled with 0 when dest and destMax - * valid . If the source and destination overlap, the behavior of wmemcpy_s is - * undefined. Use wmemmove_s to handle overlapping regions. + * if an error occured, dest will be filled with 0 when dest and destMax valid . + * If the source and destination overlap, the behavior of wmemcpy_s is undefined. + * Use wmemmove_s to handle overlapping regions. */ -errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, - size_t count) { - if (destMax == 0 || destMax > SECUREC_WCHAR_MEM_MAX_LEN) { - SECUREC_ERROR_INVALID_PARAMTER("wmemcpy_s"); - return ERANGE; - } - if (count > destMax) { - SECUREC_ERROR_INVALID_PARAMTER("wmemcpy_s"); - if (dest != NULL) { - (void)memset(dest, 0, destMax * sizeof(wchar_t)); - return ERANGE_AND_RESET; +errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count) +{ + if (destMax == 0 || destMax > SECUREC_WCHAR_MEM_MAX_LEN) { + SECUREC_ERROR_INVALID_PARAMTER("wmemcpy_s"); + return ERANGE; } - return ERANGE; - } - return memcpy_s(dest, destMax * sizeof(wchar_t), src, - count * sizeof(wchar_t)); + if (count > destMax) { + SECUREC_ERROR_INVALID_PARAMTER("wmemcpy_s"); + if (dest != NULL) { + (void)memset(dest, 0, destMax * sizeof(wchar_t)); + return ERANGE_AND_RESET; + } + return ERANGE; + } + return memcpy_s(dest, destMax * sizeof(wchar_t), src, count * sizeof(wchar_t)); } + diff --git a/project/app/wifi_app/hisi_tools/securec/wmemmove_s.c b/project/app/wifi_app/hisi_tools/securec/wmemmove_s.c index e115af35e..5182230a2 100644 --- a/project/app/wifi_app/hisi_tools/securec/wmemmove_s.c +++ b/project/app/wifi_app/hisi_tools/securec/wmemmove_s.c @@ -6,17 +6,16 @@ */ /* * [Standardize-exceptions] Use unsafe function: Portability - * [reason] Use unsafe function to implement security function to maintain - * platform compatibility. And sufficient input validation is performed before - * calling + * [reason] Use unsafe function to implement security function to maintain platform compatibility. + * And sufficient input validation is performed before calling */ #include "securecutil.h" /* * - * The wmemmove_s function copies n successive wide characters from the object - * pointed to by src into the object pointed to by dest. + * The wmemmove_s function copies n successive wide characters from the object pointed + * to by src into the object pointed to by dest. * * * dest Destination buffer. @@ -29,35 +28,36 @@ * * * EOK Success - * EINVAL dest is NULL and destMax != 0 and count <= - * destMax and destMax <= SECUREC_WCHAR_MEM_MAX_LEN EINVAL_AND_RESET dest != - * NULL and src is NULLL and destMax != 0 and destMax <= - * SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax ERANGE destMax > - * SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or (count > destMax and dest is - * NULL and destMax != 0 and destMax <= SECUREC_WCHAR_MEM_MAX_LEN) - * ERANGE_AND_RESET count > destMax and dest != NULL and destMax != - * 0 and destMax <= SECUREC_WCHAR_MEM_MAX_LEN + * EINVAL dest is NULL and destMax != 0 and count <= destMax + * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN + * EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 + * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax + * ERANGE destMax > SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or + * (count > destMax and dest is NULL and destMax != 0 + * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN) + * ERANGE_AND_RESET count > destMax and dest != NULL and destMax != 0 + * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN * * - * If an error occured, dest will be filled with 0 when dest and destMax - * valid. If some regions of the source area and the destination overlap, - * wmemmove_s ensures that the original source bytes in the overlapping region - * are copied before being overwritten + * If an error occured, dest will be filled with 0 when dest and destMax valid. + * If some regions of the source area and the destination overlap, wmemmove_s + * ensures that the original source bytes in the overlapping region are copied + * before being overwritten */ -errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, - size_t count) { - if (destMax == 0 || destMax > SECUREC_WCHAR_MEM_MAX_LEN) { - SECUREC_ERROR_INVALID_PARAMTER("wmemmove_s"); - return ERANGE; - } - if (count > destMax) { - SECUREC_ERROR_INVALID_PARAMTER("wmemmove_s"); - if (dest != NULL) { - (void)memset(dest, 0, destMax * sizeof(wchar_t)); - return ERANGE_AND_RESET; +errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count) +{ + if (destMax == 0 || destMax > SECUREC_WCHAR_MEM_MAX_LEN) { + SECUREC_ERROR_INVALID_PARAMTER("wmemmove_s"); + return ERANGE; } - return ERANGE; - } - return memmove_s(dest, destMax * sizeof(wchar_t), src, - count * sizeof(wchar_t)); + if (count > destMax) { + SECUREC_ERROR_INVALID_PARAMTER("wmemmove_s"); + if (dest != NULL) { + (void)memset(dest, 0, destMax * sizeof(wchar_t)); + return ERANGE_AND_RESET; + } + return ERANGE; + } + return memmove_s(dest, destMax * sizeof(wchar_t), src, count * sizeof(wchar_t)); } + diff --git a/project/app/wifi_app/hisi_tools/securec/wscanf_s.c b/project/app/wifi_app/hisi_tools/securec/wscanf_s.c index 58842cdaa..a724a0f87 100644 --- a/project/app/wifi_app/hisi_tools/securec/wscanf_s.c +++ b/project/app/wifi_app/hisi_tools/securec/wscanf_s.c @@ -10,20 +10,19 @@ /* * * - * The wscanf_s function is the wide-character equivalent of the - * scanf_s function The wscanf_s function reads data from the standard input - * stream stdin and writes the data into the location that's given by argument. - * Each argument must be a pointer to a variable of a type that corresponds to a - * type specifier in format. If copying occurs between strings that overlap, the - * behavior is undefined. + * The wscanf_s function is the wide-character equivalent of the scanf_s function + * The wscanf_s function reads data from the standard input stream stdin and + * writes the data into the location that's given by argument. Each argument + * must be a pointer to a variable of a type that corresponds to a type specifier + * in format. If copying occurs between strings that overlap, the behavior is + * undefined. * * * format Format control string. * ... Optional arguments. * * - * ... the converted value stored in user assigned - * address + * ... the converted value stored in user assigned address * * * Returns the number of fields successfully converted and assigned; @@ -31,15 +30,16 @@ * A return value of 0 indicates that no fields were assigned. * return -1 if an error occurs. */ -int wscanf_s(const wchar_t *format, ...) { - int ret; /* If initialization causes e838 */ - va_list argList; +int wscanf_s(const wchar_t *format, ...) +{ + int ret; /* If initialization causes e838 */ + va_list argList; - va_start(argList, format); - ret = vwscanf_s(format, argList); - va_end(argList); - (void)argList; /* To clear e438 last value assigned not used , the compiler - will optimize this code */ + va_start(argList, format); + ret = vwscanf_s(format, argList); + va_end(argList); + (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */ - return ret; + return ret; } + diff --git a/project/app/wifi_app/hostapd-2.6/hostapd/config_file.c b/project/app/wifi_app/hostapd-2.6/hostapd/config_file.c index 522aaee28..5079f69e3 100644 --- a/project/app/wifi_app/hostapd-2.6/hostapd/config_file.c +++ b/project/app/wifi_app/hostapd-2.6/hostapd/config_file.c @@ -11,3440 +11,3608 @@ #include #endif /* CONFIG_NATIVE_WINDOWS */ -#include "ap/ap_config.h" -#include "ap/wpa_auth.h" +#include "utils/common.h" +#include "utils/uuid.h" #include "common/ieee802_11_defs.h" -#include "config_file.h" #include "drivers/driver.h" #include "eap_server/eap.h" #include "radius/radius_client.h" -#include "utils/common.h" -#include "utils/uuid.h" +#include "ap/wpa_auth.h" +#include "ap/ap_config.h" +#include "config_file.h" + #ifndef CONFIG_NO_RADIUS #ifdef EAP_SERVER -static struct hostapd_radius_attr *hostapd_parse_radius_attr(const char *value); +static struct hostapd_radius_attr * +hostapd_parse_radius_attr(const char *value); #endif /* EAP_SERVER */ #endif /* CONFIG_NO_RADIUS */ + #ifndef CONFIG_NO_VLAN static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss, - const char *fname) { - FILE *f; - char buf[128], *pos, *pos2; - int line = 0, vlan_id; - struct hostapd_vlan *vlan; + const char *fname) +{ + FILE *f; + char buf[128], *pos, *pos2; + int line = 0, vlan_id; + struct hostapd_vlan *vlan; - f = fopen(fname, "r"); - if (!f) { - wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname); - return -1; - } + f = fopen(fname, "r"); + if (!f) { + wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname); + return -1; + } - while (fgets(buf, sizeof(buf), f)) { - line++; + while (fgets(buf, sizeof(buf), f)) { + line++; - if (buf[0] == '#') - continue; - pos = buf; - while (*pos != '\0') { - if (*pos == '\n') { - *pos = '\0'; - break; - } - pos++; - } - if (buf[0] == '\0') - continue; + if (buf[0] == '#') + continue; + pos = buf; + while (*pos != '\0') { + if (*pos == '\n') { + *pos = '\0'; + break; + } + pos++; + } + if (buf[0] == '\0') + continue; - if (buf[0] == '*') { - vlan_id = VLAN_ID_WILDCARD; - pos = buf + 1; - } else { - vlan_id = strtol(buf, &pos, 10); - if (buf == pos || vlan_id < 1 || vlan_id > MAX_VLAN_ID) { - wpa_printf(MSG_ERROR, - "Invalid VLAN ID at " - "line %d in '%s'", - line, fname); - fclose(f); - return -1; - } - } + if (buf[0] == '*') { + vlan_id = VLAN_ID_WILDCARD; + pos = buf + 1; + } else { + vlan_id = strtol(buf, &pos, 10); + if (buf == pos || vlan_id < 1 || + vlan_id > MAX_VLAN_ID) { + wpa_printf(MSG_ERROR, "Invalid VLAN ID at " + "line %d in '%s'", line, fname); + fclose(f); + return -1; + } + } - while (*pos == ' ' || *pos == '\t') - pos++; - pos2 = pos; - while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0') - pos2++; - *pos2 = '\0'; - if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) { - wpa_printf(MSG_ERROR, - "Invalid VLAN ifname at line %d " - "in '%s'", - line, fname); - fclose(f); - return -1; - } + while (*pos == ' ' || *pos == '\t') + pos++; + pos2 = pos; + while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0') + pos2++; + *pos2 = '\0'; + if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) { + wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d " + "in '%s'", line, fname); + fclose(f); + return -1; + } - vlan = os_zalloc(sizeof(*vlan)); - if (vlan == NULL) { - wpa_printf(MSG_ERROR, - "Out of memory while reading " - "VLAN interfaces from '%s'", - fname); - fclose(f); - return -1; - } + vlan = os_zalloc(sizeof(*vlan)); + if (vlan == NULL) { + wpa_printf(MSG_ERROR, "Out of memory while reading " + "VLAN interfaces from '%s'", fname); + fclose(f); + return -1; + } - vlan->vlan_id = vlan_id; - vlan->vlan_desc.untagged = vlan_id; - vlan->vlan_desc.notempty = !!vlan_id; - os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname)); - vlan->next = bss->vlan; - bss->vlan = vlan; - } + vlan->vlan_id = vlan_id; + vlan->vlan_desc.untagged = vlan_id; + vlan->vlan_desc.notempty = !!vlan_id; + os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname)); + vlan->next = bss->vlan; + bss->vlan = vlan; + } - fclose(f); + fclose(f); - return 0; + return 0; } #endif /* CONFIG_NO_VLAN */ -static int hostapd_acl_comp(const void *a, const void *b) { - const struct mac_acl_entry *aa = a; - const struct mac_acl_entry *bb = b; - return os_memcmp(aa->addr, bb->addr, sizeof(macaddr)); + +static int hostapd_acl_comp(const void *a, const void *b) +{ + const struct mac_acl_entry *aa = a; + const struct mac_acl_entry *bb = b; + return os_memcmp(aa->addr, bb->addr, sizeof(macaddr)); } + static int hostapd_config_read_maclist(const char *fname, - struct mac_acl_entry **acl, int *num) { - FILE *f; - char buf[128], *pos; - int line = 0; - u8 addr[ETH_ALEN]; - struct mac_acl_entry *newacl; - int vlan_id; + struct mac_acl_entry **acl, int *num) +{ + FILE *f; + char buf[128], *pos; + int line = 0; + u8 addr[ETH_ALEN]; + struct mac_acl_entry *newacl; + int vlan_id; - if (!fname) - return 0; + if (!fname) + return 0; - f = fopen(fname, "r"); - if (!f) { - wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname); - return -1; - } + f = fopen(fname, "r"); + if (!f) { + wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname); + return -1; + } - while (fgets(buf, sizeof(buf), f)) { - int i, rem = 0; + while (fgets(buf, sizeof(buf), f)) { + int i, rem = 0; - line++; + line++; - if (buf[0] == '#') - continue; - pos = buf; - while (*pos != '\0') { - if (*pos == '\n') { - *pos = '\0'; - break; - } - pos++; - } - if (buf[0] == '\0') - continue; - pos = buf; - if (buf[0] == '-') { - rem = 1; - pos++; - } + if (buf[0] == '#') + continue; + pos = buf; + while (*pos != '\0') { + if (*pos == '\n') { + *pos = '\0'; + break; + } + pos++; + } + if (buf[0] == '\0') + continue; + pos = buf; + if (buf[0] == '-') { + rem = 1; + pos++; + } - if (hwaddr_aton(pos, addr)) { - wpa_printf(MSG_ERROR, - "Invalid MAC address '%s' at " - "line %d in '%s'", - pos, line, fname); - fclose(f); - return -1; - } + if (hwaddr_aton(pos, addr)) { + wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at " + "line %d in '%s'", pos, line, fname); + fclose(f); + return -1; + } - if (rem) { - i = 0; - while (i < *num) { - if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) == 0) { - os_remove_in_array(*acl, *num, sizeof(**acl), i); - (*num)--; - } else - i++; - } - continue; - } - vlan_id = 0; - pos = buf; - while (*pos != '\0' && *pos != ' ' && *pos != '\t') - pos++; - while (*pos == ' ' || *pos == '\t') - pos++; - if (*pos != '\0') - vlan_id = atoi(pos); + if (rem) { + i = 0; + while (i < *num) { + if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) == + 0) { + os_remove_in_array(*acl, *num, + sizeof(**acl), i); + (*num)--; + } else + i++; + } + continue; + } + vlan_id = 0; + pos = buf; + while (*pos != '\0' && *pos != ' ' && *pos != '\t') + pos++; + while (*pos == ' ' || *pos == '\t') + pos++; + if (*pos != '\0') + vlan_id = atoi(pos); - newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl)); - if (newacl == NULL) { - wpa_printf(MSG_ERROR, "MAC list reallocation failed"); - fclose(f); - return -1; - } + newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl)); + if (newacl == NULL) { + wpa_printf(MSG_ERROR, "MAC list reallocation failed"); + fclose(f); + return -1; + } - *acl = newacl; - os_memcpy((*acl)[*num].addr, addr, ETH_ALEN); - os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id)); - (*acl)[*num].vlan_id.untagged = vlan_id; - (*acl)[*num].vlan_id.notempty = !!vlan_id; - (*num)++; - } + *acl = newacl; + os_memcpy((*acl)[*num].addr, addr, ETH_ALEN); + os_memset(&(*acl)[*num].vlan_id, 0, + sizeof((*acl)[*num].vlan_id)); + (*acl)[*num].vlan_id.untagged = vlan_id; + (*acl)[*num].vlan_id.notempty = !!vlan_id; + (*num)++; + } - fclose(f); + fclose(f); - qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp); + qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp); - return 0; + return 0; } + #ifdef EAP_SERVER static int hostapd_config_read_eap_user(const char *fname, - struct hostapd_bss_config *conf) { - FILE *f; - char buf[512], *pos, *start, *pos2; - int line = 0, ret = 0, num_methods; - struct hostapd_eap_user *user = NULL, *tail = NULL, *new_user = NULL; + struct hostapd_bss_config *conf) +{ + FILE *f; + char buf[512], *pos, *start, *pos2; + int line = 0, ret = 0, num_methods; + struct hostapd_eap_user *user = NULL, *tail = NULL, *new_user = NULL; - if (!fname) - return 0; + if (!fname) + return 0; - if (os_strncmp(fname, "sqlite:", 7) == 0) { + if (os_strncmp(fname, "sqlite:", 7) == 0) { #ifdef CONFIG_SQLITE - os_free(conf->eap_user_sqlite); - conf->eap_user_sqlite = os_strdup(fname + 7); - return 0; -#else /* CONFIG_SQLITE */ - wpa_printf(MSG_ERROR, "EAP user file in SQLite DB, but CONFIG_SQLITE was " - "not enabled in the build."); - return -1; + os_free(conf->eap_user_sqlite); + conf->eap_user_sqlite = os_strdup(fname + 7); + return 0; +#else /* CONFIG_SQLITE */ + wpa_printf(MSG_ERROR, + "EAP user file in SQLite DB, but CONFIG_SQLITE was not enabled in the build."); + return -1; #endif /* CONFIG_SQLITE */ - } + } - f = fopen(fname, "r"); - if (!f) { - wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname); - return -1; - } + f = fopen(fname, "r"); + if (!f) { + wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname); + return -1; + } - /* Lines: "user" METHOD,METHOD2 "password" (password optional) */ - while (fgets(buf, sizeof(buf), f)) { - line++; + /* Lines: "user" METHOD,METHOD2 "password" (password optional) */ + while (fgets(buf, sizeof(buf), f)) { + line++; - if (buf[0] == '#') - continue; - pos = buf; - while (*pos != '\0') { - if (*pos == '\n') { - *pos = '\0'; - break; - } - pos++; - } - if (buf[0] == '\0') - continue; + if (buf[0] == '#') + continue; + pos = buf; + while (*pos != '\0') { + if (*pos == '\n') { + *pos = '\0'; + break; + } + pos++; + } + if (buf[0] == '\0') + continue; #ifndef CONFIG_NO_RADIUS - if (user && os_strncmp(buf, "radius_accept_attr=", 19) == 0) { - struct hostapd_radius_attr *attr, *a; - attr = hostapd_parse_radius_attr(buf + 19); - if (attr == NULL) { - wpa_printf(MSG_ERROR, "Invalid radius_auth_req_attr: %s", buf + 19); - user = NULL; /* already in the BSS list */ - goto failed; - } - if (user->accept_attr == NULL) { - user->accept_attr = attr; - } else { - a = user->accept_attr; - while (a->next) - a = a->next; - a->next = attr; - } - continue; - } + if (user && os_strncmp(buf, "radius_accept_attr=", 19) == 0) { + struct hostapd_radius_attr *attr, *a; + attr = hostapd_parse_radius_attr(buf + 19); + if (attr == NULL) { + wpa_printf(MSG_ERROR, "Invalid radius_auth_req_attr: %s", + buf + 19); + user = NULL; /* already in the BSS list */ + goto failed; + } + if (user->accept_attr == NULL) { + user->accept_attr = attr; + } else { + a = user->accept_attr; + while (a->next) + a = a->next; + a->next = attr; + } + continue; + } #endif /* CONFIG_NO_RADIUS */ - user = NULL; + user = NULL; - if (buf[0] != '"' && buf[0] != '*') { - wpa_printf(MSG_ERROR, - "Invalid EAP identity (no \" in " - "start) on line %d in '%s'", - line, fname); - goto failed; - } + if (buf[0] != '"' && buf[0] != '*') { + wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in " + "start) on line %d in '%s'", line, fname); + goto failed; + } - user = os_zalloc(sizeof(*user)); - if (user == NULL) { - wpa_printf(MSG_ERROR, "EAP user allocation failed"); - goto failed; - } - user->force_version = -1; + user = os_zalloc(sizeof(*user)); + if (user == NULL) { + wpa_printf(MSG_ERROR, "EAP user allocation failed"); + goto failed; + } + user->force_version = -1; - if (buf[0] == '*') { - pos = buf; - } else { - pos = buf + 1; - start = pos; - while (*pos != '"' && *pos != '\0') - pos++; - if (*pos == '\0') { - wpa_printf(MSG_ERROR, - "Invalid EAP identity " - "(no \" in end) on line %d in '%s'", - line, fname); - goto failed; - } + if (buf[0] == '*') { + pos = buf; + } else { + pos = buf + 1; + start = pos; + while (*pos != '"' && *pos != '\0') + pos++; + if (*pos == '\0') { + wpa_printf(MSG_ERROR, "Invalid EAP identity " + "(no \" in end) on line %d in '%s'", + line, fname); + goto failed; + } - user->identity = os_malloc(pos - start); - if (user->identity == NULL) { - wpa_printf(MSG_ERROR, "Failed to allocate " - "memory for EAP identity"); - goto failed; - } - os_memcpy(user->identity, start, pos - start); - user->identity_len = pos - start; + user->identity = os_malloc(pos - start); + if (user->identity == NULL) { + wpa_printf(MSG_ERROR, "Failed to allocate " + "memory for EAP identity"); + goto failed; + } + os_memcpy(user->identity, start, pos - start); + user->identity_len = pos - start; - if (pos[0] == '"' && pos[1] == '*') { - user->wildcard_prefix = 1; - pos++; - } - } - pos++; - while (*pos == ' ' || *pos == '\t') - pos++; + if (pos[0] == '"' && pos[1] == '*') { + user->wildcard_prefix = 1; + pos++; + } + } + pos++; + while (*pos == ' ' || *pos == '\t') + pos++; - if (*pos == '\0') { - wpa_printf(MSG_ERROR, - "No EAP method on line %d in " - "'%s'", - line, fname); - goto failed; - } + if (*pos == '\0') { + wpa_printf(MSG_ERROR, "No EAP method on line %d in " + "'%s'", line, fname); + goto failed; + } - start = pos; - while (*pos != ' ' && *pos != '\t' && *pos != '\0') - pos++; - if (*pos == '\0') { - pos = NULL; - } else { - *pos = '\0'; - pos++; - } - num_methods = 0; - while (*start) { - char *pos3 = os_strchr(start, ','); - if (pos3) { - *pos3++ = '\0'; - } - user->methods[num_methods].method = - eap_server_get_type(start, &user->methods[num_methods].vendor); - if (user->methods[num_methods].vendor == EAP_VENDOR_IETF && - user->methods[num_methods].method == EAP_TYPE_NONE) { - if (os_strcmp(start, "TTLS-PAP") == 0) { - user->ttls_auth |= EAP_TTLS_AUTH_PAP; - goto skip_eap; - } - if (os_strcmp(start, "TTLS-CHAP") == 0) { - user->ttls_auth |= EAP_TTLS_AUTH_CHAP; - goto skip_eap; - } - if (os_strcmp(start, "TTLS-MSCHAP") == 0) { - user->ttls_auth |= EAP_TTLS_AUTH_MSCHAP; - goto skip_eap; - } - if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) { - user->ttls_auth |= EAP_TTLS_AUTH_MSCHAPV2; - goto skip_eap; - } - if (os_strcmp(start, "MACACL") == 0) { - user->macacl = 1; - goto skip_eap; - } - wpa_printf(MSG_ERROR, - "Unsupported EAP type " - "'%s' on line %d in '%s'", - start, line, fname); - goto failed; - } + start = pos; + while (*pos != ' ' && *pos != '\t' && *pos != '\0') + pos++; + if (*pos == '\0') { + pos = NULL; + } else { + *pos = '\0'; + pos++; + } + num_methods = 0; + while (*start) { + char *pos3 = os_strchr(start, ','); + if (pos3) { + *pos3++ = '\0'; + } + user->methods[num_methods].method = + eap_server_get_type( + start, + &user->methods[num_methods].vendor); + if (user->methods[num_methods].vendor == + EAP_VENDOR_IETF && + user->methods[num_methods].method == EAP_TYPE_NONE) + { + if (os_strcmp(start, "TTLS-PAP") == 0) { + user->ttls_auth |= EAP_TTLS_AUTH_PAP; + goto skip_eap; + } + if (os_strcmp(start, "TTLS-CHAP") == 0) { + user->ttls_auth |= EAP_TTLS_AUTH_CHAP; + goto skip_eap; + } + if (os_strcmp(start, "TTLS-MSCHAP") == 0) { + user->ttls_auth |= + EAP_TTLS_AUTH_MSCHAP; + goto skip_eap; + } + if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) { + user->ttls_auth |= + EAP_TTLS_AUTH_MSCHAPV2; + goto skip_eap; + } + if (os_strcmp(start, "MACACL") == 0) { + user->macacl = 1; + goto skip_eap; + } + wpa_printf(MSG_ERROR, "Unsupported EAP type " + "'%s' on line %d in '%s'", + start, line, fname); + goto failed; + } - num_methods++; - if (num_methods >= EAP_MAX_METHODS) - break; - skip_eap: - if (pos3 == NULL) - break; - start = pos3; - } - if (num_methods == 0 && user->ttls_auth == 0 && !user->macacl) { - wpa_printf(MSG_ERROR, - "No EAP types configured on " - "line %d in '%s'", - line, fname); - goto failed; - } + num_methods++; + if (num_methods >= EAP_MAX_METHODS) + break; + skip_eap: + if (pos3 == NULL) + break; + start = pos3; + } + if (num_methods == 0 && user->ttls_auth == 0 && !user->macacl) { + wpa_printf(MSG_ERROR, "No EAP types configured on " + "line %d in '%s'", line, fname); + goto failed; + } - if (pos == NULL) - goto done; + if (pos == NULL) + goto done; - while (*pos == ' ' || *pos == '\t') - pos++; - if (*pos == '\0') - goto done; + while (*pos == ' ' || *pos == '\t') + pos++; + if (*pos == '\0') + goto done; - if (os_strncmp(pos, "[ver=0]", 7) == 0) { - user->force_version = 0; - goto done; - } + if (os_strncmp(pos, "[ver=0]", 7) == 0) { + user->force_version = 0; + goto done; + } - if (os_strncmp(pos, "[ver=1]", 7) == 0) { - user->force_version = 1; - goto done; - } + if (os_strncmp(pos, "[ver=1]", 7) == 0) { + user->force_version = 1; + goto done; + } - if (os_strncmp(pos, "[2]", 3) == 0) { - user->phase2 = 1; - goto done; - } + if (os_strncmp(pos, "[2]", 3) == 0) { + user->phase2 = 1; + goto done; + } - if (*pos == '"') { - pos++; - start = pos; - while (*pos != '"' && *pos != '\0') - pos++; - if (*pos == '\0') { - wpa_printf(MSG_ERROR, - "Invalid EAP password " - "(no \" in end) on line %d in '%s'", - line, fname); - goto failed; - } + if (*pos == '"') { + pos++; + start = pos; + while (*pos != '"' && *pos != '\0') + pos++; + if (*pos == '\0') { + wpa_printf(MSG_ERROR, "Invalid EAP password " + "(no \" in end) on line %d in '%s'", + line, fname); + goto failed; + } - user->password = os_malloc(pos - start); - if (user->password == NULL) { - wpa_printf(MSG_ERROR, "Failed to allocate " - "memory for EAP password"); - goto failed; - } - os_memcpy(user->password, start, pos - start); - user->password_len = pos - start; + user->password = os_malloc(pos - start); + if (user->password == NULL) { + wpa_printf(MSG_ERROR, "Failed to allocate " + "memory for EAP password"); + goto failed; + } + os_memcpy(user->password, start, pos - start); + user->password_len = pos - start; - pos++; - } else if (os_strncmp(pos, "hash:", 5) == 0) { - pos += 5; - pos2 = pos; - while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t' && *pos2 != '#') - pos2++; - if (pos2 - pos != 32) { - wpa_printf(MSG_ERROR, - "Invalid password hash " - "on line %d in '%s'", - line, fname); - goto failed; - } - user->password = os_malloc(16); - if (user->password == NULL) { - wpa_printf(MSG_ERROR, "Failed to allocate " - "memory for EAP password hash"); - goto failed; - } - if (hexstr2bin(pos, user->password, 16) < 0) { - wpa_printf(MSG_ERROR, - "Invalid hash password " - "on line %d in '%s'", - line, fname); - goto failed; - } - user->password_len = 16; - user->password_hash = 1; - pos = pos2; - } else { - pos2 = pos; - while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t' && *pos2 != '#') - pos2++; - if ((pos2 - pos) & 1) { - wpa_printf(MSG_ERROR, - "Invalid hex password " - "on line %d in '%s'", - line, fname); - goto failed; - } - user->password = os_malloc((pos2 - pos) / 2); - if (user->password == NULL) { - wpa_printf(MSG_ERROR, "Failed to allocate " - "memory for EAP password"); - goto failed; - } - if (hexstr2bin(pos, user->password, (pos2 - pos) / 2) < 0) { - wpa_printf(MSG_ERROR, - "Invalid hex password " - "on line %d in '%s'", - line, fname); - goto failed; - } - user->password_len = (pos2 - pos) / 2; - pos = pos2; - } + pos++; + } else if (os_strncmp(pos, "hash:", 5) == 0) { + pos += 5; + pos2 = pos; + while (*pos2 != '\0' && *pos2 != ' ' && + *pos2 != '\t' && *pos2 != '#') + pos2++; + if (pos2 - pos != 32) { + wpa_printf(MSG_ERROR, "Invalid password hash " + "on line %d in '%s'", line, fname); + goto failed; + } + user->password = os_malloc(16); + if (user->password == NULL) { + wpa_printf(MSG_ERROR, "Failed to allocate " + "memory for EAP password hash"); + goto failed; + } + if (hexstr2bin(pos, user->password, 16) < 0) { + wpa_printf(MSG_ERROR, "Invalid hash password " + "on line %d in '%s'", line, fname); + goto failed; + } + user->password_len = 16; + user->password_hash = 1; + pos = pos2; + } else { + pos2 = pos; + while (*pos2 != '\0' && *pos2 != ' ' && + *pos2 != '\t' && *pos2 != '#') + pos2++; + if ((pos2 - pos) & 1) { + wpa_printf(MSG_ERROR, "Invalid hex password " + "on line %d in '%s'", line, fname); + goto failed; + } + user->password = os_malloc((pos2 - pos) / 2); + if (user->password == NULL) { + wpa_printf(MSG_ERROR, "Failed to allocate " + "memory for EAP password"); + goto failed; + } + if (hexstr2bin(pos, user->password, + (pos2 - pos) / 2) < 0) { + wpa_printf(MSG_ERROR, "Invalid hex password " + "on line %d in '%s'", line, fname); + goto failed; + } + user->password_len = (pos2 - pos) / 2; + pos = pos2; + } - while (*pos == ' ' || *pos == '\t') - pos++; - if (os_strncmp(pos, "[2]", 3) == 0) { - user->phase2 = 1; - } + while (*pos == ' ' || *pos == '\t') + pos++; + if (os_strncmp(pos, "[2]", 3) == 0) { + user->phase2 = 1; + } - done: - if (tail == NULL) { - tail = new_user = user; - } else { - tail->next = user; - tail = user; - } - continue; + done: + if (tail == NULL) { + tail = new_user = user; + } else { + tail->next = user; + tail = user; + } + continue; - failed: - if (user) - hostapd_config_free_eap_user(user); - ret = -1; - break; - } + failed: + if (user) + hostapd_config_free_eap_user(user); + ret = -1; + break; + } - fclose(f); + fclose(f); - if (ret == 0) { - user = conf->eap_user; - while (user) { - struct hostapd_eap_user *prev; + if (ret == 0) { + user = conf->eap_user; + while (user) { + struct hostapd_eap_user *prev; - prev = user; - user = user->next; - hostapd_config_free_eap_user(prev); - } - conf->eap_user = new_user; - } + prev = user; + user = user->next; + hostapd_config_free_eap_user(prev); + } + conf->eap_user = new_user; + } - return ret; + return ret; } #endif /* EAP_SERVER */ + #ifndef CONFIG_NO_RADIUS static int hostapd_config_read_radius_addr(struct hostapd_radius_server **server, - int *num_server, const char *val, int def_port, - struct hostapd_radius_server **curr_serv) { - struct hostapd_radius_server *nserv; - int ret; - static int server_index = 1; + int *num_server, const char *val, int def_port, + struct hostapd_radius_server **curr_serv) +{ + struct hostapd_radius_server *nserv; + int ret; + static int server_index = 1; - nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv)); - if (nserv == NULL) - return -1; + nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv)); + if (nserv == NULL) + return -1; - *server = nserv; - nserv = &nserv[*num_server]; - (*num_server)++; - (*curr_serv) = nserv; + *server = nserv; + nserv = &nserv[*num_server]; + (*num_server)++; + (*curr_serv) = nserv; - os_memset(nserv, 0, sizeof(*nserv)); - nserv->port = def_port; - ret = hostapd_parse_ip_addr(val, &nserv->addr); - nserv->index = server_index++; + os_memset(nserv, 0, sizeof(*nserv)); + nserv->port = def_port; + ret = hostapd_parse_ip_addr(val, &nserv->addr); + nserv->index = server_index++; - return ret; + return ret; } + static struct hostapd_radius_attr * -hostapd_parse_radius_attr(const char *value) { - const char *pos; - char syntax; - struct hostapd_radius_attr *attr; - size_t len; +hostapd_parse_radius_attr(const char *value) +{ + const char *pos; + char syntax; + struct hostapd_radius_attr *attr; + size_t len; - attr = os_zalloc(sizeof(*attr)); - if (attr == NULL) - return NULL; + attr = os_zalloc(sizeof(*attr)); + if (attr == NULL) + return NULL; - attr->type = atoi(value); + attr->type = atoi(value); - pos = os_strchr(value, ':'); - if (pos == NULL) { - attr->val = wpabuf_alloc(1); - if (attr->val == NULL) { - os_free(attr); - return NULL; - } - wpabuf_put_u8(attr->val, 0); - return attr; - } + pos = os_strchr(value, ':'); + if (pos == NULL) { + attr->val = wpabuf_alloc(1); + if (attr->val == NULL) { + os_free(attr); + return NULL; + } + wpabuf_put_u8(attr->val, 0); + return attr; + } - pos++; - if (pos[0] == '\0' || pos[1] != ':') { - os_free(attr); - return NULL; - } - syntax = *pos++; - pos++; + pos++; + if (pos[0] == '\0' || pos[1] != ':') { + os_free(attr); + return NULL; + } + syntax = *pos++; + pos++; - switch (syntax) { - case 's': - attr->val = wpabuf_alloc_copy(pos, os_strlen(pos)); - break; - case 'x': - len = os_strlen(pos); - if (len & 1) - break; - len /= 2; - attr->val = wpabuf_alloc(len); - if (attr->val == NULL) - break; - if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) { - wpabuf_free(attr->val); - os_free(attr); - return NULL; - } - break; - case 'd': - attr->val = wpabuf_alloc(4); - if (attr->val) - wpabuf_put_be32(attr->val, atoi(pos)); - break; - default: - os_free(attr); - return NULL; - } + switch (syntax) { + case 's': + attr->val = wpabuf_alloc_copy(pos, os_strlen(pos)); + break; + case 'x': + len = os_strlen(pos); + if (len & 1) + break; + len /= 2; + attr->val = wpabuf_alloc(len); + if (attr->val == NULL) + break; + if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) { + wpabuf_free(attr->val); + os_free(attr); + return NULL; + } + break; + case 'd': + attr->val = wpabuf_alloc(4); + if (attr->val) + wpabuf_put_be32(attr->val, atoi(pos)); + break; + default: + os_free(attr); + return NULL; + } - if (attr->val == NULL) { - os_free(attr); - return NULL; - } + if (attr->val == NULL) { + os_free(attr); + return NULL; + } - return attr; + return attr; } -static int hostapd_parse_das_client(struct hostapd_bss_config *bss, char *val) { - char *secret; - secret = os_strchr(val, ' '); - if (secret == NULL) - return -1; +static int hostapd_parse_das_client(struct hostapd_bss_config *bss, char *val) +{ + char *secret; - *secret++ = '\0'; + secret = os_strchr(val, ' '); + if (secret == NULL) + return -1; - if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr)) - return -1; + *secret++ = '\0'; - os_free(bss->radius_das_shared_secret); - bss->radius_das_shared_secret = (u8 *)os_strdup(secret); - if (bss->radius_das_shared_secret == NULL) - return -1; - bss->radius_das_shared_secret_len = os_strlen(secret); + if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr)) + return -1; - return 0; + os_free(bss->radius_das_shared_secret); + bss->radius_das_shared_secret = (u8 *) os_strdup(secret); + if (bss->radius_das_shared_secret == NULL) + return -1; + bss->radius_das_shared_secret_len = os_strlen(secret); + + return 0; } #endif /* CONFIG_NO_RADIUS */ -static int hostapd_config_parse_key_mgmt(int line, const char *value) { - int val = 0, last; - char *start, *end, *buf; - buf = os_strdup(value); - if (buf == NULL) - return -1; - start = buf; +static int hostapd_config_parse_key_mgmt(int line, const char *value) +{ + int val = 0, last; + char *start, *end, *buf; - while (*start != '\0') { - while (*start == ' ' || *start == '\t') - start++; - if (*start == '\0') - break; - end = start; - while (*end != ' ' && *end != '\t' && *end != '\0') - end++; - last = *end == '\0'; - *end = '\0'; - if (os_strcmp(start, "WPA-PSK") == 0) - val |= WPA_KEY_MGMT_PSK; - else if (os_strcmp(start, "WPA-EAP") == 0) - val |= WPA_KEY_MGMT_IEEE8021X; + buf = os_strdup(value); + if (buf == NULL) + return -1; + start = buf; + + while (*start != '\0') { + while (*start == ' ' || *start == '\t') + start++; + if (*start == '\0') + break; + end = start; + while (*end != ' ' && *end != '\t' && *end != '\0') + end++; + last = *end == '\0'; + *end = '\0'; + if (os_strcmp(start, "WPA-PSK") == 0) + val |= WPA_KEY_MGMT_PSK; + else if (os_strcmp(start, "WPA-EAP") == 0) + val |= WPA_KEY_MGMT_IEEE8021X; #ifdef CONFIG_IEEE80211R - else if (os_strcmp(start, "FT-PSK") == 0) - val |= WPA_KEY_MGMT_FT_PSK; - else if (os_strcmp(start, "FT-EAP") == 0) - val |= WPA_KEY_MGMT_FT_IEEE8021X; + else if (os_strcmp(start, "FT-PSK") == 0) + val |= WPA_KEY_MGMT_FT_PSK; + else if (os_strcmp(start, "FT-EAP") == 0) + val |= WPA_KEY_MGMT_FT_IEEE8021X; #endif /* CONFIG_IEEE80211R */ #ifdef CONFIG_IEEE80211W - else if (os_strcmp(start, "WPA-PSK-SHA256") == 0) - val |= WPA_KEY_MGMT_PSK_SHA256; - else if (os_strcmp(start, "WPA-EAP-SHA256") == 0) - val |= WPA_KEY_MGMT_IEEE8021X_SHA256; + else if (os_strcmp(start, "WPA-PSK-SHA256") == 0) + val |= WPA_KEY_MGMT_PSK_SHA256; + else if (os_strcmp(start, "WPA-EAP-SHA256") == 0) + val |= WPA_KEY_MGMT_IEEE8021X_SHA256; #endif /* CONFIG_IEEE80211W */ #ifdef CONFIG_SAE - else if (os_strcmp(start, "SAE") == 0) - val |= WPA_KEY_MGMT_SAE; - else if (os_strcmp(start, "FT-SAE") == 0) - val |= WPA_KEY_MGMT_FT_SAE; + else if (os_strcmp(start, "SAE") == 0) + val |= WPA_KEY_MGMT_SAE; + else if (os_strcmp(start, "FT-SAE") == 0) + val |= WPA_KEY_MGMT_FT_SAE; #endif /* CONFIG_SAE */ #ifdef CONFIG_SUITEB - else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0) - val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B; + else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0) + val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B; #endif /* CONFIG_SUITEB */ #ifdef CONFIG_SUITEB192 - else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0) - val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192; + else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0) + val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192; #endif /* CONFIG_SUITEB192 */ - else { - wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'", line, start); - os_free(buf); - return -1; - } + else { + wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'", + line, start); + os_free(buf); + return -1; + } - if (last) - break; - start = end + 1; - } + if (last) + break; + start = end + 1; + } - os_free(buf); - if (val == 0) { - wpa_printf(MSG_ERROR, - "Line %d: no key_mgmt values " - "configured.", - line); - return -1; - } + os_free(buf); + if (val == 0) { + wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values " + "configured.", line); + return -1; + } - return val; + return val; } -static int hostapd_config_parse_cipher(int line, const char *value) { - int val = wpa_parse_cipher(value); - if (val < 0) { - wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.", line, value); - return -1; - } - if (val == 0) { - wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.", line); - return -1; - } - return val; + +static int hostapd_config_parse_cipher(int line, const char *value) +{ + int val = wpa_parse_cipher(value); + if (val < 0) { + wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.", + line, value); + return -1; + } + if (val == 0) { + wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.", + line); + return -1; + } + return val; } + static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx, - char *val) { - size_t len = os_strlen(val); + char *val) +{ + size_t len = os_strlen(val); - if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL) - return -1; + if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL) + return -1; - if (val[0] == '"') { - if (len < 2 || val[len - 1] != '"') - return -1; - len -= 2; - wep->key[keyidx] = os_malloc(len); - if (wep->key[keyidx] == NULL) - return -1; - os_memcpy(wep->key[keyidx], val + 1, len); - wep->len[keyidx] = len; - } else { - if (len & 1) - return -1; - len /= 2; - wep->key[keyidx] = os_malloc(len); - if (wep->key[keyidx] == NULL) - return -1; - wep->len[keyidx] = len; - if (hexstr2bin(val, wep->key[keyidx], len) < 0) - return -1; - } + if (val[0] == '"') { + if (len < 2 || val[len - 1] != '"') + return -1; + len -= 2; + wep->key[keyidx] = os_malloc(len); + if (wep->key[keyidx] == NULL) + return -1; + os_memcpy(wep->key[keyidx], val + 1, len); + wep->len[keyidx] = len; + } else { + if (len & 1) + return -1; + len /= 2; + wep->key[keyidx] = os_malloc(len); + if (wep->key[keyidx] == NULL) + return -1; + wep->len[keyidx] = len; + if (hexstr2bin(val, wep->key[keyidx], len) < 0) + return -1; + } - wep->keys_set++; + wep->keys_set++; - return 0; + return 0; } -static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val) { - char *pos; - /* for backwards compatibility, translate ' ' in conf str to ',' */ - pos = val; - while (pos) { - pos = os_strchr(pos, ' '); - if (pos) - *pos++ = ','; - } - if (freq_range_list_parse(&conf->acs_ch_list, val)) - return -1; +static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val) +{ + char *pos; - return 0; + /* for backwards compatibility, translate ' ' in conf str to ',' */ + pos = val; + while (pos) { + pos = os_strchr(pos, ' '); + if (pos) + *pos++ = ','; + } + if (freq_range_list_parse(&conf->acs_ch_list, val)) + return -1; + + return 0; } -static int hostapd_parse_intlist(int **int_list, char *val) { - int *list; - int count; - char *pos, *end; - os_free(*int_list); - *int_list = NULL; +static int hostapd_parse_intlist(int **int_list, char *val) +{ + int *list; + int count; + char *pos, *end; - pos = val; - count = 0; - while (*pos != '\0') { - if (*pos == ' ') - count++; - pos++; - } + os_free(*int_list); + *int_list = NULL; - list = os_malloc(sizeof(int) * (count + 2)); - if (list == NULL) - return -1; - pos = val; - count = 0; - while (*pos != '\0') { - end = os_strchr(pos, ' '); - if (end) - *end = '\0'; + pos = val; + count = 0; + while (*pos != '\0') { + if (*pos == ' ') + count++; + pos++; + } - list[count++] = atoi(pos); - if (!end) - break; - pos = end + 1; - } - list[count] = -1; + list = os_malloc(sizeof(int) * (count + 2)); + if (list == NULL) + return -1; + pos = val; + count = 0; + while (*pos != '\0') { + end = os_strchr(pos, ' '); + if (end) + *end = '\0'; - *int_list = list; - return 0; + list[count++] = atoi(pos); + if (!end) + break; + pos = end + 1; + } + list[count] = -1; + + *int_list = list; + return 0; } -static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname) { - struct hostapd_bss_config **all, *bss; - if (*ifname == '\0') - return -1; +static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname) +{ + struct hostapd_bss_config **all, *bss; - all = os_realloc_array(conf->bss, conf->num_bss + 1, - sizeof(struct hostapd_bss_config *)); - if (all == NULL) { - wpa_printf(MSG_ERROR, "Failed to allocate memory for " - "multi-BSS entry"); - return -1; - } - conf->bss = all; + if (*ifname == '\0') + return -1; - bss = os_zalloc(sizeof(*bss)); - if (bss == NULL) - return -1; - bss->radius = os_zalloc(sizeof(*bss->radius)); - if (bss->radius == NULL) { - wpa_printf(MSG_ERROR, "Failed to allocate memory for " - "multi-BSS RADIUS data"); - os_free(bss); - return -1; - } + all = os_realloc_array(conf->bss, conf->num_bss + 1, + sizeof(struct hostapd_bss_config *)); + if (all == NULL) { + wpa_printf(MSG_ERROR, "Failed to allocate memory for " + "multi-BSS entry"); + return -1; + } + conf->bss = all; - conf->bss[conf->num_bss++] = bss; - conf->last_bss = bss; + bss = os_zalloc(sizeof(*bss)); + if (bss == NULL) + return -1; + bss->radius = os_zalloc(sizeof(*bss->radius)); + if (bss->radius == NULL) { + wpa_printf(MSG_ERROR, "Failed to allocate memory for " + "multi-BSS RADIUS data"); + os_free(bss); + return -1; + } - hostapd_config_defaults_bss(bss); - os_strlcpy(bss->iface, ifname, sizeof(bss->iface)); - os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1); + conf->bss[conf->num_bss++] = bss; + conf->last_bss = bss; - return 0; + hostapd_config_defaults_bss(bss); + os_strlcpy(bss->iface, ifname, sizeof(bss->iface)); + os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1); + + return 0; } + /* convert floats with one decimal place to value*10 int, i.e., * "1.5" will return 15 */ -static int hostapd_config_read_int10(const char *value) { - int i, d; - char *pos; +static int hostapd_config_read_int10(const char *value) +{ + int i, d; + char *pos; - i = atoi(value); - pos = os_strchr(value, '.'); - d = 0; - if (pos) { - pos++; - if (*pos >= '0' && *pos <= '9') - d = *pos - '0'; - } + i = atoi(value); + pos = os_strchr(value, '.'); + d = 0; + if (pos) { + pos++; + if (*pos >= '0' && *pos <= '9') + d = *pos - '0'; + } - return i * 10 + d; + return i * 10 + d; } -static int valid_cw(int cw) { - return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 || cw == 63 || - cw == 127 || cw == 255 || cw == 511 || cw == 1023 || cw == 2047 || - cw == 4095 || cw == 8191 || cw == 16383 || cw == 32767); + +static int valid_cw(int cw) +{ + return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 || + cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023 || + cw == 2047 || cw == 4095 || cw == 8191 || cw == 16383 || + cw == 32767); } + enum { - IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */ - IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */ - IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */ - IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */ + IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */ + IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */ + IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */ + IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */ }; static int hostapd_config_tx_queue(struct hostapd_config *conf, - const char *name, const char *val) { - int num; - const char *pos; - struct hostapd_tx_queue_params *queue; + const char *name, const char *val) +{ + int num; + const char *pos; + struct hostapd_tx_queue_params *queue; - /* skip 'tx_queue_' prefix */ - pos = name + 9; - if (os_strncmp(pos, "data", 4) == 0 && pos[4] >= '0' && pos[4] <= '9' && - pos[5] == '_') { - num = pos[4] - '0'; - pos += 6; - } else if (os_strncmp(pos, "after_beacon_", 13) == 0 || - os_strncmp(pos, "beacon_", 7) == 0) { - wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name); - return 0; - } else { - wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos); - return -1; - } + /* skip 'tx_queue_' prefix */ + pos = name + 9; + if (os_strncmp(pos, "data", 4) == 0 && + pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') { + num = pos[4] - '0'; + pos += 6; + } else if (os_strncmp(pos, "after_beacon_", 13) == 0 || + os_strncmp(pos, "beacon_", 7) == 0) { + wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name); + return 0; + } else { + wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos); + return -1; + } - if (num >= NUM_TX_QUEUES) { - /* for backwards compatibility, do not trigger failure */ - wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name); - return 0; - } + if (num >= NUM_TX_QUEUES) { + /* for backwards compatibility, do not trigger failure */ + wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name); + return 0; + } - queue = &conf->tx_queue[num]; + queue = &conf->tx_queue[num]; - if (os_strcmp(pos, "aifs") == 0) { - queue->aifs = atoi(val); - if (queue->aifs < 0 || queue->aifs > 255) { - wpa_printf(MSG_ERROR, "Invalid AIFS value %d", queue->aifs); - return -1; - } - } else if (os_strcmp(pos, "cwmin") == 0) { - queue->cwmin = atoi(val); - if (!valid_cw(queue->cwmin)) { - wpa_printf(MSG_ERROR, "Invalid cwMin value %d", queue->cwmin); - return -1; - } - } else if (os_strcmp(pos, "cwmax") == 0) { - queue->cwmax = atoi(val); - if (!valid_cw(queue->cwmax)) { - wpa_printf(MSG_ERROR, "Invalid cwMax value %d", queue->cwmax); - return -1; - } - } else if (os_strcmp(pos, "burst") == 0) { - queue->burst = hostapd_config_read_int10(val); - } else { - wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos); - return -1; - } + if (os_strcmp(pos, "aifs") == 0) { + queue->aifs = atoi(val); + if (queue->aifs < 0 || queue->aifs > 255) { + wpa_printf(MSG_ERROR, "Invalid AIFS value %d", + queue->aifs); + return -1; + } + } else if (os_strcmp(pos, "cwmin") == 0) { + queue->cwmin = atoi(val); + if (!valid_cw(queue->cwmin)) { + wpa_printf(MSG_ERROR, "Invalid cwMin value %d", + queue->cwmin); + return -1; + } + } else if (os_strcmp(pos, "cwmax") == 0) { + queue->cwmax = atoi(val); + if (!valid_cw(queue->cwmax)) { + wpa_printf(MSG_ERROR, "Invalid cwMax value %d", + queue->cwmax); + return -1; + } + } else if (os_strcmp(pos, "burst") == 0) { + queue->burst = hostapd_config_read_int10(val); + } else { + wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos); + return -1; + } - return 0; + return 0; } + #ifdef CONFIG_IEEE80211R -static int add_r0kh(struct hostapd_bss_config *bss, char *value) { - struct ft_remote_r0kh *r0kh; - char *pos, *next; +static int add_r0kh(struct hostapd_bss_config *bss, char *value) +{ + struct ft_remote_r0kh *r0kh; + char *pos, *next; - r0kh = os_zalloc(sizeof(*r0kh)); - if (r0kh == NULL) - return -1; + r0kh = os_zalloc(sizeof(*r0kh)); + if (r0kh == NULL) + return -1; - /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */ - pos = value; - next = os_strchr(pos, ' '); - if (next) - *next++ = '\0'; - if (next == NULL || hwaddr_aton(pos, r0kh->addr)) { - wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos); - os_free(r0kh); - return -1; - } + /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */ + pos = value; + next = os_strchr(pos, ' '); + if (next) + *next++ = '\0'; + if (next == NULL || hwaddr_aton(pos, r0kh->addr)) { + wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos); + os_free(r0kh); + return -1; + } - pos = next; - next = os_strchr(pos, ' '); - if (next) - *next++ = '\0'; - if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) { - wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos); - os_free(r0kh); - return -1; - } - r0kh->id_len = next - pos - 1; - os_memcpy(r0kh->id, pos, r0kh->id_len); + pos = next; + next = os_strchr(pos, ' '); + if (next) + *next++ = '\0'; + if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) { + wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos); + os_free(r0kh); + return -1; + } + r0kh->id_len = next - pos - 1; + os_memcpy(r0kh->id, pos, r0kh->id_len); - pos = next; - if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) { - wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos); - os_free(r0kh); - return -1; - } + pos = next; + if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) { + wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos); + os_free(r0kh); + return -1; + } - r0kh->next = bss->r0kh_list; - bss->r0kh_list = r0kh; + r0kh->next = bss->r0kh_list; + bss->r0kh_list = r0kh; - return 0; + return 0; } -static int add_r1kh(struct hostapd_bss_config *bss, char *value) { - struct ft_remote_r1kh *r1kh; - char *pos, *next; - r1kh = os_zalloc(sizeof(*r1kh)); - if (r1kh == NULL) - return -1; +static int add_r1kh(struct hostapd_bss_config *bss, char *value) +{ + struct ft_remote_r1kh *r1kh; + char *pos, *next; - /* 02:01:02:03:04:05 02:01:02:03:04:05 - * 000102030405060708090a0b0c0d0e0f */ - pos = value; - next = os_strchr(pos, ' '); - if (next) - *next++ = '\0'; - if (next == NULL || hwaddr_aton(pos, r1kh->addr)) { - wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos); - os_free(r1kh); - return -1; - } + r1kh = os_zalloc(sizeof(*r1kh)); + if (r1kh == NULL) + return -1; - pos = next; - next = os_strchr(pos, ' '); - if (next) - *next++ = '\0'; - if (next == NULL || hwaddr_aton(pos, r1kh->id)) { - wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos); - os_free(r1kh); - return -1; - } + /* 02:01:02:03:04:05 02:01:02:03:04:05 + * 000102030405060708090a0b0c0d0e0f */ + pos = value; + next = os_strchr(pos, ' '); + if (next) + *next++ = '\0'; + if (next == NULL || hwaddr_aton(pos, r1kh->addr)) { + wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos); + os_free(r1kh); + return -1; + } - pos = next; - if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) { - wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos); - os_free(r1kh); - return -1; - } + pos = next; + next = os_strchr(pos, ' '); + if (next) + *next++ = '\0'; + if (next == NULL || hwaddr_aton(pos, r1kh->id)) { + wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos); + os_free(r1kh); + return -1; + } - r1kh->next = bss->r1kh_list; - bss->r1kh_list = r1kh; + pos = next; + if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) { + wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos); + os_free(r1kh); + return -1; + } - return 0; + r1kh->next = bss->r1kh_list; + bss->r1kh_list = r1kh; + + return 0; } #endif /* CONFIG_IEEE80211R */ + #ifdef CONFIG_IEEE80211N static int hostapd_config_ht_capab(struct hostapd_config *conf, - const char *capab) { - if (os_strstr(capab, "[LDPC]")) - conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP; - if (os_strstr(capab, "[HT40-]")) { - conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; - conf->secondary_channel = -1; - } - if (os_strstr(capab, "[HT40+]")) { - conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; - conf->secondary_channel = 1; - } - if (os_strstr(capab, "[SMPS-STATIC]")) { - conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK; - conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC; - } - if (os_strstr(capab, "[SMPS-DYNAMIC]")) { - conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK; - conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC; - } - if (os_strstr(capab, "[GF]")) - conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD; - if (os_strstr(capab, "[SHORT-GI-20]")) - conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ; - if (os_strstr(capab, "[SHORT-GI-40]")) - conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ; - if (os_strstr(capab, "[TX-STBC]")) - conf->ht_capab |= HT_CAP_INFO_TX_STBC; - if (os_strstr(capab, "[RX-STBC1]")) { - conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; - conf->ht_capab |= HT_CAP_INFO_RX_STBC_1; - } - if (os_strstr(capab, "[RX-STBC12]")) { - conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; - conf->ht_capab |= HT_CAP_INFO_RX_STBC_12; - } - if (os_strstr(capab, "[RX-STBC123]")) { - conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; - conf->ht_capab |= HT_CAP_INFO_RX_STBC_123; - } - if (os_strstr(capab, "[DELAYED-BA]")) - conf->ht_capab |= HT_CAP_INFO_DELAYED_BA; - if (os_strstr(capab, "[MAX-AMSDU-7935]")) - conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE; - if (os_strstr(capab, "[DSSS_CCK-40]")) - conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ; - if (os_strstr(capab, "[40-INTOLERANT]")) - conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT; - if (os_strstr(capab, "[LSIG-TXOP-PROT]")) - conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT; + const char *capab) +{ + if (os_strstr(capab, "[LDPC]")) + conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP; + if (os_strstr(capab, "[HT40-]")) { + conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; + conf->secondary_channel = -1; + } + if (os_strstr(capab, "[HT40+]")) { + conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; + conf->secondary_channel = 1; + } + if (os_strstr(capab, "[SMPS-STATIC]")) { + conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK; + conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC; + } + if (os_strstr(capab, "[SMPS-DYNAMIC]")) { + conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK; + conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC; + } + if (os_strstr(capab, "[GF]")) + conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD; + if (os_strstr(capab, "[SHORT-GI-20]")) + conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ; + if (os_strstr(capab, "[SHORT-GI-40]")) + conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ; + if (os_strstr(capab, "[TX-STBC]")) + conf->ht_capab |= HT_CAP_INFO_TX_STBC; + if (os_strstr(capab, "[RX-STBC1]")) { + conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; + conf->ht_capab |= HT_CAP_INFO_RX_STBC_1; + } + if (os_strstr(capab, "[RX-STBC12]")) { + conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; + conf->ht_capab |= HT_CAP_INFO_RX_STBC_12; + } + if (os_strstr(capab, "[RX-STBC123]")) { + conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; + conf->ht_capab |= HT_CAP_INFO_RX_STBC_123; + } + if (os_strstr(capab, "[DELAYED-BA]")) + conf->ht_capab |= HT_CAP_INFO_DELAYED_BA; + if (os_strstr(capab, "[MAX-AMSDU-7935]")) + conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE; + if (os_strstr(capab, "[DSSS_CCK-40]")) + conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ; + if (os_strstr(capab, "[40-INTOLERANT]")) + conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT; + if (os_strstr(capab, "[LSIG-TXOP-PROT]")) + conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT; - return 0; + return 0; } #endif /* CONFIG_IEEE80211N */ + #ifdef CONFIG_IEEE80211AC static int hostapd_config_vht_capab(struct hostapd_config *conf, - const char *capab) { - if (os_strstr(capab, "[MAX-MPDU-7991]")) - conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991; - if (os_strstr(capab, "[MAX-MPDU-11454]")) - conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454; - if (os_strstr(capab, "[VHT160]")) - conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; - if (os_strstr(capab, "[VHT160-80PLUS80]")) - conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; - if (os_strstr(capab, "[RXLDPC]")) - conf->vht_capab |= VHT_CAP_RXLDPC; - if (os_strstr(capab, "[SHORT-GI-80]")) - conf->vht_capab |= VHT_CAP_SHORT_GI_80; - if (os_strstr(capab, "[SHORT-GI-160]")) - conf->vht_capab |= VHT_CAP_SHORT_GI_160; - if (os_strstr(capab, "[TX-STBC-2BY1]")) - conf->vht_capab |= VHT_CAP_TXSTBC; - if (os_strstr(capab, "[RX-STBC-1]")) - conf->vht_capab |= VHT_CAP_RXSTBC_1; - if (os_strstr(capab, "[RX-STBC-12]")) - conf->vht_capab |= VHT_CAP_RXSTBC_2; - if (os_strstr(capab, "[RX-STBC-123]")) - conf->vht_capab |= VHT_CAP_RXSTBC_3; - if (os_strstr(capab, "[RX-STBC-1234]")) - conf->vht_capab |= VHT_CAP_RXSTBC_4; - if (os_strstr(capab, "[SU-BEAMFORMER]")) - conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE; - if (os_strstr(capab, "[SU-BEAMFORMEE]")) - conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE; - if (os_strstr(capab, "[BF-ANTENNA-2]") && - (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE)) - conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET); - if (os_strstr(capab, "[BF-ANTENNA-3]") && - (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE)) - conf->vht_capab |= (2 << VHT_CAP_BEAMFORMEE_STS_OFFSET); - if (os_strstr(capab, "[BF-ANTENNA-4]") && - (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE)) - conf->vht_capab |= (3 << VHT_CAP_BEAMFORMEE_STS_OFFSET); - if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") && - (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE)) - conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET); - if (os_strstr(capab, "[SOUNDING-DIMENSION-3]") && - (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE)) - conf->vht_capab |= (2 << VHT_CAP_SOUNDING_DIMENSION_OFFSET); - if (os_strstr(capab, "[SOUNDING-DIMENSION-4]") && - (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE)) - conf->vht_capab |= (3 << VHT_CAP_SOUNDING_DIMENSION_OFFSET); - if (os_strstr(capab, "[MU-BEAMFORMER]")) - conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE; - if (os_strstr(capab, "[VHT-TXOP-PS]")) - conf->vht_capab |= VHT_CAP_VHT_TXOP_PS; - if (os_strstr(capab, "[HTC-VHT]")) - conf->vht_capab |= VHT_CAP_HTC_VHT; - if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]")) - conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX; - else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]")) - conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6; - else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]")) - conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5; - else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]")) - conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4; - else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]")) - conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3; - else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]")) - conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2; - else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]")) - conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1; - if (os_strstr(capab, "[VHT-LINK-ADAPT2]") && - (conf->vht_capab & VHT_CAP_HTC_VHT)) - conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB; - if (os_strstr(capab, "[VHT-LINK-ADAPT3]") && - (conf->vht_capab & VHT_CAP_HTC_VHT)) - conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB; - if (os_strstr(capab, "[RX-ANTENNA-PATTERN]")) - conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN; - if (os_strstr(capab, "[TX-ANTENNA-PATTERN]")) - conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN; - return 0; + const char *capab) +{ + if (os_strstr(capab, "[MAX-MPDU-7991]")) + conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991; + if (os_strstr(capab, "[MAX-MPDU-11454]")) + conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454; + if (os_strstr(capab, "[VHT160]")) + conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; + if (os_strstr(capab, "[VHT160-80PLUS80]")) + conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; + if (os_strstr(capab, "[RXLDPC]")) + conf->vht_capab |= VHT_CAP_RXLDPC; + if (os_strstr(capab, "[SHORT-GI-80]")) + conf->vht_capab |= VHT_CAP_SHORT_GI_80; + if (os_strstr(capab, "[SHORT-GI-160]")) + conf->vht_capab |= VHT_CAP_SHORT_GI_160; + if (os_strstr(capab, "[TX-STBC-2BY1]")) + conf->vht_capab |= VHT_CAP_TXSTBC; + if (os_strstr(capab, "[RX-STBC-1]")) + conf->vht_capab |= VHT_CAP_RXSTBC_1; + if (os_strstr(capab, "[RX-STBC-12]")) + conf->vht_capab |= VHT_CAP_RXSTBC_2; + if (os_strstr(capab, "[RX-STBC-123]")) + conf->vht_capab |= VHT_CAP_RXSTBC_3; + if (os_strstr(capab, "[RX-STBC-1234]")) + conf->vht_capab |= VHT_CAP_RXSTBC_4; + if (os_strstr(capab, "[SU-BEAMFORMER]")) + conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE; + if (os_strstr(capab, "[SU-BEAMFORMEE]")) + conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE; + if (os_strstr(capab, "[BF-ANTENNA-2]") && + (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE)) + conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET); + if (os_strstr(capab, "[BF-ANTENNA-3]") && + (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE)) + conf->vht_capab |= (2 << VHT_CAP_BEAMFORMEE_STS_OFFSET); + if (os_strstr(capab, "[BF-ANTENNA-4]") && + (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE)) + conf->vht_capab |= (3 << VHT_CAP_BEAMFORMEE_STS_OFFSET); + if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") && + (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE)) + conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET); + if (os_strstr(capab, "[SOUNDING-DIMENSION-3]") && + (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE)) + conf->vht_capab |= (2 << VHT_CAP_SOUNDING_DIMENSION_OFFSET); + if (os_strstr(capab, "[SOUNDING-DIMENSION-4]") && + (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE)) + conf->vht_capab |= (3 << VHT_CAP_SOUNDING_DIMENSION_OFFSET); + if (os_strstr(capab, "[MU-BEAMFORMER]")) + conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE; + if (os_strstr(capab, "[VHT-TXOP-PS]")) + conf->vht_capab |= VHT_CAP_VHT_TXOP_PS; + if (os_strstr(capab, "[HTC-VHT]")) + conf->vht_capab |= VHT_CAP_HTC_VHT; + if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]")) + conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX; + else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]")) + conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6; + else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]")) + conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5; + else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]")) + conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4; + else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]")) + conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3; + else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]")) + conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2; + else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]")) + conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1; + if (os_strstr(capab, "[VHT-LINK-ADAPT2]") && + (conf->vht_capab & VHT_CAP_HTC_VHT)) + conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB; + if (os_strstr(capab, "[VHT-LINK-ADAPT3]") && + (conf->vht_capab & VHT_CAP_HTC_VHT)) + conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB; + if (os_strstr(capab, "[RX-ANTENNA-PATTERN]")) + conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN; + if (os_strstr(capab, "[TX-ANTENNA-PATTERN]")) + conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN; + return 0; } #endif /* CONFIG_IEEE80211AC */ + #ifdef CONFIG_INTERWORKING static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos, - int line) { - size_t len = os_strlen(pos); - u8 oi[MAX_ROAMING_CONSORTIUM_LEN]; + int line) +{ + size_t len = os_strlen(pos); + u8 oi[MAX_ROAMING_CONSORTIUM_LEN]; - struct hostapd_roaming_consortium *rc; + struct hostapd_roaming_consortium *rc; - if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN || - hexstr2bin(pos, oi, len / 2)) { - wpa_printf(MSG_ERROR, - "Line %d: invalid roaming_consortium " - "'%s'", - line, pos); - return -1; - } - len /= 2; + if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN || + hexstr2bin(pos, oi, len / 2)) { + wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium " + "'%s'", line, pos); + return -1; + } + len /= 2; - rc = os_realloc_array(bss->roaming_consortium, - bss->roaming_consortium_count + 1, - sizeof(struct hostapd_roaming_consortium)); - if (rc == NULL) - return -1; + rc = os_realloc_array(bss->roaming_consortium, + bss->roaming_consortium_count + 1, + sizeof(struct hostapd_roaming_consortium)); + if (rc == NULL) + return -1; - os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len); - rc[bss->roaming_consortium_count].len = len; + os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len); + rc[bss->roaming_consortium_count].len = len; - bss->roaming_consortium = rc; - bss->roaming_consortium_count++; + bss->roaming_consortium = rc; + bss->roaming_consortium_count++; - return 0; + return 0; } + static int parse_lang_string(struct hostapd_lang_string **array, - unsigned int *count, char *pos) { - char *sep, *str = NULL; - size_t clen, nlen, slen; - struct hostapd_lang_string *ls; - int ret = -1; + unsigned int *count, char *pos) +{ + char *sep, *str = NULL; + size_t clen, nlen, slen; + struct hostapd_lang_string *ls; + int ret = -1; - if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) { - str = wpa_config_parse_string(pos, &slen); - if (!str) - return -1; - pos = str; - } + if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) { + str = wpa_config_parse_string(pos, &slen); + if (!str) + return -1; + pos = str; + } - sep = os_strchr(pos, ':'); - if (sep == NULL) - goto fail; - *sep++ = '\0'; + sep = os_strchr(pos, ':'); + if (sep == NULL) + goto fail; + *sep++ = '\0'; - clen = os_strlen(pos); - if (clen < 2 || clen > sizeof(ls->lang)) - goto fail; - nlen = os_strlen(sep); - if (nlen > 252) - goto fail; + clen = os_strlen(pos); + if (clen < 2 || clen > sizeof(ls->lang)) + goto fail; + nlen = os_strlen(sep); + if (nlen > 252) + goto fail; - ls = os_realloc_array(*array, *count + 1, sizeof(struct hostapd_lang_string)); - if (ls == NULL) - goto fail; + ls = os_realloc_array(*array, *count + 1, + sizeof(struct hostapd_lang_string)); + if (ls == NULL) + goto fail; - *array = ls; - ls = &(*array)[*count]; - (*count)++; + *array = ls; + ls = &(*array)[*count]; + (*count)++; - os_memset(ls->lang, 0, sizeof(ls->lang)); - os_memcpy(ls->lang, pos, clen); - ls->name_len = nlen; - os_memcpy(ls->name, sep, nlen); + os_memset(ls->lang, 0, sizeof(ls->lang)); + os_memcpy(ls->lang, pos, clen); + ls->name_len = nlen; + os_memcpy(ls->name, sep, nlen); - ret = 0; + ret = 0; fail: - os_free(str); - return ret; + os_free(str); + return ret; } + static int parse_venue_name(struct hostapd_bss_config *bss, char *pos, - int line) { - if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) { - wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'", line, pos); - return -1; - } - return 0; + int line) +{ + if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) { + wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'", + line, pos); + return -1; + } + return 0; } + static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf, - int line) { - size_t count; - char *pos; - u8 *info = NULL, *ipos; + int line) +{ + size_t count; + char *pos; + u8 *info = NULL, *ipos; - /* format: [;][;...] */ + /* format: [;][;...] */ - count = 1; - for (pos = buf; *pos; pos++) { - if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',') - goto fail; - if (*pos == ';') - count++; - } - if (1 + count * 3 > 0x7f) - goto fail; + count = 1; + for (pos = buf; *pos; pos++) { + if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',') + goto fail; + if (*pos == ';') + count++; + } + if (1 + count * 3 > 0x7f) + goto fail; - info = os_zalloc(2 + 3 + count * 3); - if (info == NULL) - return -1; + info = os_zalloc(2 + 3 + count * 3); + if (info == NULL) + return -1; - ipos = info; - *ipos++ = 0; /* GUD - Version 1 */ - *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */ - *ipos++ = 0; /* PLMN List IEI */ - /* ext(b8) | Length of PLMN List value contents(b7..1) */ - *ipos++ = 1 + count * 3; - *ipos++ = count; /* Number of PLMNs */ + ipos = info; + *ipos++ = 0; /* GUD - Version 1 */ + *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */ + *ipos++ = 0; /* PLMN List IEI */ + /* ext(b8) | Length of PLMN List value contents(b7..1) */ + *ipos++ = 1 + count * 3; + *ipos++ = count; /* Number of PLMNs */ - pos = buf; - while (pos && *pos) { - char *mcc, *mnc; - size_t mnc_len; + pos = buf; + while (pos && *pos) { + char *mcc, *mnc; + size_t mnc_len; - mcc = pos; - mnc = os_strchr(pos, ','); - if (mnc == NULL) - goto fail; - *mnc++ = '\0'; - pos = os_strchr(mnc, ';'); - if (pos) - *pos++ = '\0'; + mcc = pos; + mnc = os_strchr(pos, ','); + if (mnc == NULL) + goto fail; + *mnc++ = '\0'; + pos = os_strchr(mnc, ';'); + if (pos) + *pos++ = '\0'; - mnc_len = os_strlen(mnc); - if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3)) - goto fail; + mnc_len = os_strlen(mnc); + if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3)) + goto fail; - /* BC coded MCC,MNC */ - /* MCC digit 2 | MCC digit 1 */ - *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0'); - /* MNC digit 3 | MCC digit 3 */ - *ipos++ = - (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) | (mcc[2] - '0'); - /* MNC digit 2 | MNC digit 1 */ - *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0'); - } + /* BC coded MCC,MNC */ + /* MCC digit 2 | MCC digit 1 */ + *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0'); + /* MNC digit 3 | MCC digit 3 */ + *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) | + (mcc[2] - '0'); + /* MNC digit 2 | MNC digit 1 */ + *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0'); + } - os_free(bss->anqp_3gpp_cell_net); - bss->anqp_3gpp_cell_net = info; - bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count; - wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information", - bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len); + os_free(bss->anqp_3gpp_cell_net); + bss->anqp_3gpp_cell_net = info; + bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count; + wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information", + bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len); - return 0; + return 0; fail: - wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s", line, buf); - os_free(info); - return -1; + wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s", + line, buf); + os_free(info); + return -1; } -static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, - int line) { - struct hostapd_nai_realm_data *realm; - size_t i, j, len; - int *offsets; - char *pos, *end, *rpos; - offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS, sizeof(int)); - if (offsets == NULL) - return -1; +static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line) +{ + struct hostapd_nai_realm_data *realm; + size_t i, j, len; + int *offsets; + char *pos, *end, *rpos; - for (i = 0; i < bss->nai_realm_count; i++) { - realm = &bss->nai_realm_data[i]; - for (j = 0; j < MAX_NAI_REALMS; j++) { - offsets[i * MAX_NAI_REALMS + j] = - realm->realm[j] ? realm->realm[j] - realm->realm_buf : -1; - } - } + offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS, + sizeof(int)); + if (offsets == NULL) + return -1; - realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1, - sizeof(struct hostapd_nai_realm_data)); - if (realm == NULL) { - os_free(offsets); - return -1; - } - bss->nai_realm_data = realm; + for (i = 0; i < bss->nai_realm_count; i++) { + realm = &bss->nai_realm_data[i]; + for (j = 0; j < MAX_NAI_REALMS; j++) { + offsets[i * MAX_NAI_REALMS + j] = + realm->realm[j] ? + realm->realm[j] - realm->realm_buf : -1; + } + } - /* patch the pointers after realloc */ - for (i = 0; i < bss->nai_realm_count; i++) { - realm = &bss->nai_realm_data[i]; - for (j = 0; j < MAX_NAI_REALMS; j++) { - int offs = offsets[i * MAX_NAI_REALMS + j]; - if (offs >= 0) - realm->realm[j] = realm->realm_buf + offs; - else - realm->realm[j] = NULL; - } - } - os_free(offsets); + realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1, + sizeof(struct hostapd_nai_realm_data)); + if (realm == NULL) { + os_free(offsets); + return -1; + } + bss->nai_realm_data = realm; - realm = &bss->nai_realm_data[bss->nai_realm_count]; - os_memset(realm, 0, sizeof(*realm)); + /* patch the pointers after realloc */ + for (i = 0; i < bss->nai_realm_count; i++) { + realm = &bss->nai_realm_data[i]; + for (j = 0; j < MAX_NAI_REALMS; j++) { + int offs = offsets[i * MAX_NAI_REALMS + j]; + if (offs >= 0) + realm->realm[j] = realm->realm_buf + offs; + else + realm->realm[j] = NULL; + } + } + os_free(offsets); - pos = buf; - realm->encoding = atoi(pos); - pos = os_strchr(pos, ','); - if (pos == NULL) - goto fail; - pos++; + realm = &bss->nai_realm_data[bss->nai_realm_count]; + os_memset(realm, 0, sizeof(*realm)); - end = os_strchr(pos, ','); - if (end) { - len = end - pos; - *end = '\0'; - } else { - len = os_strlen(pos); - } + pos = buf; + realm->encoding = atoi(pos); + pos = os_strchr(pos, ','); + if (pos == NULL) + goto fail; + pos++; - if (len > MAX_NAI_REALMLEN) { - wpa_printf(MSG_ERROR, - "Too long a realm string (%d > max %d " - "characters)", - (int)len, MAX_NAI_REALMLEN); - goto fail; - } - os_memcpy(realm->realm_buf, pos, len); + end = os_strchr(pos, ','); + if (end) { + len = end - pos; + *end = '\0'; + } else { + len = os_strlen(pos); + } - if (end) - pos = end + 1; - else - pos = NULL; + if (len > MAX_NAI_REALMLEN) { + wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d " + "characters)", (int) len, MAX_NAI_REALMLEN); + goto fail; + } + os_memcpy(realm->realm_buf, pos, len); - while (pos && *pos) { - struct hostapd_nai_realm_eap *eap; + if (end) + pos = end + 1; + else + pos = NULL; - if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) { - wpa_printf(MSG_ERROR, "Too many EAP methods"); - goto fail; - } + while (pos && *pos) { + struct hostapd_nai_realm_eap *eap; - eap = &realm->eap_method[realm->eap_method_count]; - realm->eap_method_count++; + if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) { + wpa_printf(MSG_ERROR, "Too many EAP methods"); + goto fail; + } - end = os_strchr(pos, ','); - if (end == NULL) - end = pos + os_strlen(pos); + eap = &realm->eap_method[realm->eap_method_count]; + realm->eap_method_count++; - eap->eap_method = atoi(pos); - for (;;) { - pos = os_strchr(pos, '['); - if (pos == NULL || pos > end) - break; - pos++; - if (eap->num_auths >= MAX_NAI_AUTH_TYPES) { - wpa_printf(MSG_ERROR, "Too many auth params"); - goto fail; - } - eap->auth_id[eap->num_auths] = atoi(pos); - pos = os_strchr(pos, ':'); - if (pos == NULL || pos > end) - goto fail; - pos++; - eap->auth_val[eap->num_auths] = atoi(pos); - pos = os_strchr(pos, ']'); - if (pos == NULL || pos > end) - goto fail; - pos++; - eap->num_auths++; - } + end = os_strchr(pos, ','); + if (end == NULL) + end = pos + os_strlen(pos); - if (*end != ',') - break; + eap->eap_method = atoi(pos); + for (;;) { + pos = os_strchr(pos, '['); + if (pos == NULL || pos > end) + break; + pos++; + if (eap->num_auths >= MAX_NAI_AUTH_TYPES) { + wpa_printf(MSG_ERROR, "Too many auth params"); + goto fail; + } + eap->auth_id[eap->num_auths] = atoi(pos); + pos = os_strchr(pos, ':'); + if (pos == NULL || pos > end) + goto fail; + pos++; + eap->auth_val[eap->num_auths] = atoi(pos); + pos = os_strchr(pos, ']'); + if (pos == NULL || pos > end) + goto fail; + pos++; + eap->num_auths++; + } - pos = end + 1; - } + if (*end != ',') + break; - /* Split realm list into null terminated realms */ - rpos = realm->realm_buf; - i = 0; - while (*rpos) { - if (i >= MAX_NAI_REALMS) { - wpa_printf(MSG_ERROR, "Too many realms"); - goto fail; - } - realm->realm[i++] = rpos; - rpos = os_strchr(rpos, ';'); - if (rpos == NULL) - break; - *rpos++ = '\0'; - } + pos = end + 1; + } - bss->nai_realm_count++; + /* Split realm list into null terminated realms */ + rpos = realm->realm_buf; + i = 0; + while (*rpos) { + if (i >= MAX_NAI_REALMS) { + wpa_printf(MSG_ERROR, "Too many realms"); + goto fail; + } + realm->realm[i++] = rpos; + rpos = os_strchr(rpos, ';'); + if (rpos == NULL) + break; + *rpos++ = '\0'; + } - return 0; + bss->nai_realm_count++; + + return 0; fail: - wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf); - return -1; + wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf); + return -1; } -static int parse_anqp_elem(struct hostapd_bss_config *bss, char *buf, - int line) { - char *delim; - u16 infoid; - size_t len; - struct wpabuf *payload; - struct anqp_element *elem; - delim = os_strchr(buf, ':'); - if (!delim) - return -1; - delim++; - infoid = atoi(buf); - len = os_strlen(delim); - if (len & 1) - return -1; - len /= 2; - payload = wpabuf_alloc(len); - if (!payload) - return -1; - if (hexstr2bin(delim, wpabuf_put(payload, len), len) < 0) { - wpabuf_free(payload); - return -1; - } +static int parse_anqp_elem(struct hostapd_bss_config *bss, char *buf, int line) +{ + char *delim; + u16 infoid; + size_t len; + struct wpabuf *payload; + struct anqp_element *elem; - dl_list_for_each(elem, &bss->anqp_elem, struct anqp_element, list) { - if (elem->infoid == infoid) { - /* Update existing entry */ - wpabuf_free(elem->payload); - elem->payload = payload; - return 0; - } - } + delim = os_strchr(buf, ':'); + if (!delim) + return -1; + delim++; + infoid = atoi(buf); + len = os_strlen(delim); + if (len & 1) + return -1; + len /= 2; + payload = wpabuf_alloc(len); + if (!payload) + return -1; + if (hexstr2bin(delim, wpabuf_put(payload, len), len) < 0) { + wpabuf_free(payload); + return -1; + } - /* Add a new entry */ - elem = os_zalloc(sizeof(*elem)); - if (!elem) { - wpabuf_free(payload); - return -1; - } - elem->infoid = infoid; - elem->payload = payload; - dl_list_add(&bss->anqp_elem, &elem->list); + dl_list_for_each(elem, &bss->anqp_elem, struct anqp_element, list) { + if (elem->infoid == infoid) { + /* Update existing entry */ + wpabuf_free(elem->payload); + elem->payload = payload; + return 0; + } + } - return 0; + /* Add a new entry */ + elem = os_zalloc(sizeof(*elem)); + if (!elem) { + wpabuf_free(payload); + return -1; + } + elem->infoid = infoid; + elem->payload = payload; + dl_list_add(&bss->anqp_elem, &elem->list); + + return 0; } -static int parse_qos_map_set(struct hostapd_bss_config *bss, char *buf, - int line) { - u8 qos_map_set[16 + 2 * 21], count = 0; - char *pos = buf; - int val; - for (;;) { - if (count == sizeof(qos_map_set)) { - wpa_printf(MSG_ERROR, - "Line %d: Too many qos_map_set " - "parameters '%s'", - line, buf); - return -1; - } +static int parse_qos_map_set(struct hostapd_bss_config *bss, + char *buf, int line) +{ + u8 qos_map_set[16 + 2 * 21], count = 0; + char *pos = buf; + int val; - val = atoi(pos); - if (val > 255 || val < 0) { - wpa_printf(MSG_ERROR, - "Line %d: Invalid qos_map_set " - "'%s'", - line, buf); - return -1; - } + for (;;) { + if (count == sizeof(qos_map_set)) { + wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set " + "parameters '%s'", line, buf); + return -1; + } - qos_map_set[count++] = val; - pos = os_strchr(pos, ','); - if (!pos) - break; - pos++; - } + val = atoi(pos); + if (val > 255 || val < 0) { + wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set " + "'%s'", line, buf); + return -1; + } - if (count < 16 || count & 1) { - wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'", line, buf); - return -1; - } + qos_map_set[count++] = val; + pos = os_strchr(pos, ','); + if (!pos) + break; + pos++; + } - os_memcpy(bss->qos_map_set, qos_map_set, count); - bss->qos_map_set_len = count; + if (count < 16 || count & 1) { + wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'", + line, buf); + return -1; + } - return 0; + os_memcpy(bss->qos_map_set, qos_map_set, count); + bss->qos_map_set_len = count; + + return 0; } #endif /* CONFIG_INTERWORKING */ + #ifdef CONFIG_HS20 static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf, - int line) { - u8 *conn_cap; - char *pos; + int line) +{ + u8 *conn_cap; + char *pos; - if (bss->hs20_connection_capability_len >= 0xfff0) - return -1; + if (bss->hs20_connection_capability_len >= 0xfff0) + return -1; - conn_cap = os_realloc(bss->hs20_connection_capability, - bss->hs20_connection_capability_len + 4); - if (conn_cap == NULL) - return -1; + conn_cap = os_realloc(bss->hs20_connection_capability, + bss->hs20_connection_capability_len + 4); + if (conn_cap == NULL) + return -1; - bss->hs20_connection_capability = conn_cap; - conn_cap += bss->hs20_connection_capability_len; - pos = buf; - conn_cap[0] = atoi(pos); - pos = os_strchr(pos, ':'); - if (pos == NULL) - return -1; - pos++; - WPA_PUT_LE16(conn_cap + 1, atoi(pos)); - pos = os_strchr(pos, ':'); - if (pos == NULL) - return -1; - pos++; - conn_cap[3] = atoi(pos); - bss->hs20_connection_capability_len += 4; + bss->hs20_connection_capability = conn_cap; + conn_cap += bss->hs20_connection_capability_len; + pos = buf; + conn_cap[0] = atoi(pos); + pos = os_strchr(pos, ':'); + if (pos == NULL) + return -1; + pos++; + WPA_PUT_LE16(conn_cap + 1, atoi(pos)); + pos = os_strchr(pos, ':'); + if (pos == NULL) + return -1; + pos++; + conn_cap[3] = atoi(pos); + bss->hs20_connection_capability_len += 4; - return 0; + return 0; } + static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf, - int line) { - u8 *wan_metrics; - char *pos; + int line) +{ + u8 *wan_metrics; + char *pos; - /* :
: