├── Config.in ├── LICENSE ├── Makefile ├── README.md ├── adapter ├── Config.in ├── Makefile ├── aos.mk ├── include │ ├── amp_fs.h │ ├── amp_httpc.h │ ├── amp_kv.h │ ├── amp_location.h │ ├── amp_network.h │ ├── amp_ota.h │ ├── amp_pcm.h │ ├── amp_pm.h │ ├── amp_socket.h │ ├── amp_system.h │ ├── amp_tcp.h │ ├── amp_tts.h │ ├── amp_udp.h │ └── peripheral │ │ ├── amp_hal_adc.h │ │ ├── amp_hal_can.h │ │ ├── amp_hal_dac.h │ │ ├── amp_hal_flash.h │ │ ├── amp_hal_gpio.h │ │ ├── amp_hal_i2c.h │ │ ├── amp_hal_pwm.h │ │ ├── amp_hal_rtc.h │ │ ├── amp_hal_spi.h │ │ ├── amp_hal_timer.h │ │ ├── amp_hal_uart.h │ │ └── amp_hal_wdg.h └── platform │ ├── aos-haas100 │ ├── README.md │ ├── amp_config.h │ ├── amp_fs.c │ ├── amp_kv.c │ ├── amp_ota.c │ ├── amp_platform.h │ ├── amp_pm.c │ ├── amp_socket.c │ ├── amp_system.c │ ├── amp_tls_mbedtls.c │ ├── network │ │ ├── amp_cellular.c │ │ ├── amp_dns.c │ │ ├── amp_dns.h │ │ ├── amp_httpc.c │ │ ├── amp_tcp.c │ │ ├── amp_udp.c │ │ └── amp_wifi.c │ └── peripheral │ │ ├── amp_hal_adc.c │ │ ├── amp_hal_can.c │ │ ├── amp_hal_dac.c │ │ ├── amp_hal_flash.c │ │ ├── amp_hal_gpio.c │ │ ├── amp_hal_i2c.c │ │ ├── amp_hal_pwm.c │ │ ├── amp_hal_rtc.c │ │ ├── amp_hal_spi.c │ │ ├── amp_hal_timer.c │ │ ├── amp_hal_uart.c │ │ └── amp_hal_wdg.c │ └── linux │ ├── README.md │ ├── amp_config.h │ ├── amp_flash.c │ ├── amp_fs.c │ ├── amp_kv.c │ ├── amp_platform.h │ ├── amp_pm.c │ ├── amp_socket.c │ ├── amp_system.c │ ├── amp_tls_mbedtls.c │ ├── network │ ├── amp_cellular.c │ ├── amp_httpc.c │ ├── amp_tcp.c │ ├── amp_udp.c │ └── amp_wifi.c │ └── peripheral │ ├── amp_hal_adc.c │ ├── amp_hal_can.c │ ├── amp_hal_dac.c │ ├── amp_hal_gpio.c │ ├── amp_hal_i2c.c │ ├── amp_hal_pwm.c │ ├── amp_hal_rtc.c │ ├── amp_hal_spi.c │ ├── amp_hal_timer.c │ ├── amp_hal_uart.c │ └── amp_hal_wdg.c ├── aos.mk ├── components ├── das │ ├── Config.in │ ├── Makefile │ ├── aos.mk │ ├── include │ │ ├── das.h │ │ └── das │ │ │ ├── configure.h │ │ │ ├── hardware.h │ │ │ ├── platform.h │ │ │ ├── queue.h │ │ │ ├── service.h │ │ │ ├── sha1.h │ │ │ └── sha1_alt.h │ └── src │ │ ├── board │ │ ├── das_board.c │ │ └── das_board.h │ │ ├── core │ │ ├── das_attest.c │ │ ├── das_core.c │ │ ├── proto │ │ │ ├── lsoc.pb.c │ │ │ ├── lsoc.pb.h │ │ │ ├── pb.h │ │ │ ├── pb_common.c │ │ │ ├── pb_common.h │ │ │ ├── pb_decode.c │ │ │ ├── pb_decode.h │ │ │ ├── pb_encode.c │ │ │ └── pb_encode.h │ │ ├── sha1.c │ │ └── utils.c │ │ └── service │ │ ├── netfilter │ │ ├── domain_parser.c │ │ ├── icmp_ignore.c │ │ ├── service_netfilter.c │ │ ├── tcp.h │ │ └── udp.h │ │ ├── service.c │ │ ├── service_fscan.c │ │ ├── service_lwip_nfi.c │ │ ├── service_rom.c │ │ └── service_sys.c ├── http │ ├── Config.in │ ├── Makefile │ ├── aos.mk │ ├── include │ │ ├── http.h │ │ ├── http_client.h │ │ ├── http_def_config.h │ │ ├── http_parser.h │ │ ├── http_string.h │ │ └── http_wrapper.h │ └── src │ │ ├── http_client.c │ │ ├── http_parser.c │ │ ├── http_string.c │ │ └── http_wrapper.c ├── kv │ ├── Config.in │ ├── Makefile │ ├── include │ │ └── kv_api.h │ ├── kv.c │ ├── kv_adapt.c │ ├── kv_adapt.h │ ├── kv_conf.h │ ├── kv_secure.c │ └── kv_types.h ├── linkkit │ ├── Config.in │ ├── Makefile │ ├── aos.mk │ ├── certs │ │ └── root_ca.c │ ├── dev_model │ │ ├── dev_model_api.h │ │ ├── dm_api.c │ │ ├── dm_client.c │ │ ├── dm_client.h │ │ ├── dm_client_adapter.c │ │ ├── dm_client_adapter.h │ │ ├── dm_cota.c │ │ ├── dm_cota.h │ │ ├── dm_fota.c │ │ ├── dm_fota.h │ │ ├── dm_intf.h │ │ ├── dm_ipc.c │ │ ├── dm_ipc.h │ │ ├── dm_log_report.c │ │ ├── dm_manager.c │ │ ├── dm_manager.h │ │ ├── dm_message.c │ │ ├── dm_message.h │ │ ├── dm_message_cache.c │ │ ├── dm_message_cache.h │ │ ├── dm_msg_process.c │ │ ├── dm_msg_process.h │ │ ├── dm_opt.c │ │ ├── dm_opt.h │ │ ├── dm_ota.c │ │ ├── dm_ota.h │ │ ├── dm_server.c │ │ ├── dm_server.h │ │ ├── dm_server_adapter.c │ │ ├── dm_server_adapter.h │ │ ├── dm_shadow.c │ │ ├── dm_shadow.h │ │ ├── dm_tsl_alink.c │ │ ├── dm_tsl_alink.h │ │ ├── dm_utils.c │ │ ├── dm_utils.h │ │ ├── impl_gateway.c │ │ ├── impl_gateway.h │ │ ├── impl_linkkit.c │ │ ├── impl_ntp.c │ │ ├── impl_ntp.h │ │ ├── impl_solo.c │ │ ├── impl_solo.h │ │ ├── iot_export_linkkit.h │ │ ├── iotx_cm.c │ │ ├── iotx_cm.h │ │ ├── iotx_cm_coap.c │ │ ├── iotx_cm_coap.h │ │ ├── iotx_cm_internal.h │ │ ├── iotx_cm_mqtt.c │ │ ├── iotx_cm_mqtt.h │ │ ├── iotx_dm.h │ │ ├── iotx_dm_config.h │ │ ├── iotx_dm_internal.h │ │ ├── iotx_log_report.h │ │ ├── linkkit_export.h │ │ └── linkkit_gateway_export.h │ ├── dev_sign │ │ ├── dev_sign_api.h │ │ ├── dev_sign_config.h │ │ ├── dev_sign_internal.h │ │ └── dev_sign_mqtt.c │ ├── dynamic_register │ │ ├── dynreg.c │ │ ├── dynreg_api.h │ │ └── dynreg_internal.h │ ├── infra │ │ ├── infra_activation.c │ │ ├── infra_activation.h │ │ ├── infra_aes.c │ │ ├── infra_aes.h │ │ ├── infra_cjson.c │ │ ├── infra_cjson.h │ │ ├── infra_compat.c │ │ ├── infra_compat.h │ │ ├── infra_config.h │ │ ├── infra_defs.c │ │ ├── infra_defs.h │ │ ├── infra_httpc.c │ │ ├── infra_httpc.h │ │ ├── infra_json_parser.c │ │ ├── infra_json_parser.h │ │ ├── infra_list.h │ │ ├── infra_log.c │ │ ├── infra_log.h │ │ ├── infra_md5.c │ │ ├── infra_md5.h │ │ ├── infra_net.c │ │ ├── infra_net.h │ │ ├── infra_prt_nwk_payload.c │ │ ├── infra_report.c │ │ ├── infra_report.h │ │ ├── infra_sha256.c │ │ ├── infra_sha256.h │ │ ├── infra_state.h │ │ ├── infra_string.c │ │ ├── infra_string.h │ │ ├── infra_timer.c │ │ ├── infra_timer.h │ │ └── infra_types.h │ ├── mqtt │ │ ├── MQTTConnect.h │ │ ├── MQTTConnectClient.c │ │ ├── MQTTDeserializePublish.c │ │ ├── MQTTPacket.c │ │ ├── MQTTPacket.h │ │ ├── MQTTPublish.h │ │ ├── MQTTSerializePublish.c │ │ ├── MQTTSubscribe.h │ │ ├── MQTTSubscribeClient.c │ │ ├── MQTTUnsubscribe.h │ │ ├── MQTTUnsubscribeClient.c │ │ ├── iotx_mqtt_client.c │ │ ├── iotx_mqtt_client.h │ │ ├── iotx_mqtt_config.h │ │ ├── mqtt_api.c │ │ ├── mqtt_api.h │ │ ├── mqtt_internal.h │ │ └── mqtt_wrapper.h │ ├── sdk_include.h │ ├── wrappers.h │ └── wrappers_defs.h ├── ota │ ├── Config.in │ ├── Makefile │ ├── README.md │ ├── aos.mk │ ├── hal │ │ ├── ota_hal_ctrl.c │ │ ├── ota_hal_digest.c │ │ ├── ota_hal_digest.h │ │ ├── ota_hal_fs_ctrl.c │ │ ├── ota_hal_fs_plat.c │ │ ├── ota_hal_os.c │ │ ├── ota_hal_os.h │ │ ├── ota_hal_param.c │ │ ├── ota_hal_plat.c │ │ ├── ota_hal_trans.c │ │ └── ota_hal_trans.h │ ├── include │ │ ├── ota_agent.h │ │ ├── ota_hal.h │ │ ├── ota_import.h │ │ ├── ota_log.h │ │ └── ota_updater.h │ └── ota_agent │ │ ├── Config.in │ │ ├── aos.mk │ │ ├── download │ │ ├── ota_download_file2fs_http.c │ │ └── ota_download_http.c │ │ ├── ota_service.c │ │ ├── tools │ │ ├── ota_image_package.py │ │ ├── upack_data_file.c │ │ ├── upack_data_file.h │ │ └── xz │ │ │ ├── include │ │ │ ├── xz.h │ │ │ ├── xz_config.h │ │ │ ├── xz_export.h │ │ │ ├── xz_hal_plat.h │ │ │ ├── xz_lzma2.h │ │ │ ├── xz_private.h │ │ │ └── xz_stream.h │ │ │ └── src │ │ │ ├── xz_crc32.c │ │ │ ├── xz_dec_lzma2.c │ │ │ ├── xz_dec_stream.c │ │ │ ├── xz_export.c │ │ │ └── xz_hal_plat.c │ │ ├── transport │ │ └── ota_transport_mqtt.c │ │ └── verify │ │ ├── ota_verify_hash.c │ │ └── ota_verify_rsa.c ├── ulog │ ├── Makefile │ ├── README.md │ ├── aos.mk │ ├── include │ │ └── ulog_config.h │ ├── ulog.c │ ├── ulog.h │ ├── ulog_api.h │ ├── ulog_async.c │ ├── ulog_fs_cfg.c │ ├── ulog_init.c │ ├── ulog_ring_fifo.c │ ├── ulog_ring_fifo.h │ ├── ulog_session_file.c │ ├── ulog_session_file.h │ ├── ulog_session_udp.c │ └── ulog_utility.c ├── und │ ├── Makefile │ ├── README.md │ ├── include │ │ ├── und.h │ │ ├── und_adapter.h │ │ ├── und_config.h │ │ ├── und_hal.h │ │ ├── und_log.h │ │ ├── und_manage.h │ │ ├── und_packet.h │ │ ├── und_platform.h │ │ ├── und_report.h │ │ ├── und_sched.h │ │ ├── und_types.h │ │ └── und_utils.h │ └── src │ │ ├── und.c │ │ ├── und_adapter.c │ │ ├── und_manage.c │ │ ├── und_packet.c │ │ ├── und_report.c │ │ └── und_sched.c └── uvoice │ └── include │ ├── uvoice_comb.h │ ├── uvoice_event.h │ ├── uvoice_init.h │ ├── uvoice_player.h │ └── uvoice_types.h ├── engine ├── duktape_engine │ ├── Config.in │ ├── Makefile │ ├── addons │ │ ├── advanced │ │ │ ├── audio │ │ │ │ ├── module_audioplayer.c │ │ │ │ └── module_tts.c │ │ │ ├── keypad │ │ │ │ └── module_keypad.c │ │ │ ├── location │ │ │ │ └── module_location.c │ │ │ └── und │ │ │ │ └── module_und.c │ │ ├── hardware │ │ │ ├── adc │ │ │ │ └── module_adc.c │ │ │ ├── can │ │ │ │ └── module_can.c │ │ │ ├── dac │ │ │ │ └── module_dac.c │ │ │ ├── gpio │ │ │ │ └── module_gpio.c │ │ │ ├── i2c │ │ │ │ └── module_i2c.c │ │ │ ├── ir │ │ │ │ └── module_ir.c │ │ │ ├── lcd │ │ │ │ ├── fontlib.h │ │ │ │ └── module_lcd.c │ │ │ ├── pwm │ │ │ │ └── module_pwm.c │ │ │ ├── rtc │ │ │ │ └── module_rtc.c │ │ │ ├── spi │ │ │ │ └── module_spi.c │ │ │ ├── timer │ │ │ │ └── module_timer.c │ │ │ ├── uart │ │ │ │ └── module_uart.c │ │ │ └── wdg │ │ │ │ └── module_wdg.c │ │ ├── libjs.c │ │ ├── libjs.h │ │ ├── network │ │ │ ├── cellular │ │ │ │ └── module_cellular.c │ │ │ ├── http │ │ │ │ └── module_http.c │ │ │ ├── iot │ │ │ │ └── module_iot.c │ │ │ ├── mqtt │ │ │ │ └── module_mqtt.c │ │ │ ├── tcp │ │ │ │ └── module_tcp.c │ │ │ ├── udp │ │ │ │ └── module_udp.c │ │ │ └── wifi │ │ │ │ └── module_wifi.c │ │ └── utils │ │ │ ├── builtin │ │ │ └── module_builtin.c │ │ │ ├── crypto │ │ │ └── module_crypto.c │ │ │ ├── fs │ │ │ └── module_fs.c │ │ │ ├── kv │ │ │ └── module_kv.c │ │ │ ├── pm │ │ │ ├── module_battery.c │ │ │ ├── module_charger.c │ │ │ └── module_pm.c │ │ │ ├── system │ │ │ └── module_system.c │ │ │ ├── systimer │ │ │ └── module_systimer.c │ │ │ └── ui │ │ │ ├── module_ui.c │ │ │ └── module_vm.c │ ├── aos.mk │ ├── be.c │ ├── be_inl.h │ ├── be_module_node.c │ ├── be_refs.c │ ├── duktape │ │ ├── duk_config.h │ │ ├── duk_source_meta.json │ │ ├── duktape.c │ │ └── duktape.h │ ├── repl.c │ ├── repl.h │ └── startup │ │ ├── app_entry.c │ │ ├── app_entry.h │ │ ├── page_entry.c │ │ └── page_entry.h └── lite_engine │ ├── addons │ ├── builtin │ │ └── module_builtin.c │ ├── process │ │ └── module_process.c │ └── timer │ │ ├── module_timer.c │ │ └── module_timer.h │ ├── core │ ├── be.c │ ├── be_executor.c │ ├── be_lex.c │ ├── be_module.c │ ├── be_symbol.c │ └── be_utils.c │ └── include │ ├── be.h │ ├── be_addon.h │ ├── be_api.h │ ├── be_executor.h │ ├── be_feature.h │ ├── be_global.h │ ├── be_lex.h │ ├── be_module.h │ ├── be_native_addon.h │ ├── be_symbol.h │ ├── be_types.h │ └── be_utils.h ├── entry └── amp_entry.c ├── example ├── adc.js ├── fs.js ├── gpio.js ├── http.js ├── i2c.js ├── iot.js ├── mqtt.js ├── network.js ├── promise.js ├── pwm.js ├── rtc.js ├── spi.js ├── system.js ├── tcp.js ├── uart.js ├── udp.js └── wdg.js ├── libjs ├── .babelrc ├── README.md ├── build.js ├── generator.js ├── init │ ├── process.js │ └── promise.js ├── lib │ ├── adc.js │ ├── audio.js │ ├── audioplayer.js │ ├── battery.js │ ├── can.js │ ├── charger.js │ ├── dac.js │ ├── device.js │ ├── events.js │ ├── fs.js │ ├── gpio.js │ ├── http.js │ ├── i2c.js │ ├── iot.js │ ├── keypad.js │ ├── kv.js │ ├── location.js │ ├── mqtt.js │ ├── network.js │ ├── pm.js │ ├── pwm.js │ ├── rtc.js │ ├── spi.js │ ├── tcp.js │ ├── timer.js │ ├── tts.js │ ├── uart.js │ ├── udp.js │ ├── ui.js │ ├── und.js │ ├── vm.js │ └── wdg.js └── package.json ├── main ├── Config.in ├── Makefile ├── amp_defines.h ├── amp_engine.c ├── amp_errno.h ├── amp_main.c ├── amp_task.c ├── amp_task.h └── aos.mk ├── services ├── Config.in ├── Makefile ├── amp_utils │ ├── amp_utils.c │ └── amp_utils.h ├── aos.mk ├── app_mgr │ ├── app_mgr.c │ ├── app_mgr.h │ ├── app_ntp.c │ ├── app_ntp.h │ ├── ota_socket.c │ └── ota_socket.h ├── board_mgr │ ├── board_info.c │ ├── board_info.h │ ├── board_marker.h │ ├── board_mgr.c │ └── board_mgr.h └── recovery │ ├── recovery.c │ ├── recovery.h │ └── ymodem.c ├── test ├── host │ ├── tcpServer.js │ └── udpServer.js ├── network.js ├── test_fs.js ├── test_http.js ├── test_iot.js ├── test_kv.js ├── test_mqtt.js ├── test_tcp.js └── test_udp.js ├── tools ├── config.mk └── rules.mk └── utils ├── cJSON ├── Config.in ├── Makefile ├── aos.mk ├── cJSON.c └── cJSON.h └── mbedtls ├── Makefile ├── include └── mbedtls │ ├── aes.h │ ├── asn1.h │ ├── base64.h │ ├── bignum.h │ ├── bn_mul.h │ ├── check_config.h │ ├── cipher.h │ ├── cipher_internal.h │ ├── config.h │ ├── ctr_drbg.h │ ├── debug.h │ ├── des.h │ ├── ecp.h │ ├── entropy.h │ ├── entropy_poll.h │ ├── error.h │ ├── md.h │ ├── md5.h │ ├── md_internal.h │ ├── net.h │ ├── net_sockets.h │ ├── oid.h │ ├── pem.h │ ├── pk.h │ ├── pk_internal.h │ ├── platform.h │ ├── rsa.h │ ├── sha1.h │ ├── sha256.h │ ├── ssl.h │ ├── ssl_ciphersuites.h │ ├── ssl_cookie.h │ ├── ssl_internal.h │ ├── timing.h │ ├── x509.h │ ├── x509_crl.h │ └── x509_crt.h └── library ├── aes.c ├── asn1parse.c ├── base64.c ├── bignum.c ├── cipher.c ├── cipher_wrap.c ├── ctr_drbg.c ├── debug.c ├── entropy.c ├── entropy_poll.c ├── error.c ├── md.c ├── md5.c ├── md_wrap.c ├── net_sockets.c ├── oid.c ├── pem.c ├── pk.c ├── pk_wrap.c ├── pkparse.c ├── platform.c ├── rsa.c ├── sha1.c ├── sha256.c ├── ssl_ciphersuites.c ├── ssl_cli.c ├── ssl_cookie.c ├── ssl_tls.c ├── timing.c ├── x509.c └── x509_crt.c /Config.in: -------------------------------------------------------------------------------- 1 | ################################################################### 2 | # Component enable/disable selection 3 | # in the updated build system, default is y and can not be disabled 4 | if AOS_CREATE_PROJECT 5 | config AOS_COMP_AMP 6 | bool 7 | default n 8 | # do NOT select depend component in this file 9 | # use $(NAME)_COMPONENTS in aos.mk 10 | endif 11 | 12 | # Backward compatibility 13 | if !AOS_CREATE_PROJECT 14 | config AOS_COMP_AMP 15 | bool "amp" 16 | default n 17 | select AOS_COMP_AMP_ADAPTER 18 | select AOS_COMP_AMP_COMP_DAS 19 | select AOS_COMP_AMP_COMP_HTTP 20 | select AOS_COMP_AMP_COMP_LINKKIT 21 | select AOS_COMP_AMP_ENGINE_DUK 22 | select AOS_COMP_AMP_MAIN 23 | select AOS_COMP_AMP_SERVICES 24 | select AOS_COMP_AMP_UTILS_CJSON 25 | help 26 | AliOS things mini program -- smart config support component 27 | endif 28 | -------------------------------------------------------------------------------- /adapter/Config.in: -------------------------------------------------------------------------------- 1 | ################################################################### 2 | # Component enable/disable selection 3 | # in the updated build system, default is y and can not be disabled 4 | if AOS_CREATE_PROJECT 5 | config AOS_COMP_AMP_ADAPTER 6 | bool 7 | default y 8 | # do NOT select depend component in this file 9 | # use $(NAME)_COMPONENTS in aos.mk 10 | endif 11 | 12 | # Backward compatibility 13 | if !AOS_CREATE_PROJECT 14 | config AOS_COMP_AMP_ADAPTER 15 | bool "amp_adapter" 16 | default y 17 | help 18 | AliOS things mini program -- smart config support component 19 | endif 20 | -------------------------------------------------------------------------------- /adapter/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libadapter.a 2 | MODULE = adapter 3 | 4 | MOD_SOURCES := \ 5 | platform/linux/peripheral/amp_hal_adc.c \ 6 | platform/linux/peripheral/amp_hal_dac.c \ 7 | platform/linux/peripheral/amp_hal_can.c \ 8 | platform/linux/peripheral/amp_hal_gpio.c \ 9 | platform/linux/peripheral/amp_hal_i2c.c \ 10 | platform/linux/peripheral/amp_hal_pwm.c \ 11 | platform/linux/peripheral/amp_hal_rtc.c \ 12 | platform/linux/peripheral/amp_hal_spi.c \ 13 | platform/linux/peripheral/amp_hal_timer.c \ 14 | platform/linux/peripheral/amp_hal_uart.c \ 15 | platform/linux/peripheral/amp_hal_wdg.c \ 16 | platform/linux/network/amp_cellular.c \ 17 | platform/linux/network/amp_wifi.c \ 18 | platform/linux/network/amp_tcp.c \ 19 | platform/linux/network/amp_udp.c \ 20 | platform/linux/network/amp_httpc.c \ 21 | platform/linux/amp_flash.c \ 22 | platform/linux/amp_fs.c \ 23 | platform/linux/amp_kv.c \ 24 | platform/linux/amp_pm.c \ 25 | platform/linux/amp_system.c \ 26 | platform/linux/amp_socket.c \ 27 | platform/linux/amp_tls_mbedtls.c 28 | 29 | MOD_INCLUDES := \ 30 | include \ 31 | include/peripheral \ 32 | ../components/linkkit \ 33 | ../components/linkkit/infra \ 34 | ../components/http/include \ 35 | ../components/ulog \ 36 | ../main \ 37 | ../utils/mbedtls/include \ 38 | ./platform/linux 39 | 40 | include $(TOOLS_DIR)/rules.mk 41 | -------------------------------------------------------------------------------- /adapter/aos.mk: -------------------------------------------------------------------------------- 1 | NAME = libamp_adapter 2 | 3 | $(NAME)_MBINS_TYPE := kernel 4 | $(NAME)_VERSION := 1.0.0 5 | $(NAME)_SUMMARY := amp adapter 6 | 7 | $(NAME)_SOURCES := \ 8 | platform/aos-haas100/peripheral/amp_hal_adc.c \ 9 | platform/aos-haas100/peripheral/amp_hal_dac.c \ 10 | platform/aos-haas100/peripheral/amp_hal_can.c \ 11 | platform/aos-haas100/peripheral/amp_hal_gpio.c \ 12 | platform/aos-haas100/peripheral/amp_hal_i2c.c \ 13 | platform/aos-haas100/peripheral/amp_hal_pwm.c \ 14 | platform/aos-haas100/peripheral/amp_hal_rtc.c \ 15 | platform/aos-haas100/peripheral/amp_hal_spi.c \ 16 | platform/aos-haas100/peripheral/amp_hal_timer.c \ 17 | platform/aos-haas100/peripheral/amp_hal_uart.c \ 18 | platform/aos-haas100/peripheral/amp_hal_wdg.c \ 19 | platform/aos-haas100/peripheral/amp_hal_flash.c \ 20 | platform/aos-haas100/network/amp_tcp.c \ 21 | platform/aos-haas100/network/amp_udp.c \ 22 | platform/aos-haas100/network/amp_dns.c \ 23 | platform/aos-haas100/network/amp_wifi.c \ 24 | platform/aos-haas100/network/amp_cellular.c \ 25 | platform/aos-haas100/network/amp_httpc.c \ 26 | platform/aos-haas100/amp_fs.c \ 27 | platform/aos-haas100/amp_kv.c \ 28 | platform/aos-haas100/amp_ota.c \ 29 | platform/aos-haas100/amp_pm.c \ 30 | platform/aos-haas100/amp_system.c \ 31 | platform/aos-haas100/amp_socket.c \ 32 | platform/aos-haas100/amp_tls_mbedtls.c 33 | 34 | $(NAME)_INCLUDES := \ 35 | include \ 36 | include/peripheral \ 37 | platform/aos-haas100 \ 38 | platform/aos-haas100/network \ 39 | ../main \ 40 | ../components/ota/include \ 41 | ../components/linkkit \ 42 | ../components/linkkit/infra -------------------------------------------------------------------------------- /adapter/include/amp_httpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _AMP_HTTPC_H_ 6 | #define _AMP_HTTPC_H_ 7 | 8 | #include "amp_platform.h" 9 | 10 | /** 11 | * @brief amp_httpc_get_host_by_name() get host by name. 12 | * 13 | * @param[in] name the name of the host. 14 | * 15 | * @return On success, return struct of hostent. 16 | * On error 17 | */ 18 | struct hostent *amp_httpc_get_host_by_name(const char *name); 19 | 20 | /** 21 | * @brief amp_httpc_socket_connect() http socket connect. 22 | * 23 | * @param[in] fd the file descriptor. 24 | * @param[in] name the name of sock addr. 25 | * @param[in] namelen name length. 26 | * 27 | * @return On success, return 0. 28 | * On error, negative error code is returned to indicate the cause 29 | * of the error. 30 | */ 31 | int amp_httpc_socket_connect(uintptr_t fd, const struct sockaddr *name, socklen_t namelen); 32 | 33 | #endif /* _AMP_HTTPC_H_ */ 34 | 35 | -------------------------------------------------------------------------------- /adapter/include/amp_kv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef AMP_KV_H 6 | #define AMP_KV_H 7 | 8 | /** 9 | * Add a new KV pair. 10 | * 11 | * @param[in] key the key of the KV pair. 12 | * @param[in] val the value of the KV pair. 13 | * @param[in] len the length of the value. 14 | * @param[in] sync save the KV pair to flash right now (should always be 1). 15 | * 16 | * @return 0 on success, negative error on failure. 17 | */ 18 | int amp_kv_set(const char *key, const void *val, int len, int sync); 19 | 20 | /** 21 | * Get the KV pair's value stored in buffer by its key. 22 | * 23 | * @note: the buffer_len should be larger than the real length of the value, 24 | * otherwise buffer would be NULL. 25 | * 26 | * @param[in] key the key of the KV pair to get. 27 | * @param[out] val the memory to store the value. 28 | * @param[in-out] buffer_len in: the length of the input buffer. 29 | * out: the real length of the value. 30 | * 31 | * @return 0 on success, negative error on failure. 32 | */ 33 | int amp_kv_get(const char *key, void *val, int *buffer_len); 34 | 35 | /** 36 | * Delete the KV pair by its key. 37 | * 38 | * @param[in] key the key of the KV pair to delete. 39 | * 40 | * @return 0 on success, negative error on failure. 41 | */ 42 | int amp_kv_del(const char *key); 43 | 44 | 45 | #endif /* AMP_KV_H */ 46 | -------------------------------------------------------------------------------- /adapter/include/amp_ota.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef AMP_OTA_H 6 | #define AMP_OTA_H 7 | 8 | /** 9 | * sys ota upgrade thread function. 10 | * 11 | * @param[in] ctx device information. 12 | * 13 | * @return 0 on success, negative error on failure. 14 | */ 15 | int interval_sys_upgrade_start(void *ctx); 16 | 17 | /** 18 | * submodule ota cb. 19 | * 20 | * 21 | * @param[in] ctx submodule information. 22 | * 23 | * 24 | * @return 0 on success, negative error on failure. 25 | */ 26 | int interval_module_upgrade_start(void *ctx); 27 | 28 | #endif /* AMP_OTA_H */ -------------------------------------------------------------------------------- /adapter/include/amp_tcp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _AMP_TCP_H_ 6 | #define _AMP_TCP_H_ 7 | 8 | /** 9 | * This function will establish a tcp socket. 10 | * 11 | * @param[in] host host name of tcp socket connect 12 | * @param[in] port port. 13 | * 14 | * @return 0: success, otherwise: fail. 15 | */ 16 | int amp_tcp_establish(const char *host, unsigned int port); 17 | 18 | /** 19 | * This function will destroy a tcp socket. 20 | * 21 | * @param[in] fd the file descriptor of the file or device. 22 | * 23 | * @return 0: success, otherwise: fail. 24 | */ 25 | int amp_tcp_destroy(unsigned int fd); 26 | 27 | /** 28 | * This function will send data with a tcp socket. 29 | * 30 | * @param[in] fd the file descriptor of the file or device. 31 | * @param[in] buf data buf. 32 | * @param[in] len data length. 33 | * @param[in] timeout_ms ms of timeout. 34 | * 35 | * @return 0: success, otherwise: fail. 36 | */ 37 | int amp_tcp_write(unsigned int fd, const char *buf, unsigned int len, unsigned int timeout_ms); 38 | 39 | /** 40 | * This function will receive data from a tcp socket. 41 | * 42 | * @param[in] fd the file descriptor of the file or device. 43 | * @param[in] buf data buf. 44 | * @param[in] len data length. 45 | * @param[in] timeout_ms ms of timeout. 46 | * 47 | * @return 0: success, otherwise: fail. 48 | */ 49 | int amp_tcp_read(unsigned int fd, char *buf, unsigned int len, unsigned int timeout_ms); 50 | 51 | 52 | #endif /* _AMP_TCP_H_ */ 53 | 54 | -------------------------------------------------------------------------------- /adapter/include/peripheral/amp_hal_adc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef AMP_HAL_ADC_H 6 | #define AMP_HAL_ADC_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include 13 | 14 | #define HAL_WAIT_FOREVER 0xFFFFFFFFU 15 | 16 | typedef struct { 17 | uint32_t sampling_cycle; /* sampling period in number of ADC clock cycles */ 18 | } adc_config_t; 19 | 20 | typedef struct { 21 | uint8_t port; /* adc port */ 22 | adc_config_t config; /* adc config */ 23 | void *priv; /* priv data */ 24 | } adc_dev_t; 25 | 26 | /** 27 | * Initialises an ADC interface, Prepares an ADC hardware interface for sampling 28 | * 29 | * @param[in] adc the interface which should be initialised 30 | * 31 | * @return 0 : on success, EIO : if an error occurred with any step 32 | */ 33 | int32_t amp_hal_adc_init(adc_dev_t *adc); 34 | 35 | /** 36 | * Takes a single sample from an ADC interface 37 | * 38 | * @param[in] adc the interface which should be sampled 39 | * @param[out] output pointer to a variable which will receive the sample 40 | * @param[in] timeout ms timeout 41 | * 42 | * @return 0 : on success, EIO : if an error occurred with any step 43 | */ 44 | int32_t amp_hal_adc_value_get(adc_dev_t *adc, void *output, uint32_t timeout); 45 | 46 | /** 47 | * De-initialises an ADC interface, Turns off an ADC hardware interface 48 | * 49 | * @param[in] adc the interface which should be de-initialised 50 | * 51 | * @return 0 : on success, EIO : if an error occurred with any step 52 | */ 53 | int32_t amp_hal_adc_finalize(adc_dev_t *adc); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif /* AMP_HAL_ADC_H */ 60 | 61 | -------------------------------------------------------------------------------- /adapter/include/peripheral/amp_hal_wdg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef AMP_HAL_WDG_H 6 | #define AMP_HAL_WDG_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include 13 | 14 | typedef struct { 15 | uint32_t timeout; /* Watchdag timeout */ 16 | } wdg_config_t; 17 | 18 | typedef struct { 19 | uint8_t port; /* wdg port */ 20 | wdg_config_t config; /* wdg config */ 21 | void *priv; /* priv data */ 22 | } wdg_dev_t; 23 | 24 | /** 25 | * This function will initialize the on board CPU hardware watch dog 26 | * 27 | * @param[in] wdg the watch dog device 28 | * 29 | * @return 0 : on success, EIO : if an error occurred with any step 30 | */ 31 | int32_t amp_hal_wdg_init(wdg_dev_t *wdg); 32 | 33 | /** 34 | * Reload watchdog counter. 35 | * 36 | * @param[in] wdg the watch dog device 37 | */ 38 | void amp_hal_wdg_reload(wdg_dev_t *wdg); 39 | 40 | /** 41 | * This function performs any platform-specific cleanup needed for hardware watch dog. 42 | * 43 | * @param[in] wdg the watch dog device 44 | * 45 | * @return 0 : on success, EIO : if an error occurred with any step 46 | */ 47 | int32_t amp_hal_wdg_finalize(wdg_dev_t *wdg); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* AMP_HAL_WDG_H */ 54 | 55 | -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/README.md: -------------------------------------------------------------------------------- 1 | ## aos 适配说明 2 | 3 | ### 代码目录 4 | ``` 5 | ├── amp_fs.c 6 | ├── amp_system.c 7 | ├── amp_tls_mbedtls.c 8 | ├── network 9 | │ ├── amp_tcp.c 10 | │ └── amp_udp.c 11 | ├── peripheral 12 | │ ├── amp_hal_adc.c 13 | │ ├── amp_hal_dac.c 14 | │ ├── amp_hal_gpio.c 15 | │ ├── amp_hal_i2c.c 16 | │ ├── amp_hal_pwm.c 17 | │ ├── amp_hal_rtc.c 18 | │ ├── amp_hal_spi.c 19 | │ ├── amp_hal_timer.c 20 | │ ├── amp_hal_uart.c 21 | │ └── amp_hal_wdg.c 22 | └── README.md 23 | 24 | ### 详细说明 25 | 26 | * amp_fs.c 27 | 文件系统相关接口,接口列表和详情请见 adapter/include/amp_fs.h 28 | 29 | 主要包含如:fopen、fread、fwrite等文件操作接口 30 | 31 | * amp_kv.c 32 | key、value本地数据保存,如接入阿里云物联网平台获取的device_secret等 33 | 34 | * amp_system.c 35 | 主要包含操作系统相关接口,如线程创建、信号量、锁、定时器、队列等接口 36 | 37 | * amp_tcp.c 38 | 包含TCP建立连接,发送和接收数据接口,底层网络接口会有依赖 39 | 40 | * amp_udp.c 41 | 包含UDP建立连接,收发数据等接口 42 | -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/amp_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | /* js engine low memory enabled */ 6 | // #define AMP_LOWMEMORY_ENABLE 7 | 8 | /* enable network */ 9 | #define AMP_NETWORK_ENABLE 10 | 11 | /* enable kv */ 12 | #define AMP_KV_ENABLE 13 | 14 | /* enable high-level jsapi */ 15 | #define JSE_HIGHLEVEL_JSAPI 16 | 17 | /* os */ 18 | #define JSE_CORE_ADDON_BUILDIN 19 | #define JSE_CORE_ADDON_SYSTEM 20 | #define JSE_CORE_ADDON_FS 21 | #define JSE_CORE_ADDON_KV 22 | #define JSE_CORE_ADDON_LPM 23 | #define JSE_CORE_ADDON_SYSTIMER 24 | #define JSE_CORE_ADDON_CRYPTO 25 | #define JSE_CORE_ADDON_INITJS 26 | 27 | /* periperal */ 28 | #define JSE_HW_ADDON_ADC 29 | // #define JSE_HW_ADDON_DAC 30 | // #define JSE_HW_ADDON_CAN 31 | #define JSE_HW_ADDON_GPIO 32 | #define JSE_HW_ADDON_I2C 33 | #define JSE_HW_ADDON_SPI 34 | #define JSE_HW_ADDON_TIMER 35 | #define JSE_HW_ADDON_PWM 36 | #define JSE_HW_ADDON_RTC 37 | #define JSE_HW_ADDON_UART 38 | #define JSE_HW_ADDON_WDG 39 | 40 | /* network */ 41 | #define JSE_NET_ADDON_UDP 42 | #define JSE_NET_ADDON_TCP 43 | #define JSE_NET_ADDON_MQTT 44 | #define JSE_NET_ADDON_HTTP 45 | #define JSE_NET_ADDON_IOT 46 | #define JSE_NET_ADDON_WIFI 47 | #define JSE_NET_ADDON_CELLULAR 48 | 49 | /* recovery switch & status led */ 50 | #define AMP_RECOVERY_ENABLE 51 | #define AMP_REC_UART 0 52 | #define AMP_REC_IO 26 53 | #define AMP_REC_IO_ON 0 54 | #define AMP_STATUS_IO 40 55 | #define AMP_STATUS_IO_ON 1 56 | 57 | /* repl */ 58 | // #define AMP_REPL_STDIO_EXTERNAL /* not init stdio in repl */ 59 | #define AMP_REPL_PROMPT "amp> " 60 | #define AMP_REPL_STDIO 0 61 | #define AMP_REPL_STDIO_BANDRATE 115200 62 | #define AMP_REPL_STACK_SIZE 2048 63 | 64 | /* advanced component */ 65 | #define DEBUG -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/amp_kv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "amp_kv.h" 6 | #include "aos/kv.h" 7 | 8 | int amp_kv_set(const char *key, const void *val, int len, int sync) 9 | { 10 | int ret = 0; 11 | ret = aos_kv_set(key, val, len, sync); 12 | return ret; 13 | } 14 | 15 | int amp_kv_get(const char *key, void *buffer, int *buffer_len) 16 | { 17 | int ret = 0; 18 | ret = aos_kv_get(key, buffer, buffer_len); 19 | return ret; 20 | } 21 | 22 | int amp_kv_del(const char *key) 23 | { 24 | int ret = 0; 25 | ret = aos_kv_del(key); 26 | return ret; 27 | } 28 | 29 | int amp_kv_init() 30 | { 31 | int ret = 0; 32 | ret = aos_kv_init(); 33 | return ret; 34 | } -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/amp_ota.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "amp_ota.h" 6 | #include "amp_system.h" 7 | #include "ota_agent.h" 8 | 9 | int interval_sys_upgrade_start(void *ctx) 10 | { 11 | return ota_service_start((ota_service_t*)ctx); 12 | } -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/amp_platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "stdio.h" 6 | #include 7 | #include 8 | #include "aos/errno.h" 9 | #include "aos/kernel.h" 10 | #include "aos/kv.h" 11 | #include "aos/yloop.h" 12 | #include "ulog/ulog.h" 13 | #include 14 | -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/amp_pm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "amp_pm.h" 10 | 11 | 12 | int amp_system_sleep(void) 13 | { 14 | return -1; 15 | } 16 | 17 | int amp_system_autosleep(int mode) 18 | { 19 | return -1; 20 | } 21 | 22 | int amp_wakelock_lock(void *wakelock) 23 | { 24 | return -1; 25 | } 26 | 27 | int amp_wakelock_unlock(void *wakelock) 28 | { 29 | return -1; 30 | } 31 | 32 | int amp_wakelock_timedlock(void *wakelock, unsigned int msec) 33 | { 34 | return -1; 35 | } 36 | 37 | void *amp_wakelock_create(const char *name) 38 | { 39 | return NULL; 40 | } 41 | 42 | void amp_wakelock_release(void *wakelock) 43 | { 44 | } 45 | 46 | int amp_pwrkey_notify_register(void (*cb)(int)) 47 | { 48 | return -1; 49 | } 50 | 51 | int amp_power_down(void) 52 | { 53 | return -1; 54 | } 55 | 56 | int amp_power_reset(void) 57 | { 58 | return -1; 59 | } 60 | 61 | int amp_battery_connect_state_get(int *state) 62 | { 63 | return -1; 64 | } 65 | 66 | int amp_battery_voltage_get(int *voltage) 67 | { 68 | return -1; 69 | } 70 | 71 | int amp_battery_charge_voltage_get(int *voltage) 72 | { 73 | return -1; 74 | } 75 | 76 | int amp_battery_level_get(int *level) 77 | { 78 | return -1; 79 | } 80 | 81 | int amp_battery_temperature_get(int *temperature) 82 | { 83 | return -1; 84 | } 85 | 86 | int amp_charger_connect_state_get(int *state) 87 | { 88 | return -1; 89 | } 90 | 91 | int amp_charger_current_get(int *current) 92 | { 93 | return -1; 94 | } 95 | 96 | int amp_charger_switch_set(int enable) 97 | { 98 | return -1; 99 | } 100 | 101 | -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/network/amp_cellular.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "amp_network.h" 6 | 7 | int amp_get_sim_info(amp_sim_info_t *sim_info) 8 | { 9 | int ret = -1; 10 | 11 | return ret; 12 | } 13 | 14 | int amp_get_locator_info(amp_locator_info_t *locator_info) 15 | { 16 | int ret = -1; 17 | 18 | return ret; 19 | } 20 | 21 | int amp_get_neighbor_locator_info(void (*cb)(amp_locator_info_t*, int)) 22 | { 23 | // cb(NULL, 0); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/network/amp_dns.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _AMP_DNS_H_ 6 | #define _AMP_DNS_H_ 7 | 8 | #define DNS_RESULT_COUNT (3) 9 | int dns_getaddrinfo(char *domain, char *ip[DNS_RESULT_COUNT]); 10 | 11 | #endif -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/network/amp_httpc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "amp_network.h" 6 | #include "amp_platform.h" 7 | 8 | struct hostent *amp_httpc_get_host_by_name(const char *name) 9 | { 10 | return gethostbyname(name); 11 | } 12 | 13 | int32_t amp_httpc_socket_connect(uintptr_t fd, const struct sockaddr *name, socklen_t namelen) 14 | { 15 | return connect(fd, name, namelen); 16 | } -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/network/amp_wifi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "amp_platform.h" 6 | #include "amp_network.h" 7 | #include "netmgr.h" 8 | #include "netmgr_wifi.h" 9 | 10 | int amp_wifi_init() 11 | { 12 | return wifi_service_init(); 13 | } 14 | 15 | int amp_wifi_connect(const char *ssid, const char *passwd) 16 | { 17 | #if 0 18 | netmgr_ap_config_t config; 19 | 20 | memset(&config, 0, sizeof(config)); 21 | strncpy(config.ssid, ssid, sizeof(config.ssid) - 1); 22 | strncpy(config.pwd, passwd, sizeof(config.pwd) - 1); 23 | netmgr_set_ap_config(&config); 24 | netmgr_start(false); 25 | #else 26 | wifi_service_wifi_connect(ssid, passwd, NULL, 60000); 27 | #endif 28 | return 0; 29 | } 30 | 31 | int amp_get_wifi_info(amp_wifi_info_t *wifi_info) 32 | { 33 | char ip[32]; 34 | netmgr_ap_config_t config; 35 | netmgr_stats_t stat; 36 | 37 | memset(&stat, 0, sizeof(stat)); 38 | netmgr_stats(INTERFACE_WIFI, &stat); 39 | if (!stat.ip_available) 40 | return -1; 41 | snprintf(wifi_info->ip, sizeof(wifi_info->ip), "%s", stat.ip); 42 | 43 | memset(&config, 0, sizeof(config)); 44 | netmgr_get_ap_config(&config); 45 | wifi_info->ssid = aos_malloc(strlen(config.ssid) + 1); 46 | if (!wifi_info->ssid) { 47 | return -1; 48 | } 49 | memset(wifi_info->ssid, 0, strlen(config.ssid) + 1); 50 | memcpy(wifi_info->ssid, config.ssid, strlen(config.ssid)); 51 | 52 | wifi_service_get_mac(wifi_info->mac); 53 | wifi_service_get_rssi(&wifi_info->rssi); 54 | 55 | return 0; 56 | } 57 | 58 | int amp_wifi_disconnect() 59 | { 60 | return wifi_service_disconnect(); 61 | } 62 | 63 | AMP_NETWORK_TYPE_E amp_get_network_type() 64 | { 65 | return AMP_NETWORK_WIFI; 66 | } -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/peripheral/amp_hal_adc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_adc.h" 7 | 8 | int32_t amp_hal_adc_init(adc_dev_t *adc) 9 | { 10 | return hal_adc_init(adc); 11 | } 12 | 13 | int32_t amp_hal_adc_value_get(adc_dev_t *adc, void *output, uint32_t timeout) 14 | { 15 | return hal_adc_value_get(adc, output, timeout); 16 | } 17 | 18 | int32_t amp_hal_adc_finalize(adc_dev_t *adc) 19 | { 20 | return hal_adc_finalize(adc); 21 | } -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/peripheral/amp_hal_dac.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_dac.h" 7 | 8 | int32_t amp_hal_dac_init(dac_dev_t *dac) 9 | { 10 | return hal_dac_init(dac); 11 | } 12 | 13 | int32_t amp_hal_dac_start(dac_dev_t *dac, uint32_t channel) 14 | { 15 | return hal_dac_start(dac, channel); 16 | } 17 | 18 | int32_t amp_hal_dac_stop(dac_dev_t *dac, uint32_t channel) 19 | { 20 | return hal_dac_stop(dac, channel); 21 | } 22 | 23 | int32_t amp_hal_dac_set_value(dac_dev_t *dac, uint32_t channel, uint32_t data) 24 | { 25 | return hal_dac_set_value(dac, channel, data); 26 | } 27 | 28 | int32_t amp_hal_dac_get_value(dac_dev_t *dac, uint32_t channel) 29 | { 30 | return hal_dac_get_value(dac, channel); 31 | } 32 | 33 | int32_t amp_hal_dac_finalize(dac_dev_t *dac) 34 | { 35 | return hal_dac_finalize(dac); 36 | } -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/peripheral/amp_hal_flash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_defines.h" 7 | #include "amp_hal_flash.h" 8 | #include "aos/hal/flash.h" 9 | 10 | int32_t amp_hal_flash_info_get(amp_partition_id_t in_partition, amp_hal_logic_partition_t *partition) 11 | { 12 | int32_t ret = -1; 13 | hal_partition_t tmp_id; 14 | if(partition != NULL) { 15 | ret = hal_flash_info_get((hal_partition_t)in_partition, (hal_logic_partition_t*)partition); 16 | } 17 | return ret; 18 | } 19 | 20 | int32_t amp_hal_flash_read(amp_partition_id_t id, uint32_t *offset, void *buffer, uint32_t buffer_len) 21 | { 22 | int32_t ret = -1; 23 | ret = hal_flash_read((hal_partition_t) id, offset, buffer, buffer_len); 24 | return ret; 25 | } 26 | 27 | int32_t amp_hal_flash_write(amp_partition_id_t id, uint32_t *offset, const void *buffer, uint32_t buffer_len) 28 | { 29 | int32_t ret = -1; 30 | ret = hal_flash_write((hal_partition_t) id, offset, buffer, buffer_len); 31 | return ret; 32 | } 33 | 34 | int32_t amp_hal_flash_erase(amp_partition_id_t id, uint32_t offset, uint32_t size) 35 | { 36 | int32_t ret = -1; 37 | ret = hal_flash_erase((hal_partition_t)id, offset, size); 38 | return ret; 39 | } -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/peripheral/amp_hal_i2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_i2c.h" 7 | 8 | int32_t amp_hal_i2c_init(i2c_dev_t *i2c) 9 | { 10 | return hal_i2c_init(i2c); 11 | } 12 | 13 | int32_t amp_hal_i2c_master_send(i2c_dev_t *i2c, uint16_t dev_addr, const uint8_t *data, 14 | uint16_t size, uint32_t timeout) 15 | { 16 | return hal_i2c_master_send(i2c, dev_addr, data, size, timeout); 17 | } 18 | 19 | int32_t amp_hal_i2c_master_recv(i2c_dev_t *i2c, uint16_t dev_addr, uint8_t *data, 20 | uint16_t size, uint32_t timeout) 21 | { 22 | return hal_i2c_master_recv(i2c, dev_addr, data, size, timeout); 23 | } 24 | 25 | int32_t amp_hal_i2c_slave_send(i2c_dev_t *i2c, const uint8_t *data, uint16_t size, uint32_t timeout) 26 | { 27 | return hal_i2c_slave_send(i2c, data, size, timeout); 28 | } 29 | 30 | int32_t amp_hal_i2c_slave_recv(i2c_dev_t *i2c, uint8_t *data, uint16_t size, uint32_t timeout) 31 | { 32 | return hal_i2c_slave_recv(i2c, data, size, timeout); 33 | } 34 | 35 | int32_t amp_hal_i2c_mem_write(i2c_dev_t *i2c, uint16_t dev_addr, uint16_t mem_addr, 36 | uint16_t mem_addr_size, const uint8_t *data, uint16_t size, 37 | uint32_t timeout) 38 | { 39 | return hal_i2c_mem_write(i2c, dev_addr, mem_addr, mem_addr_size, data, size, timeout); 40 | } 41 | 42 | int32_t amp_hal_i2c_mem_read(i2c_dev_t *i2c, uint16_t dev_addr, uint16_t mem_addr, 43 | uint16_t mem_addr_size, uint8_t *data, uint16_t size, 44 | uint32_t timeout) 45 | { 46 | return hal_i2c_mem_read(i2c, dev_addr, mem_addr, mem_addr_size, data, size, timeout); 47 | } 48 | 49 | int32_t amp_hal_i2c_finalize(i2c_dev_t *i2c) 50 | { 51 | return hal_i2c_finalize(i2c); 52 | } 53 | -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/peripheral/amp_hal_pwm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_pwm.h" 7 | 8 | int32_t amp_hal_pwm_init(pwm_dev_t *pwm) 9 | { 10 | return hal_pwm_init(pwm); 11 | } 12 | 13 | int32_t amp_hal_pwm_start(pwm_dev_t *pwm) 14 | { 15 | return hal_pwm_start(pwm); 16 | } 17 | 18 | int32_t amp_hal_pwm_stop(pwm_dev_t *pwm) 19 | { 20 | return hal_pwm_stop(pwm); 21 | } 22 | 23 | int32_t amp_hal_pwm_para_chg(pwm_dev_t *pwm, pwm_config_t para) 24 | { 25 | return hal_pwm_para_chg(pwm, para); 26 | } 27 | 28 | int32_t amp_hal_pwm_finalize(pwm_dev_t *pwm) 29 | { 30 | return hal_pwm_finalize(pwm); 31 | } 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/peripheral/amp_hal_rtc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_rtc.h" 7 | 8 | int32_t amp_hal_rtc_init(rtc_dev_t *rtc) 9 | { 10 | return hal_rtc_init(rtc); 11 | } 12 | 13 | int32_t amp_hal_rtc_get_time(rtc_dev_t *rtc, rtc_time_t *time) 14 | { 15 | return hal_rtc_get_time(rtc, time); 16 | } 17 | 18 | int32_t amp_hal_rtc_set_time(rtc_dev_t *rtc, const rtc_time_t *time) 19 | { 20 | return hal_rtc_set_time(rtc, time); 21 | } 22 | 23 | int32_t amp_hal_rtc_finalize(rtc_dev_t *rtc) 24 | { 25 | return hal_rtc_finalize(rtc); 26 | } -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/peripheral/amp_hal_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_spi.h" 7 | 8 | int32_t amp_hal_spi_init(spi_dev_t *spi) 9 | { 10 | return hal_spi_init(spi); 11 | } 12 | 13 | int32_t amp_hal_spi_send(spi_dev_t *spi, const uint8_t *data, uint16_t size, uint32_t timeout) 14 | { 15 | return hal_spi_send(spi, data, size, timeout); 16 | } 17 | 18 | int32_t amp_hal_spi_recv(spi_dev_t *spi, uint8_t *data, uint16_t size, uint32_t timeout) 19 | { 20 | return hal_spi_recv(spi, data, size, timeout); 21 | } 22 | 23 | int32_t amp_hal_spi_send_recv(spi_dev_t *spi, uint8_t *tx_data, uint8_t *rx_data, 24 | uint16_t size, uint32_t timeout) 25 | { 26 | return hal_spi_send_recv(spi, tx_data, rx_data, size, timeout); 27 | } 28 | 29 | int32_t amp_hal_spi_finalize(spi_dev_t *spi) 30 | { 31 | return hal_spi_finalize(spi); 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/peripheral/amp_hal_timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_timer.h" 7 | 8 | int32_t amp_hal_timer_init(timer_dev_t *tim) 9 | { 10 | return hal_timer_init(tim); 11 | } 12 | 13 | int32_t amp_hal_timer_start(timer_dev_t *tim) 14 | { 15 | return hal_timer_start(tim); 16 | } 17 | 18 | void amp_hal_timer_stop(timer_dev_t *tim) 19 | { 20 | hal_timer_stop(tim); 21 | } 22 | 23 | int32_t amp_hal_timer_para_chg(timer_dev_t *tim, timer_config_t para) 24 | { 25 | return hal_timer_para_chg(tim, para); 26 | } 27 | 28 | int32_t amp_hal_timer_finalize(timer_dev_t *tim) 29 | { 30 | return hal_timer_finalize(tim); 31 | } -------------------------------------------------------------------------------- /adapter/platform/aos-haas100/peripheral/amp_hal_wdg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_wdg.h" 7 | 8 | int32_t amp_hal_wdg_init(wdg_dev_t *wdg) 9 | { 10 | return hal_wdg_init(wdg); 11 | } 12 | 13 | void amp_hal_wdg_reload(wdg_dev_t *wdg) 14 | { 15 | hal_wdg_reload(wdg); 16 | } 17 | 18 | int32_t amp_hal_wdg_finalize(wdg_dev_t *wdg) 19 | { 20 | return hal_wdg_finalize(wdg); 21 | } -------------------------------------------------------------------------------- /adapter/platform/linux/README.md: -------------------------------------------------------------------------------- 1 | ## linux 适配说明 2 | 3 | ### 代码目录 4 | ``` 5 | ├── amp_fs.c 6 | ├── amp_kv.c 7 | ├── amp_system.c 8 | ├── amp_tls_mbedtls.c 9 | ├── network 10 | │ ├── amp_tcp.c 11 | │ └── amp_udp.c 12 | ├── peripheral 13 | │ ├── amp_hal_adc.c 14 | │ ├── amp_hal_dac.c 15 | │ ├── amp_hal_gpio.c 16 | │ ├── amp_hal_i2c.c 17 | │ ├── amp_hal_pwm.c 18 | │ ├── amp_hal_rtc.c 19 | │ ├── amp_hal_spi.c 20 | │ ├── amp_hal_timer.c 21 | │ ├── amp_hal_uart.c 22 | │ └── amp_hal_wdg.c 23 | └── README.md 24 | 25 | ### 详细说明 26 | 27 | * amp_fs.c 28 | 文件系统相关接口,接口列表和详情请见 adapter/include/amp_fs.h 29 | 30 | 主要包含如:fopen、fread、fwrite等文件操作接口 31 | 32 | * amp_kv.c 33 | key、value本地数据保存,如接入阿里云物联网平台获取的device_secret等 34 | 35 | * amp_system.c 36 | 主要包含操作系统相关接口,如线程创建、信号量、锁、定时器、队列等接口 37 | 38 | * amp_tcp.c 39 | 包含TCP建立连接,发送和接收数据接口,底层网络接口会有依赖 40 | 41 | * amp_udp.c 42 | 包含UDP建立连接,收发数据等接口 -------------------------------------------------------------------------------- /adapter/platform/linux/amp_fs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "amp_platform.h" 6 | #include "amp_fs.h" 7 | 8 | #define JSE_FS_USER_DIR "." 9 | 10 | int amp_get_user_dir(char *dir) 11 | { 12 | memcpy(dir, JSE_FS_USER_DIR, strlen(JSE_FS_USER_DIR)); 13 | dir[strlen(JSE_FS_USER_DIR)] = '\0'; 14 | return 0; 15 | } 16 | 17 | int amp_fs_init() 18 | { 19 | return 0; 20 | } 21 | 22 | void *amp_fopen(const char *path, const char *mode) 23 | { 24 | return (void *)fopen(path, mode); 25 | } 26 | 27 | int amp_fclose(void *stream) 28 | { 29 | return fclose((FILE *)stream); 30 | } 31 | 32 | int amp_fseek(void *stream, int offset, int whence, int *curpos) 33 | { 34 | *curpos = -1; 35 | return fseek((FILE *)stream, offset, whence); 36 | } 37 | 38 | int amp_fread(void *buff, unsigned int size, unsigned int count, void *stream) 39 | { 40 | return fread(buff, (size_t)size, (size_t)count, (FILE *)stream); 41 | } 42 | 43 | int amp_fwrite(void *buff, unsigned int size, unsigned int count, void *stream) 44 | { 45 | return fwrite(buff, size, count, stream); 46 | } 47 | 48 | int amp_fsync(void *stream) 49 | { 50 | return 0; 51 | } 52 | 53 | int amp_stat(const char *path, amp_stat_t *st) 54 | { 55 | struct stat _stat; 56 | int ret = stat(path, &_stat); 57 | st->st_mode = _stat.st_mode; 58 | st->st_size = _stat.st_size; 59 | return ret; 60 | } 61 | 62 | int amp_remove(const char *path) 63 | { 64 | return unlink(path); 65 | } 66 | 67 | int amp_mkdir(const char *path) 68 | { 69 | return mkdir(path, mkdir); 70 | } 71 | 72 | int amp_rmdir(const char *path) 73 | { 74 | return rmdir(path); 75 | } 76 | 77 | 78 | long amp_ftell(void *stream) 79 | { 80 | return ftell((FILE *)stream); 81 | } 82 | 83 | int amp_fs_type(unsigned int mode) 84 | { 85 | return S_ISREG(mode); 86 | } -------------------------------------------------------------------------------- /adapter/platform/linux/amp_platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #ifdef AMP_UI_SUPPORT 40 | #include 41 | #include "aui_drivers/display/monitor.h" 42 | #include "aui_drivers/indev/mouse.h" 43 | #include "aui_drivers/indev/mousewheel.h" 44 | #include "aui_drivers/indev/keyboard.h" 45 | #endif -------------------------------------------------------------------------------- /adapter/platform/linux/amp_pm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "amp_platform.h" 6 | #include "amp_pm.h" 7 | 8 | int32_t amp_system_sleep(void) 9 | { 10 | return -1; 11 | } 12 | 13 | int32_t amp_system_autosleep(int mode) 14 | { 15 | return -1; 16 | } 17 | 18 | int32_t amp_wakelock_lock(void *wakelock) 19 | { 20 | return -1; 21 | } 22 | 23 | int32_t amp_wakelock_unlock(void *wakelock) 24 | { 25 | return -1; 26 | } 27 | 28 | int32_t amp_wakelock_timedlock(void *wakelock, unsigned int msec) 29 | { 30 | return -1; 31 | } 32 | 33 | void *amp_wakelock_create(const char *name) 34 | { 35 | return NULL; 36 | } 37 | 38 | void amp_wakelock_release(void *wakelock) 39 | { 40 | } 41 | 42 | int amp_pwrkey_notify_register(void (*cb)(int)) 43 | { 44 | return -1; 45 | } 46 | 47 | int amp_power_down(void) 48 | { 49 | return -1; 50 | } 51 | 52 | int amp_power_reset(void) 53 | { 54 | return -1; 55 | } 56 | 57 | int amp_battery_connect_state_get(int *state) 58 | { 59 | return -1; 60 | } 61 | 62 | int amp_battery_voltage_get(int *voltage) 63 | { 64 | return -1; 65 | } 66 | 67 | int amp_battery_charge_voltage_get(int *voltage) 68 | { 69 | return -1; 70 | } 71 | 72 | int amp_battery_level_get(int *level) 73 | { 74 | return -1; 75 | } 76 | 77 | int amp_battery_temperature_get(int *temperature) 78 | { 79 | return -1; 80 | } 81 | 82 | int amp_charger_connect_state_get(int *state) 83 | { 84 | return -1; 85 | } 86 | 87 | int amp_charger_current_get(int *current) 88 | { 89 | return -1; 90 | } 91 | 92 | int amp_charger_switch_set(int enable) 93 | { 94 | return -1; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /adapter/platform/linux/network/amp_cellular.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "amp_network.h" 6 | 7 | int amp_get_sim_info(amp_sim_info_t *sim_info) 8 | { 9 | int ret = -1; 10 | 11 | char imsi[24] = {0}; 12 | char imei[32] = {0}; 13 | char iccid[24] = {0}; 14 | 15 | memset(sim_info, 0x0, sizeof(amp_sim_info_t)); 16 | 17 | memcpy(sim_info->imsi, imsi, 24); 18 | memcpy(sim_info->imei, imei, 32); 19 | memcpy(sim_info->iccid, iccid, 24); 20 | 21 | return 0; 22 | } 23 | 24 | int amp_get_locator_info(amp_locator_info_t *locator_info) 25 | { 26 | int ret = -1; 27 | 28 | char mcc[4] = {0}; 29 | char mnc[4] = {0}; 30 | 31 | memset(locator_info, 0x0, sizeof(amp_locator_info_t)); 32 | 33 | memcpy(locator_info->mcc, mcc, 4); 34 | memcpy(locator_info->mnc, mnc, 4); 35 | locator_info->cellid = 0; 36 | locator_info->lac = 0; 37 | 38 | return 0; 39 | } 40 | 41 | int amp_get_neighbor_locator_info(void (*cb)(amp_locator_info_t*, int)) 42 | { 43 | // cb(NULL, 0); 44 | return 0; 45 | } -------------------------------------------------------------------------------- /adapter/platform/linux/network/amp_httpc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "amp_network.h" 6 | #include "amp_platform.h" 7 | 8 | struct hostent *amp_httpc_get_host_by_name(const char *name) 9 | { 10 | return gethostbyname(name); 11 | } 12 | 13 | int32_t amp_httpc_socket_connect(uintptr_t fd, const struct sockaddr *name, socklen_t namelen) 14 | { 15 | return connect(fd, name, namelen); 16 | } -------------------------------------------------------------------------------- /adapter/platform/linux/network/amp_wifi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "amp_network.h" 6 | 7 | int amp_wifi_init() 8 | { 9 | return 0; 10 | } 11 | 12 | int amp_wifi_connect(const char *ssid, const char *passwd) 13 | { 14 | return -1; 15 | } 16 | 17 | int amp_get_wifi_info(amp_wifi_info_t *wifi_info) 18 | { 19 | return -1; 20 | } 21 | 22 | int amp_wifi_disconnect() 23 | { 24 | return -1; 25 | } -------------------------------------------------------------------------------- /adapter/platform/linux/peripheral/amp_hal_adc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_adc.h" 7 | 8 | int32_t amp_hal_adc_init(adc_dev_t *adc) 9 | { 10 | return 0; 11 | } 12 | 13 | int32_t amp_hal_adc_value_get(adc_dev_t *adc, void *output, uint32_t timeout) 14 | { 15 | return 0; 16 | } 17 | 18 | int32_t amp_hal_adc_finalize(adc_dev_t *adc) 19 | { 20 | return 0; 21 | } -------------------------------------------------------------------------------- /adapter/platform/linux/peripheral/amp_hal_can.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_can.h" 7 | 8 | int32_t amp_hal_can_init(can_dev_t *can) 9 | { 10 | return 0; 11 | } 12 | 13 | int32_t amp_hal_can_filter_init(can_dev_t *can, const uint8_t filter_grp_cnt, can_filter_item_t *filter_config) 14 | { 15 | return 0; 16 | } 17 | 18 | int32_t amp_hal_can_send(can_dev_t *can, can_frameheader_t *tx_header, const void *data, const uint32_t timeout) 19 | { 20 | return 0; 21 | } 22 | 23 | int32_t amp_hal_can_recv(can_dev_t *can, can_frameheader_t *rx_header, void *data, const uint32_t timeout) 24 | { 25 | return 0; 26 | } 27 | 28 | int32_t amp_hal_can_finalize(can_dev_t *can) 29 | { 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /adapter/platform/linux/peripheral/amp_hal_dac.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_dac.h" 7 | 8 | int32_t amp_hal_dac_init(dac_dev_t *dac) 9 | { 10 | return 0; 11 | } 12 | 13 | int32_t amp_hal_dac_start(dac_dev_t *dac, uint32_t channel) 14 | { 15 | return 0; 16 | } 17 | 18 | int32_t amp_hal_dac_stop(dac_dev_t *dac, uint32_t channel) 19 | { 20 | return 0; 21 | } 22 | 23 | int32_t amp_hal_dac_set_value(dac_dev_t *dac, uint32_t channel, uint32_t data) 24 | { 25 | return 0; 26 | } 27 | 28 | int32_t amp_hal_dac_get_value(dac_dev_t *dac, uint32_t channel) 29 | { 30 | return 0; 31 | } 32 | 33 | int32_t amp_hal_dac_finalize(dac_dev_t *dac) 34 | { 35 | return 0; 36 | } -------------------------------------------------------------------------------- /adapter/platform/linux/peripheral/amp_hal_gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_gpio.h" 7 | 8 | int32_t amp_hal_gpio_init(gpio_dev_t *gpio) 9 | { 10 | return 0; 11 | } 12 | 13 | int32_t amp_hal_gpio_output_high(gpio_dev_t *gpio) 14 | { 15 | return 0; 16 | } 17 | 18 | int32_t amp_hal_gpio_output_low(gpio_dev_t *gpio) 19 | { 20 | return 0; 21 | } 22 | 23 | int32_t amp_hal_gpio_output_toggle(gpio_dev_t *gpio) 24 | { 25 | return 0; 26 | } 27 | 28 | int32_t amp_hal_gpio_input_get(gpio_dev_t *gpio, uint32_t *value) 29 | { 30 | return 0; 31 | } 32 | 33 | int32_t amp_hal_gpio_enable_irq(gpio_dev_t *gpio, gpio_irq_trigger_t trigger, 34 | gpio_irq_handler_t handler, void *arg) 35 | { 36 | return 0; 37 | } 38 | 39 | int32_t amp_hal_gpio_disable_irq(gpio_dev_t *gpio) 40 | { 41 | return 0; 42 | } 43 | 44 | int32_t amp_hal_gpio_clear_irq(gpio_dev_t *gpio) 45 | { 46 | return 0; 47 | } 48 | 49 | int32_t amp_hal_gpio_finalize(gpio_dev_t *gpio) 50 | { 51 | return 0; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /adapter/platform/linux/peripheral/amp_hal_i2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_i2c.h" 7 | 8 | int32_t amp_hal_i2c_init(i2c_dev_t *i2c) 9 | { 10 | return 0; 11 | } 12 | 13 | int32_t amp_hal_i2c_master_send(i2c_dev_t *i2c, uint16_t dev_addr, const uint8_t *data, 14 | uint16_t size, uint32_t timeout) 15 | { 16 | return 0; 17 | } 18 | 19 | int32_t amp_hal_i2c_master_recv(i2c_dev_t *i2c, uint16_t dev_addr, uint8_t *data, 20 | uint16_t size, uint32_t timeout) 21 | { 22 | return 0; 23 | } 24 | 25 | int32_t amp_hal_i2c_slave_send(i2c_dev_t *i2c, const uint8_t *data, uint16_t size, uint32_t timeout) 26 | { 27 | return 0; 28 | } 29 | 30 | int32_t amp_hal_i2c_slave_recv(i2c_dev_t *i2c, uint8_t *data, uint16_t size, uint32_t timeout) 31 | { 32 | return 0; 33 | } 34 | 35 | int32_t amp_hal_i2c_mem_write(i2c_dev_t *i2c, uint16_t dev_addr, uint16_t mem_addr, 36 | uint16_t mem_addr_size, const uint8_t *data, uint16_t size, 37 | uint32_t timeout) 38 | { 39 | return 0; 40 | } 41 | 42 | int32_t amp_hal_i2c_mem_read(i2c_dev_t *i2c, uint16_t dev_addr, uint16_t mem_addr, 43 | uint16_t mem_addr_size, uint8_t *data, uint16_t size, 44 | uint32_t timeout) 45 | { 46 | return 0; 47 | } 48 | 49 | int32_t amp_hal_i2c_finalize(i2c_dev_t *i2c) 50 | { 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /adapter/platform/linux/peripheral/amp_hal_pwm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_pwm.h" 7 | 8 | int32_t amp_hal_pwm_init(pwm_dev_t *pwm) 9 | { 10 | return 0; 11 | } 12 | 13 | int32_t amp_hal_pwm_start(pwm_dev_t *pwm) 14 | { 15 | return 0; 16 | } 17 | 18 | int32_t amp_hal_pwm_stop(pwm_dev_t *pwm) 19 | { 20 | return 0; 21 | } 22 | 23 | int32_t amp_hal_pwm_para_chg(pwm_dev_t *pwm, pwm_config_t para) 24 | { 25 | return 0; 26 | } 27 | 28 | int32_t amp_hal_pwm_finalize(pwm_dev_t *pwm) 29 | { 30 | return 0; 31 | } 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /adapter/platform/linux/peripheral/amp_hal_rtc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_rtc.h" 7 | 8 | int32_t amp_hal_rtc_init(rtc_dev_t *rtc) 9 | { 10 | return 0; 11 | } 12 | 13 | int32_t amp_hal_rtc_get_time(rtc_dev_t *rtc, rtc_time_t *time) 14 | { 15 | time->year = 120; 16 | time->month = 5; 17 | time->date = 21; 18 | time->hr = 17; 19 | time->min = 45; 20 | time->sec = 55; 21 | return 0; 22 | } 23 | 24 | int32_t amp_hal_rtc_set_time(rtc_dev_t *rtc, const rtc_time_t *time) 25 | { 26 | return 0; 27 | } 28 | 29 | int32_t amp_hal_rtc_finalize(rtc_dev_t *rtc) 30 | { 31 | return 0; 32 | } -------------------------------------------------------------------------------- /adapter/platform/linux/peripheral/amp_hal_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_spi.h" 7 | 8 | int32_t amp_hal_spi_init(spi_dev_t *spi) 9 | { 10 | return 0; 11 | } 12 | 13 | int32_t amp_hal_spi_send(spi_dev_t *spi, const uint8_t *data, uint16_t size, uint32_t timeout) 14 | { 15 | return 0; 16 | } 17 | 18 | int32_t amp_hal_spi_recv(spi_dev_t *spi, uint8_t *data, uint16_t size, uint32_t timeout) 19 | { 20 | return 0; 21 | } 22 | 23 | int32_t amp_hal_spi_send_recv(spi_dev_t *spi, uint8_t *tx_data, uint8_t *rx_data, 24 | uint16_t size, uint32_t timeout) 25 | { 26 | return 0; 27 | } 28 | 29 | int32_t amp_hal_spi_finalize(spi_dev_t *spi) 30 | { 31 | return 0; 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /adapter/platform/linux/peripheral/amp_hal_timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_timer.h" 7 | 8 | int32_t amp_hal_timer_init(timer_dev_t *tim) 9 | { 10 | return 0; 11 | } 12 | 13 | int32_t amp_hal_timer_start(timer_dev_t *tim) 14 | { 15 | return 0; 16 | } 17 | 18 | void amp_hal_timer_stop(timer_dev_t *tim) 19 | { 20 | 21 | } 22 | 23 | int32_t amp_hal_timer_para_chg(timer_dev_t *tim, timer_config_t para) 24 | { 25 | return 0; 26 | } 27 | 28 | int32_t amp_hal_timer_finalize(timer_dev_t *tim) 29 | { 30 | return 0; 31 | } -------------------------------------------------------------------------------- /adapter/platform/linux/peripheral/amp_hal_wdg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "amp_hal_wdg.h" 7 | 8 | int32_t amp_hal_wdg_init(wdg_dev_t *wdg) 9 | { 10 | return 0; 11 | } 12 | 13 | void amp_hal_wdg_reload(wdg_dev_t *wdg) 14 | { 15 | 16 | } 17 | 18 | int32_t amp_hal_wdg_finalize(wdg_dev_t *wdg) 19 | { 20 | return 0; 21 | } -------------------------------------------------------------------------------- /aos.mk: -------------------------------------------------------------------------------- 1 | NAME := amp 2 | 3 | $(NAME)_MBINS_TYPE := kernel 4 | $(NAME)_VERSION := 1.0.0 5 | $(NAME)_SUMMARY := haas amp utils 6 | 7 | GLOBAL_CFLAGS += -DFORCE_SSL_VERIFY 8 | 9 | CONFIG_LIB_EXPORT ?= static 10 | 11 | $(NAME)_INCLUDES += \ 12 | include/ \ 13 | ./include/ \ 14 | ./adapter/include/ \ 15 | ./adapter/include/peripheral/ \ 16 | 17 | ##################################################################### 18 | $(NAME)_COMPONENTS-y := libamp_adapter 19 | $(NAME)_COMPONENTS-y += libamp_linkkit 20 | $(NAME)_COMPONENTS-y += libamp_ota 21 | $(NAME)_COMPONENTS-y += libamp_http 22 | $(NAME)_COMPONENTS-y += libamp_das 23 | $(NAME)_COMPONENTS-y += libamp_jsengine 24 | $(NAME)_COMPONENTS-y += libamp_main 25 | $(NAME)_COMPONENTS-y += libamp_services 26 | $(NAME)_COMPONENTS-y += libamp_cjson 27 | #$(NAME)_COMPONENTS-y += libamp_ulog 28 | #$(NAME)_COMPONENTS-y += libamp_mbedtls 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /components/das/Config.in: -------------------------------------------------------------------------------- 1 | ################################################################### 2 | # Component enable/disable selection 3 | # in the updated build system, default is y and can not be disabled 4 | if AOS_CREATE_PROJECT 5 | config AOS_COMP_AMP_COMP_DAS 6 | bool 7 | default y 8 | # do NOT select depend component in this file 9 | # use $(NAME)_COMPONENTS in aos.mk 10 | endif 11 | 12 | # Backward compatibility 13 | if !AOS_CREATE_PROJECT 14 | config AOS_COMP_AMP_COMP_DAS 15 | bool "amp_comp_das" 16 | default y 17 | help 18 | AliOS things mini program -- smart config support component 19 | endif -------------------------------------------------------------------------------- /components/das/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libdas.a 2 | MODULE = das 3 | 4 | MOD_SOURCES += \ 5 | src/core/das_attest.c \ 6 | src/core/das_core.c \ 7 | src/core/sha1.c \ 8 | src/core/utils.c \ 9 | src/core/proto/lsoc.pb.c \ 10 | src/core/proto/pb_common.c \ 11 | src/core/proto/pb_decode.c \ 12 | src/core/proto/pb_encode.c 13 | 14 | MOD_SOURCES += \ 15 | src/service/service_fscan.c \ 16 | src/service/service_lwip_nfi.c \ 17 | src/service/service_rom.c \ 18 | src/service/service_sys.c \ 19 | src/service/service.c \ 20 | src/service/netfilter/domain_parser.c \ 21 | src/service/netfilter/icmp_ignore.c \ 22 | src/service/netfilter/service_netfilter.c 23 | 24 | MOD_SOURCES += \ 25 | src/board/das_board.c 26 | 27 | MOD_INCLUDES := \ 28 | include \ 29 | include/das \ 30 | src/board 31 | 32 | include $(TOOLS_DIR)/rules.mk 33 | -------------------------------------------------------------------------------- /components/das/aos.mk: -------------------------------------------------------------------------------- 1 | NAME = libamp_das 2 | 3 | $(NAME)_SOURCES += \ 4 | src/core/das_attest.c \ 5 | src/core/das_core.c \ 6 | src/core/sha1.c \ 7 | src/core/utils.c \ 8 | src/core/proto/lsoc.pb.c \ 9 | src/core/proto/pb_common.c \ 10 | src/core/proto/pb_decode.c \ 11 | src/core/proto/pb_encode.c 12 | 13 | $(NAME)_SOURCES += \ 14 | src/service/service_fscan.c \ 15 | src/service/service_lwip_nfi.c \ 16 | src/service/service_rom.c \ 17 | src/service/service_sys.c \ 18 | src/service/service.c \ 19 | src/service/netfilter/domain_parser.c \ 20 | src/service/netfilter/icmp_ignore.c \ 21 | src/service/netfilter/service_netfilter.c 22 | 23 | $(NAME)_SOURCES += \ 24 | src/board/das_board.c 25 | 26 | $(NAME)_INCLUDES := \ 27 | include \ 28 | include/das \ 29 | src/board 30 | 31 | -------------------------------------------------------------------------------- /components/das/include/das.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __DAS_H__ 6 | #define __DAS_H__ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | typedef int das_result_t; 16 | 17 | /* Result Codes */ 18 | #define DAS_SUCCESS (0) 19 | #define DAS_ERROR_GENERIC (-1) 20 | #define DAS_ERROR_BAD_PARAMETERS (-2) 21 | #define DAS_ERROR_SHORT_BUFFER (-3) 22 | #define DAS_ERROR_EXCESS_DATA (-4) 23 | #define DAS_ERROR_OUT_OF_MEMORY (-5) 24 | #define DAS_ERROR_COMMUNICATION (-6) 25 | #define DAS_ERROR_NOT_SUPPORTED (-7) 26 | #define DAS_ERROR_NOT_IMPLEMENTED (-8) 27 | #define DAS_ERROR_TIMEOUT (-9) 28 | 29 | typedef int (*publish_handle_t)(const char *topic, const uint8_t *message, size_t msg_size, void *channel); 30 | 31 | void *das_init(const char *product_name, const char *device_name); 32 | void das_final(void *session); 33 | 34 | const char *das_sub_topic(void *session, const char *topic); 35 | const char *das_pub_topic(void *session, const char *topic); 36 | 37 | void das_connection(void *session, publish_handle_t publish_handle, void *channel); 38 | 39 | void das_on_connected(void *session); 40 | void das_on_disconnected(void *session); 41 | void das_on_message(void *session, const uint8_t *message, size_t msg_size); 42 | 43 | das_result_t das_stepping(void *session, uint64_t now); 44 | 45 | int das_attest(const char* tag, ...); 46 | 47 | int das_set_firmware_version(char *ver); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* __DAS_H__ */ 54 | -------------------------------------------------------------------------------- /components/das/include/das/hardware.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __DAS_HARDWARE_H__ 6 | #define __DAS_HARDWARE_H__ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | /* @brief get platform firmware version string. 14 | * 15 | * @param buf[out]: the firmware string, terminated with with '\0'. 16 | * @param size[in]: the length of buffer. 17 | * 18 | * @return: platform arch string. 19 | */ 20 | size_t das_hal_firmware_version(char *buf, size_t size); 21 | 22 | /* @brief get device unique identifier string. 23 | * 24 | * @param buf[out]: the device id string, terminated with '\0'. 25 | * @param size[in]: the length of buffer. 26 | * 27 | * @return: @see error codes. 28 | */ 29 | size_t das_hal_device_id(char *buf, size_t size); 30 | 31 | #if (DAS_SERVICE_ROM_ENABLED) 32 | 33 | typedef struct _das_rom_bank { 34 | uint8_t* address; 35 | size_t size; 36 | } das_rom_bank_t; 37 | 38 | /* @brief get rom block infos for detection. 39 | * 40 | * @param rom_info[out]: rom info array, containing rom block infos. 41 | * 42 | * @return: @see error codes. 43 | */ 44 | int das_hal_rom_info(das_rom_bank_t banks[DAS_ROM_BANK_NUMBER]); 45 | 46 | #endif 47 | 48 | #endif /* __DAS_HAL_H__ */ 49 | -------------------------------------------------------------------------------- /components/das/include/das/sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __DAS_SHA1_H__ 6 | #define __DAS_SHA1_H__ 7 | 8 | #include 9 | 10 | #ifdef DAS_PLATFORM_SHA1_ALT 11 | #include 12 | #else 13 | /** 14 | * \brief SHA-1 context structure 15 | */ 16 | typedef struct _das_sha1_context { 17 | uint32_t total[2]; /*!< number of bytes processed */ 18 | uint32_t state[5]; /*!< intermediate digest state */ 19 | unsigned char buffer[64]; /*!< data block being processed */ 20 | } das_sha1_context_t; 21 | #endif 22 | 23 | #define DAS_SHA1_LENGTH 20 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /** 30 | * \brief Initialize SHA-1 context 31 | * 32 | * \param ctx SHA-1 context to be initialized 33 | */ 34 | void das_sha1_start(das_sha1_context_t *context); 35 | 36 | /** 37 | * \brief SHA-1 process buffer 38 | * 39 | * \param ctx SHA-1 context 40 | * \param input buffer holding the data 41 | * \param ilen length of the input data 42 | */ 43 | void das_sha1_update(das_sha1_context_t *ctx, const unsigned char *input, size_t ilen); 44 | 45 | /** 46 | * \brief SHA-1 final digest 47 | * 48 | * \param ctx SHA-1 context 49 | * \param output SHA-1 checksum result 50 | */ 51 | void das_sha1_finish(das_sha1_context_t *ctx, unsigned char output[DAS_SHA1_LENGTH]); 52 | 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* mbedtls_sha1.h */ 59 | -------------------------------------------------------------------------------- /components/das/include/das/sha1_alt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __DAS_SHA1_ALT_H__ 6 | #define __DAS_SHA1_ALT_H__ 7 | 8 | #include 9 | 10 | typedef struct _das_sha1_context { 11 | void *context; 12 | uint32_t size; 13 | } das_sha1_context_t; 14 | 15 | #endif /* __DAS_SHA1_ALT_H__ */ 16 | -------------------------------------------------------------------------------- /components/das/src/board/das_board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __DAS_BOARD_H__ 6 | #define __DAS_BOARD_H__ 7 | 8 | #include 9 | 10 | #if (DAS_SERVICE_ROM_ENABLED) 11 | 12 | #define DAS_ROM_BANK_NUMBER 1 13 | 14 | #endif 15 | 16 | 17 | #endif /* __DAS_BOARD_H__ */ 18 | -------------------------------------------------------------------------------- /components/das/src/core/das_attest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int das_attest(const char* tag, ...) 7 | { 8 | int ret = -1; 9 | va_list args; 10 | int i = 0; 11 | das_attest_handler_t* attest_hdlr = NULL; 12 | 13 | #if (DAS_SERVICE_STACK_PROTECTION_ENABLED) 14 | stack_protection(tag); 15 | #endif 16 | 17 | va_start(args, tag); 18 | 19 | for (i = 0; das_attest_handler_table[i]; i++) { 20 | attest_hdlr = das_attest_handler_table[i]; 21 | 22 | if (!attest_hdlr->tag || !attest_hdlr->handler) { 23 | DAS_LOG("invalid tag handler, index: %d, tag: %s.\n", i, attest_hdlr->tag); 24 | break; 25 | } 26 | 27 | if (!strcmp(attest_hdlr->tag, tag)) { 28 | ret = attest_hdlr->handler(args); 29 | break; 30 | } 31 | } 32 | 33 | va_end(args); 34 | 35 | return ret; 36 | } 37 | -------------------------------------------------------------------------------- /components/das/src/core/proto/pb_common.h: -------------------------------------------------------------------------------- 1 | /* pb_common.h: Common support functions for pb_encode.c and pb_decode.c. 2 | * These functions are rarely needed by applications directly. 3 | */ 4 | 5 | #ifndef PB_COMMON_H_INCLUDED 6 | #define PB_COMMON_H_INCLUDED 7 | 8 | #include "pb.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /* Iterator for pb_field_t list */ 15 | struct pb_field_iter_s { 16 | const pb_field_t *start; /* Start of the pb_field_t array */ 17 | const pb_field_t *pos; /* Current position of the iterator */ 18 | unsigned required_field_index; /* Zero-based index that counts only the required fields */ 19 | void *dest_struct; /* Pointer to start of the structure */ 20 | void *pData; /* Pointer to current field value */ 21 | void *pSize; /* Pointer to count/has field */ 22 | }; 23 | typedef struct pb_field_iter_s pb_field_iter_t; 24 | 25 | /* Initialize the field iterator structure to beginning. 26 | * Returns false if the message type is empty. */ 27 | bool pb_field_iter_begin(pb_field_iter_t *iter, const pb_field_t *fields, void *dest_struct); 28 | 29 | /* Advance the iterator to the next field. 30 | * Returns false when the iterator wraps back to the first field. */ 31 | bool pb_field_iter_next(pb_field_iter_t *iter); 32 | 33 | /* Advance the iterator until it points at a field with the given tag. 34 | * Returns false if no such field exists. */ 35 | bool pb_field_iter_find(pb_field_iter_t *iter, uint32_t tag); 36 | 37 | #ifdef __cplusplus 38 | } /* extern "C" */ 39 | #endif 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /components/das/src/core/utils.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | size_t das_hex2string(char *str, size_t str_len, uint8_t *hex, size_t hex_len) 4 | { 5 | static const char *hex_table = "0123465789abcdef"; 6 | size_t i; 7 | uint8_t v; 8 | 9 | if (str_len <= hex_len * 2) { 10 | return 0; 11 | } else { 12 | str_len = hex_len * 2; 13 | } 14 | 15 | for (i = 0; i < hex_len; i++) { 16 | v = hex[i]; 17 | str[2*i + 0] = hex_table[(v & 0xf0) >> 4]; 18 | str[2*i + 1] = hex_table[(v & 0x0f)]; 19 | } 20 | 21 | str[2*i] = '\0'; 22 | 23 | return str_len; 24 | } 25 | 26 | char *das_itoa(int val, char *buf, unsigned int radix) 27 | { 28 | char *p; 29 | char *firstdig; 30 | char temp; 31 | unsigned digval; 32 | p = buf; 33 | if(val < 0) { 34 | *p++ = '-'; 35 | val = (unsigned long)(-(long)val); 36 | } 37 | 38 | firstdig = p; 39 | do { 40 | digval = (unsigned)(val % radix); 41 | val /= radix; 42 | 43 | if (digval > 9) 44 | *p++ = (char)(digval - 10 + 'a'); 45 | else 46 | *p++ = (char)(digval + '0'); 47 | } while(val > 0); 48 | 49 | *p-- = '\0'; 50 | do { 51 | temp = *p; 52 | *p = *firstdig; 53 | *firstdig = temp; 54 | --p; 55 | ++firstdig; 56 | } while(firstdig < p); 57 | 58 | return buf; 59 | } -------------------------------------------------------------------------------- /components/das/src/service/netfilter/icmp_ignore.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef DAS_PLATFORM_LINUX 4 | #if (DAS_SERVICE_NETFILER_ENABLED) 5 | 6 | static int _imcp_ignore_init (void) { 7 | return 0; 8 | } 9 | 10 | static pre_process_status_t _imcp_ignore_processor (netflow_info_t *info, 11 | void *payload, 12 | size_t payload_size, 13 | char *buf, 14 | size_t buf_size) 15 | { 16 | pre_process_status_t ret = PRE_PROCESS_CALL_NEXT; 17 | 18 | if (info == NULL) { 19 | return PRE_PROCESS_GENERAL_ERROR; 20 | } 21 | 22 | if (info->protocol == IPPROTO_ICMP || info->protocol == IPPROTO_ICMPV6) { 23 | ret = PRE_PROCESS_REPORT_IGNORE; 24 | } 25 | 26 | return ret; 27 | } 28 | 29 | netfilter_pre_processor_t imcp_ignore_pre_processor = { 30 | .name = "ICMP_IGNORE_PROCESSOR", 31 | .init = _imcp_ignore_init, 32 | .pre_process = _imcp_ignore_processor, 33 | }; 34 | 35 | #endif 36 | #endif -------------------------------------------------------------------------------- /components/das/src/service/netfilter/tcp.h: -------------------------------------------------------------------------------- 1 | #ifndef __DAS_TCP_H__ 2 | #define __DAS_TCP_H__ 3 | 4 | typedef u_int32_t tcp_seq; 5 | /* 6 | * TCP header. 7 | * Per RFC 793, September, 1981. 8 | */ 9 | struct tcphdr 10 | { 11 | u_int16_t th_sport; /* source port */ 12 | u_int16_t th_dport; /* destination port */ 13 | tcp_seq th_seq; /* sequence number */ 14 | tcp_seq th_ack; /* acknowledgement number */ 15 | # if __BYTE_ORDER == __LITTLE_ENDIAN 16 | u_int8_t th_x2:4; /* (unused) */ 17 | u_int8_t th_off:4; /* data offset */ 18 | # endif 19 | # if __BYTE_ORDER == __BIG_ENDIAN 20 | u_int8_t th_off:4; /* data offset */ 21 | u_int8_t th_x2:4; /* (unused) */ 22 | # endif 23 | u_int8_t th_flags; 24 | # define TH_FIN 0x01 25 | # define TH_SYN 0x02 26 | # define TH_RST 0x04 27 | # define TH_PUSH 0x08 28 | # define TH_ACK 0x10 29 | # define TH_URG 0x20 30 | u_int16_t th_win; /* window */ 31 | u_int16_t th_sum; /* checksum */ 32 | u_int16_t th_urp; /* urgent pointer */ 33 | }; 34 | 35 | #endif /* __DAS_TCP_H__ */ -------------------------------------------------------------------------------- /components/das/src/service/netfilter/udp.h: -------------------------------------------------------------------------------- 1 | #ifndef __DAS_UDP_H__ 2 | #define __DAS_UDP_H__ 3 | 4 | struct udphdr 5 | { 6 | struct 7 | { 8 | u_int16_t uh_sport; /* source port */ 9 | u_int16_t uh_dport; /* destination port */ 10 | u_int16_t uh_ulen; /* udp length */ 11 | u_int16_t uh_sum; /* udp checksum */ 12 | }; 13 | }; 14 | 15 | #endif /* __DAS_UDP_H__ */ -------------------------------------------------------------------------------- /components/http/Config.in: -------------------------------------------------------------------------------- 1 | ################################################################### 2 | # Component enable/disable selection 3 | # in the updated build system, default is y and can not be disabled 4 | if AOS_CREATE_PROJECT 5 | config AOS_COMP_AMP_COMP_HTTP 6 | bool 7 | default y 8 | # do NOT select depend component in this file 9 | # use $(NAME)_COMPONENTS in aos.mk 10 | endif 11 | 12 | # Backward compatibility 13 | if !AOS_CREATE_PROJECT 14 | config AOS_COMP_AMP_COMP_HTTP 15 | bool "amp_comp_http" 16 | default y 17 | help 18 | AliOS things mini program -- smart config support component 19 | endif -------------------------------------------------------------------------------- /components/http/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libhttp.a 2 | MODULE = http 3 | 4 | MOD_SOURCES := \ 5 | src/http_client.c \ 6 | src/http_parser.c \ 7 | src/http_string.c \ 8 | src/http_wrapper.c 9 | 10 | MOD_INCLUDES := \ 11 | ../../adapter/include \ 12 | ../../adapter/platform/linux \ 13 | ../../main \ 14 | ../../utils/mbedtls/include \ 15 | ../linkkit \ 16 | ../linkkit/infra \ 17 | ../ulog \ 18 | include 19 | 20 | include $(TOOLS_DIR)/rules.mk 21 | -------------------------------------------------------------------------------- /components/http/aos.mk: -------------------------------------------------------------------------------- 1 | NAME = libamp_http 2 | 3 | 4 | $(NAME)_SOURCES += \ 5 | src/http_client.c \ 6 | src/http_parser.c \ 7 | src/http_string.c \ 8 | src/http_wrapper.c 9 | 10 | $(NAME)_INCLUDES := \ 11 | ../../adapter/include \ 12 | include \ 13 | ../../adapter/include \ 14 | ../../adapter/platform/aos-haas100 \ 15 | ../linkkit \ 16 | ../linkkit/infra \ 17 | ../../main \ 18 | ../ulog 19 | 20 | -------------------------------------------------------------------------------- /components/http/include/http_def_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef HTTP_DEF_CONFIG_H 6 | #define HTTP_DEF_CONFIG_H 7 | 8 | #ifdef CONFIG_DEFINE_HTTP_CONFIG 9 | #include "http_config.h" 10 | #endif 11 | 12 | #ifndef CONFIG_HTTPC_SESSION_NUM 13 | #define CONFIG_HTTPC_SESSION_NUM 1 14 | #endif 15 | 16 | #ifndef CONFIG_HTTPC_SERVER_NAME_SIZE 17 | #define CONFIG_HTTPC_SERVER_NAME_SIZE 1024 18 | #endif 19 | 20 | #ifndef CONFIG_HTTPC_DEFAULT_CLIENT 21 | #define CONFIG_HTTPC_DEFAULT_CLIENT "AliOS-HTTP-Client/2.1" 22 | #endif 23 | 24 | #ifndef CONFIG_HTTP_STATUS_SIZE 25 | #define CONFIG_HTTP_STATUS_SIZE 32 26 | #endif 27 | 28 | #ifndef CONFIG_HTTP_SECURE 29 | #if AOS_COMP_ITLS 30 | #define CONFIG_HTTP_SECURE 1 31 | #elif AOS_COMP_MBEDTLS 32 | #define CONFIG_HTTP_SECURE 1 33 | #else 34 | #define CONFIG_HTTP_SECURE 0 35 | #endif 36 | #endif 37 | 38 | #if CONFIG_HTTP_SECURE 39 | #if AOS_COMP_ITLS 40 | #define CONFIG_HTTP_SECURE_ITLS 1 41 | #else 42 | #define CONFIG_HTTP_SECURE_ITLS 0 43 | #endif 44 | #endif 45 | 46 | #ifndef CONFIG_HTTP_ENABLE_MUTEX 47 | #define CONFIG_HTTP_ENABLE_MUTEX 1 48 | #endif 49 | 50 | #define CONFIG_HTTP_DEBUG 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /components/http/include/http_string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef HTTP_STRING_H 6 | #define HTTP_STRING_H 7 | 8 | #include "http_client.h" 9 | 10 | bool http_str_search(char *src, char *searched, uint32_t offset, 11 | uint32_t scope, httpc_param_t *param); 12 | 13 | bool http_str_insensitive_cmp(char *src, char *dest, uint32_t len); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /components/kv/Config.in: -------------------------------------------------------------------------------- 1 | ################################################################### 2 | # Component enable/disable selection 3 | # in the updated build system, default is y and can not be disabled 4 | if AOS_CREATE_PROJECT 5 | config AOS_COMP_AMP_COMP_KV 6 | bool 7 | default y 8 | # do NOT select depend component in this file 9 | # use $(NAME)_COMPONENTS in aos.mk 10 | endif 11 | 12 | # Backward compatibility 13 | if !AOS_CREATE_PROJECT 14 | config AOS_COMP_AMP_COMP_KV 15 | bool "amp_comp_kv" 16 | default y 17 | help 18 | AliOS things mini program -- smart config support component 19 | endif -------------------------------------------------------------------------------- /components/kv/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libkv.a 2 | MODULE = kv 3 | 4 | MOD_SOURCES := \ 5 | kv.c \ 6 | kv_adapt.c 7 | 8 | MOD_INCLUDES := include 9 | 10 | # MOD_OBJS_DIR = $(COMP_DIR)/$(MODULE)/build 11 | 12 | include $(TOOLS_DIR)/rules.mk 13 | -------------------------------------------------------------------------------- /components/linkkit/Config.in: -------------------------------------------------------------------------------- 1 | ################################################################### 2 | # Component enable/disable selection 3 | # in the updated build system, default is y and can not be disabled 4 | if AOS_CREATE_PROJECT 5 | config AOS_COMP_AMP_COMP_LINKKIT 6 | bool 7 | default y 8 | # do NOT select depend component in this file 9 | # use $(NAME)_COMPONENTS in aos.mk 10 | endif 11 | 12 | # Backward compatibility 13 | if !AOS_CREATE_PROJECT 14 | config AOS_COMP_AMP_COMP_LINKKIT 15 | bool "amp_comp_linkkit" 16 | default y 17 | help 18 | AliOS things mini program -- smart config support component 19 | endif -------------------------------------------------------------------------------- /components/linkkit/aos.mk: -------------------------------------------------------------------------------- 1 | NAME = libamp_linkkit 2 | 3 | $(NAME)_SOURCES := \ 4 | certs/root_ca.c 5 | 6 | $(NAME)_SOURCES += \ 7 | dev_model/dm_api.c \ 8 | dev_model/dm_client_adapter.c \ 9 | dev_model/dm_client.c \ 10 | dev_model/dm_cota.c \ 11 | dev_model/dm_fota.c \ 12 | dev_model/dm_ipc.c \ 13 | dev_model/dm_log_report.c \ 14 | dev_model/dm_manager.c \ 15 | dev_model/dm_message_cache.c \ 16 | dev_model/dm_message.c \ 17 | dev_model/dm_msg_process.c \ 18 | dev_model/dm_opt.c \ 19 | dev_model/dm_ota.c \ 20 | dev_model/dm_server_adapter.c \ 21 | dev_model/dm_server.c \ 22 | dev_model/dm_shadow.c \ 23 | dev_model/dm_tsl_alink.c \ 24 | dev_model/dm_utils.c \ 25 | dev_model/impl_gateway.c \ 26 | dev_model/impl_linkkit.c \ 27 | dev_model/impl_ntp.c \ 28 | dev_model/impl_solo.c \ 29 | dev_model/iotx_cm_coap.c \ 30 | dev_model/iotx_cm_mqtt.c \ 31 | dev_model/iotx_cm.c 32 | 33 | $(NAME)_SOURCES += \ 34 | dev_sign/dev_sign_mqtt.c 35 | 36 | $(NAME)_SOURCES += \ 37 | dynamic_register/dynreg.c 38 | 39 | $(NAME)_SOURCES += \ 40 | infra/infra_activation.c \ 41 | infra/infra_aes.c \ 42 | infra/infra_cjson.c \ 43 | infra/infra_compat.c \ 44 | infra/infra_defs.c \ 45 | infra/infra_httpc.c \ 46 | infra/infra_json_parser.c \ 47 | infra/infra_log.c \ 48 | infra/infra_md5.c \ 49 | infra/infra_net.c \ 50 | infra/infra_sha256.c \ 51 | infra/infra_string.c \ 52 | infra/infra_timer.c \ 53 | infra/infra_report.c \ 54 | infra/infra_prt_nwk_payload.c 55 | 56 | $(NAME)_SOURCES += \ 57 | mqtt/iotx_mqtt_client.c \ 58 | mqtt/mqtt_api.c \ 59 | mqtt/MQTTConnectClient.c \ 60 | mqtt/MQTTDeserializePublish.c \ 61 | mqtt/MQTTPacket.c \ 62 | mqtt/MQTTSerializePublish.c \ 63 | mqtt/MQTTSubscribeClient.c \ 64 | mqtt/MQTTUnsubscribeClient.c 65 | 66 | $(NAME)_INCLUDES := \ 67 | . \ 68 | dev_model \ 69 | dev_sign \ 70 | dynamic_register \ 71 | infra \ 72 | mqtt 73 | 74 | -------------------------------------------------------------------------------- /components/linkkit/certs/root_ca.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | 7 | const char *iotx_ca_crt = \ 8 | { 9 | \ 10 | "-----BEGIN CERTIFICATE-----\r\n" 11 | "MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG\r\n" \ 12 | "A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv\r\n" \ 13 | "b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAw\r\n" \ 14 | "MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i\r\n" \ 15 | "YWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYDVQQDExJHbG9iYWxT\r\n" \ 16 | "aWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDaDuaZ\r\n" \ 17 | "jc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavp\r\n" \ 18 | "xy0Sy6scTHAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp\r\n" \ 19 | "1Wrjsok6Vjk4bwY8iGlbKk3Fp1S4bInMm/k8yuX9ifUSPJJ4ltbcdG6TRGHRjcdG\r\n" \ 20 | "snUOhugZitVtbNV4FpWi6cgKOOvyJBNPc1STE4U6G7weNLWLBYy5d4ux2x8gkasJ\r\n" \ 21 | "U26Qzns3dLlwR5EiUWMWea6xrkEmCMgZK9FGqkjWZCrXgzT/LCrBbBlDSgeF59N8\r\n" \ 22 | "9iFo7+ryUp9/k5DPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8E\r\n" \ 23 | "BTADAQH/MB0GA1UdDgQWBBRge2YaRQ2XyolQL30EzTSo//z9SzANBgkqhkiG9w0B\r\n" \ 24 | "AQUFAAOCAQEA1nPnfE920I2/7LqivjTFKDK1fPxsnCwrvQmeU79rXqoRSLblCKOz\r\n" \ 25 | "yj1hTdNGCbM+w6DjY1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE\r\n" \ 26 | "38NflNUVyRRBnMRddWQVDf9VMOyGj/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymP\r\n" \ 27 | "AbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhHhm4qxFYxldBniYUr+WymXUad\r\n" \ 28 | "DKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveCX4XSQRjbgbME\r\n" \ 29 | "HMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A==\r\n" \ 30 | "-----END CERTIFICATE-----" 31 | }; 32 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/dm_client_adapter.h: -------------------------------------------------------------------------------- 1 | #ifndef _DM_CLIENT_ADAPTER_H_ 2 | #define _DM_CLIENT_ADAPTER_H_ 3 | 4 | typedef struct { 5 | int fd; 6 | iotx_conn_info_t *conn_info; 7 | void *callback; 8 | } dm_client_ctx_t; 9 | 10 | int dm_client_open(void); 11 | int dm_client_connect(int timeout_ms); 12 | int dm_client_close(void); 13 | int dm_client_subscribe(char *uri, iotx_cm_data_handle_cb callback, void *context); 14 | int dm_client_unsubscribe(char *uri); 15 | int dm_client_publish(char *uri, unsigned char *payload, int payload_len, iotx_cm_data_handle_cb callback); 16 | int dm_client_yield(unsigned int timeout); 17 | void dm_client_user_sub_request(int fd, const char *topic, const char *payload, unsigned int payload_len, 18 | void *context); 19 | #endif 20 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/dm_cota.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _DM_COTA_H_ 8 | #define _DM_COTA_H_ 9 | 10 | typedef struct { 11 | int is_report_new_config; 12 | } dm_cota_ctx_t; 13 | 14 | int dm_cota_init(void); 15 | int dm_cota_deinit(void); 16 | int dm_cota_perform_sync(_OU_ char *output, _IN_ int output_len); 17 | int dm_cota_get_config(const char *config_scope, const char *get_type, const char *attribute_keys); 18 | int dm_cota_status_check(void); 19 | dm_cota_ctx_t *dm_cota_get_ctx(void); 20 | #endif 21 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/dm_fota.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _DM_FOTA_H_ 8 | #define _DM_FOTA_H_ 9 | 10 | typedef struct { 11 | int is_report_new_config; 12 | } dm_fota_ctx_t; 13 | 14 | int dm_fota_init(void); 15 | int dm_fota_deinit(void); 16 | int dm_fota_perform_sync(_OU_ char *output, _IN_ int output_len); 17 | int dm_fota_status_check(void); 18 | int dm_fota_request_image(_IN_ const char *version, _IN_ int buffer_len); 19 | dm_fota_ctx_t *dm_fota_get_ctx(void); 20 | #endif 21 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/dm_intf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _IOT_DM_API_H_ 8 | #define _IOT_DM_API_H_ 9 | 10 | typedef struct { 11 | void *mutex; 12 | void *cloud_connectivity; 13 | void *local_connectivity; 14 | iotx_dm_event_callback event_callback; 15 | } dm_api_ctx_t; 16 | 17 | #if defined(DEPRECATED_LINKKIT) 18 | typedef struct { 19 | void *mutex; 20 | int devid; 21 | lite_cjson_item_t *lite; 22 | } dm_api_property_t; 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/dm_ipc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _DM_IPC_H_ 8 | #define _DM_IPC_H_ 9 | 10 | #include "iotx_dm_internal.h" 11 | 12 | typedef struct { 13 | iotx_dm_event_types_t type; 14 | char *data; 15 | } dm_ipc_msg_t; 16 | 17 | typedef struct { 18 | void *data; 19 | struct list_head linked_list; 20 | } dm_ipc_msg_node_t; 21 | 22 | typedef struct { 23 | int max_size; 24 | int size; 25 | struct list_head message_list; 26 | } dm_ipc_msg_list_t; 27 | 28 | typedef struct { 29 | void *mutex; 30 | dm_ipc_msg_list_t msg_list; 31 | } dm_ipc_t; 32 | 33 | int dm_ipc_init(int max_size); 34 | void dm_ipc_deinit(void); 35 | int dm_ipc_msg_insert(void *data); 36 | int dm_ipc_msg_next(void **data); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/dm_message_cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #if !defined(DM_MESSAGE_CACHE_DISABLED) 7 | #ifndef _DM_MESSAGE_CACHE_H_ 8 | #define _DM_MESSAGE_CACHE_H_ 9 | 10 | #include "iotx_dm_internal.h" 11 | 12 | #define DM_MSG_CACHE_TIMEOUT_MS_DEFAULT (10000) 13 | 14 | typedef struct { 15 | int msgid; 16 | int devid; 17 | iotx_dm_event_types_t response_type; 18 | char *data; 19 | uint64_t ctime; 20 | struct list_head linked_list; 21 | } dm_msg_cache_node_t; 22 | 23 | typedef struct { 24 | void *mutex; 25 | int dmc_list_size; 26 | struct list_head dmc_list; 27 | } dm_msg_cache_ctx_t; 28 | 29 | int dm_msg_cache_init(void); 30 | int dm_msg_cache_deinit(void); 31 | int dm_msg_cache_insert(int msg_id, int devid, iotx_dm_event_types_t type, char *data); 32 | int dm_msg_cache_search(_IN_ int msg_id, _OU_ dm_msg_cache_node_t **node); 33 | int dm_msg_cache_remove(int msg_id); 34 | void dm_msg_cache_tick(void); 35 | 36 | #endif 37 | #endif 38 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/dm_opt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifdef DEVICE_MODEL_ENABLED 6 | #ifndef _DM_OPT_H 7 | #define _DM_OPT_H 8 | 9 | typedef enum { 10 | #if !defined(DEVICE_MODEL_RAWDATA_SOLO) 11 | DM_OPT_DOWNSTREAM_PROPERTY_POST_REPLY, 12 | DM_OPT_DOWNSTREAM_EVENT_POST_REPLY, 13 | DM_OPT_UPSTREAM_PROPERTY_SET_REPLY, 14 | #endif 15 | DM_OPT_DOWNSTREAM_EVENT_PROPERTY_DESIRED_DELETE_REPLY, 16 | DM_OPT_DOWNSTREAM_EVENT_PROPERTY_DESIRED_GET_REPLY, 17 | DM_OPT_FOTA_RETRY_TIMEOUT_MS, 18 | DM_OPT_PROXY_PRODUCT_REGISTER 19 | } dm_opt_t; 20 | 21 | typedef struct { 22 | int prop_post_reply_opt; 23 | int event_post_reply_opt; 24 | int prop_set_reply_opt; 25 | int prop_desired_get_reply_opt; 26 | int prop_desired_delete_reply_opt; 27 | int fota_retry_timeout_ms; 28 | int proxy_product_register; 29 | } dm_opt_ctx; 30 | 31 | int dm_opt_set(dm_opt_t opt, void *data); 32 | int dm_opt_get(dm_opt_t opt, void *data); 33 | 34 | #endif 35 | #endif 36 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/dm_ota.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _DM_OTA_H_ 8 | #define _DM_OTA_H_ 9 | 10 | typedef struct { 11 | void *ota_handle; 12 | char product_key[IOTX_PRODUCT_KEY_LEN + 1]; 13 | char device_name[IOTX_DEVICE_NAME_LEN + 1]; 14 | } dm_ota_ctx_t; 15 | 16 | int dm_ota_init(void); 17 | int dm_ota_sub(void); 18 | int dm_ota_deinit(void); 19 | int dm_ota_get_ota_handle(void **handle); 20 | #ifdef DEVICE_MODEL_GATEWAY 21 | #ifdef DEVICE_MODEL_SUBDEV_OTA 22 | int dm_ota_switch_device(int devid); 23 | #endif 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/dm_server.h: -------------------------------------------------------------------------------- 1 | #ifndef _DM_SERVER_H_ 2 | #define _DM_SERVER_H_ 3 | 4 | #ifdef ALCS_ENABLED 5 | typedef struct { 6 | const char *uri_name; 7 | const char *uri_prefix; 8 | int auth_type; 9 | CoAPRecvMsgHandler callback; 10 | } dm_server_uri_map_t; 11 | 12 | #define DM_SERVER_ALCS_NO_AUTH (0) 13 | #define DM_SERVER_ALCS_AUTH (1) 14 | 15 | void dm_server_alcs_event_handler(void *pcontext, void *phandle, iotx_alcs_event_msg_t *msg); 16 | 17 | int dm_server_subscribe_all(char product_key[IOTX_PRODUCT_KEY_LEN + 1], char device_name[IOTX_DEVICE_NAME_LEN + 1]); 18 | void dm_server_thing_service_property_set(CoAPContext *context, const char *paths, NetworkAddr *remote, 19 | CoAPMessage *message); 20 | void dm_server_thing_service_property_get(CoAPContext *context, const char *paths, NetworkAddr *remote, 21 | CoAPMessage *message); 22 | void dm_server_thing_service_property_post(CoAPContext *context, const char *paths, NetworkAddr *remote, 23 | CoAPMessage *message); 24 | void dm_server_thing_dev_core_service_dev(CoAPContext *context, const char *paths, NetworkAddr *remote, 25 | CoAPMessage *message); 26 | void dm_server_thing_service_request(CoAPContext *context, const char *paths, NetworkAddr *remote, 27 | CoAPMessage *message); 28 | #endif 29 | #endif -------------------------------------------------------------------------------- /components/linkkit/dev_model/dm_server_adapter.h: -------------------------------------------------------------------------------- 1 | #ifndef _DM_SERVER_ADAPTER_H_ 2 | #define _DM_SERVER_ADAPTER_H_ 3 | 4 | #ifdef ALCS_ENABLED 5 | 6 | #define DM_SERVER_ALCS_ADDR "224.0.1.187" 7 | #define DM_SERVER_ALCS_PORT (5863) 8 | #define DM_SERVER_ALCS_SEND_MAXCOUNT (16) 9 | #define DM_SERVER_ALCS_WAITTIME (200) 10 | #define DM_SERVER_ALCS_OBS_MAXCOUNT (16) 11 | #define DM_SERVER_ALCS_RES_MAXCOUNT (255) 12 | 13 | typedef struct { 14 | void *conn_handle; 15 | } dm_server_ctx_t; 16 | 17 | typedef struct { 18 | char *ip; 19 | uint16_t port; 20 | char *token; 21 | int token_len; 22 | } dm_server_alcs_context_t; 23 | 24 | int dm_server_open(void); 25 | int dm_server_connect(void); 26 | int dm_server_close(void); 27 | int dm_server_send(char *uri, unsigned char *payload, int payload_len, void *context); 28 | int dm_server_subscribe(char *uri, CoAPRecvMsgHandler callback, int auth_type); 29 | int dm_server_add_device(char product_key[IOTX_PRODUCT_KEY_LEN + 1], char device_name[IOTX_DEVICE_NAME_LEN + 1]); 30 | int dm_server_del_device(char product_key[IOTX_PRODUCT_KEY_LEN + 1], char device_name[IOTX_DEVICE_NAME_LEN + 1]); 31 | int dm_server_yield(void); 32 | 33 | #endif 34 | #endif -------------------------------------------------------------------------------- /components/linkkit/dev_model/dm_tsl_alink.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #if defined(DEPRECATED_LINKKIT) 6 | #ifndef _DM_TSL_ALINK_H_ 7 | #define _DM_TSL_ALINK_H_ 8 | 9 | /** 10 | * @brief Create TSL struct from TSL string. 11 | * This function used to parse TSL string into TSL struct. 12 | * 13 | * @param tsl. The TSL string in JSON format. 14 | * @param tsl_len. The length of tsl 15 | * @param shadow. The pointer of TSL Struct pointer, will be malloc memory. 16 | * This memory should be free by dm_shw_destroy. 17 | * 18 | * @return success or fail. 19 | * 20 | */ 21 | int dm_tsl_alink_create(_IN_ const char *tsl, _IN_ int tsl_len, _OU_ dm_shw_t **shadow); 22 | 23 | #endif 24 | #endif 25 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/impl_ntp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NTP_H 7 | #define NTP_H 8 | 9 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 10 | extern "C" { 11 | #endif 12 | 13 | 14 | #define TOPIC_NTP "/ext/ntp/%s/%s/request" 15 | #define TOPIC_NTP_REPLY "/ext/ntp/%s/%s/response" 16 | 17 | #define NTP_TIME_STR_MAX_LEN (20) 18 | 19 | int linkkit_ntp_time_request(void (*)(const char *ntp_offset_time_ms)); 20 | 21 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/impl_solo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _LINKKIT_SOLO_LEGACY_H_ 6 | #define _LINKKIT_SOLO_LEGACY_H_ 7 | 8 | #include "linkkit_export.h" 9 | 10 | #define LINKKIT_SOLO_LEGACY_KEY_ID "id" 11 | #define LINKKIT_SOLO_LEGACY_KEY_CODE "code" 12 | #define LINKKIT_SOLO_LEGACY_KEY_DEVID "devid" 13 | #define LINKKIT_SOLO_LEGACY_KEY_SERVICEID "serviceid" 14 | #define LINKKIT_SOLO_LEGACY_KEY_PROPERTYID "propertyid" 15 | #define LINKKIT_SOLO_LEGACY_KEY_EVENTID "eventid" 16 | #define LINKKIT_SOLO_LEGACY_KEY_PAYLOAD "payload" 17 | #define LINKKIT_SOLO_LEGACY_KEY_CONFIG_ID "configId" 18 | #define LINKKIT_SOLO_LEGACY_KEY_CONFIG_SIZE "configSize" 19 | #define LINKKIT_SOLO_LEGACY_KEY_GET_TYPE "getType" 20 | #define LINKKIT_SOLO_LEGACY_KEY_SIGN "sign" 21 | #define LINKKIT_SOLO_LEGACY_KEY_SIGN_METHOD "signMethod" 22 | #define LINKKIT_SOLO_LEGACY_KEY_URL "url" 23 | #define LINKKIT_SOLO_LEGACY_KEY_VERSION "version" 24 | 25 | typedef struct { 26 | int msgid; 27 | handle_post_cb_fp_t callback; 28 | struct list_head linked_list; 29 | } linkkit_solo_upstream_callback_node_t; 30 | 31 | typedef struct { 32 | void *mutex; 33 | void *upstream_mutex; 34 | int is_started; 35 | int is_leaved; 36 | linkkit_ops_t *user_callback; 37 | void *user_context; 38 | handle_service_cota_callback_fp_t cota_callback; 39 | handle_service_fota_callback_fp_t fota_callback; 40 | struct list_head callback_list; 41 | } linkkit_solo_legacy_ctx_t; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/iotx_cm_coap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _IOTX_CM_COAP_H_ 6 | #define _IOTX_CM_COAP_H_ 7 | #include "iotx_cm.h" 8 | #include "iotx_cm_internal.h" 9 | #include "coap_api.h" 10 | 11 | 12 | typedef struct { 13 | uint32_t token_num; 14 | void *user_data; 15 | char *topic; 16 | iotx_cm_data_handle_cb responce_cb; 17 | void *context; 18 | dlist_t linked_list; 19 | } coap_response_node_t; 20 | 21 | iotx_cm_connection_t *iotx_cm_open_coap(iotx_cm_init_param_t *params); 22 | 23 | #endif /* _LINKKIT_CM_H_ */ 24 | 25 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/iotx_cm_mqtt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef _IOTX_CM_MQTT_H_ 7 | #define _IOTX_CM_MQTT_H_ 8 | 9 | #include "iotx_cm.h" 10 | #include "iotx_cm_internal.h" 11 | 12 | 13 | typedef struct { 14 | uintptr_t packet_id; 15 | char * topic; 16 | void * user_data; 17 | iotx_mqtt_event_handle_func_fpt sub_state_cb; 18 | iotx_cm_data_handle_cb sub_recieve_cb; 19 | dlist_t linked_list; 20 | } mqtt_sub_node_t; 21 | 22 | iotx_cm_connection_t *iotx_cm_open_mqtt(iotx_cm_init_param_t *params); 23 | 24 | 25 | #endif /* _LINKKIT_CM_H_ */ 26 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/iotx_dm_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | #ifndef _IOTX_DM_CONFIG_H_ 8 | #define _IOTX_DM_CONFIG_H_ 9 | 10 | #define IOTX_DM_CLIENT_CONNECT_TIMEOUT_MS (10000) 11 | #define IOTX_DM_CLIENT_SUB_RETRY_MAX_COUNTS (3) 12 | #define IOTX_DM_CLIENT_SUB_TIMEOUT_MS (5000) 13 | #define IOTX_DM_CLIENT_REQUEST_TIMEOUT_MS (5000) 14 | #define IOTX_DM_CLIENT_KEEPALIVE_INTERVAL_MS (30000) 15 | #define CONFIG_SERVICE_LIST_MAXLEN (30) 16 | #define CONFIG_SERVICE_REQUEST_TIMEOUT (20000) 17 | 18 | #ifndef CONFIG_MQTT_TX_MAXLEN 19 | #define CONFIG_MQTT_TX_MAXLEN (2048) 20 | #endif 21 | 22 | #ifndef CONFIG_MQTT_RX_MAXLEN 23 | #define CONFIG_MQTT_RX_MAXLEN (2048) 24 | #endif 25 | 26 | #ifndef CONFIG_DISPATCH_QUEUE_MAXLEN 27 | #define CONFIG_DISPATCH_QUEUE_MAXLEN (50) 28 | #endif 29 | 30 | #ifndef CONFIG_DISPATCH_PACKET_MAXCOUNT 31 | #define CONFIG_DISPATCH_PACKET_MAXCOUNT (0) 32 | #endif 33 | 34 | #ifndef CONFIG_MSGCACHE_QUEUE_MAXLEN 35 | #define CONFIG_MSGCACHE_QUEUE_MAXLEN (50) 36 | #endif 37 | 38 | #ifndef CONFIG_FOTA_RETRY_INTERNAL_MS 39 | #define CONFIG_FOTA_RETRY_INTERNAL_MS (100) 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /components/linkkit/dev_model/iotx_log_report.h: -------------------------------------------------------------------------------- 1 | void get_msgid(char *payload, int is_cloud); 2 | int check_target_msg(const char *input, int len); 3 | void send_permance_info(char *input, int input_len, char *comments, int report_format); 4 | -------------------------------------------------------------------------------- /components/linkkit/dev_sign/dev_sign_api.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEV_SIGN_H_ 2 | #define _DEV_SIGN_H_ 3 | 4 | #include "infra_types.h" 5 | #include "infra_defs.h" 6 | 7 | int32_t IOT_Sign_MQTT(iotx_mqtt_region_types_t region, iotx_dev_meta_info_t *meta, iotx_sign_mqtt_t *signout); 8 | #endif 9 | 10 | 11 | -------------------------------------------------------------------------------- /components/linkkit/dev_sign/dev_sign_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEV_SIGN_CONFIG_H_ 2 | #define _DEV_SIGN_CONFIG_H_ 3 | 4 | 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /components/linkkit/dev_sign/dev_sign_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEV_SIGN_INTERNAL_H_ 2 | #define _DEV_SIGN_INTERNAL_H_ 3 | 4 | #include 5 | #include 6 | #include "infra_config.h" 7 | #include "infra_defs.h" 8 | #include "dev_sign_api.h" 9 | #include "wrappers.h" 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /components/linkkit/dynamic_register/dynreg_api.h: -------------------------------------------------------------------------------- 1 | #ifndef _DYNREG_API_H_ 2 | #define _DYNREG_API_H_ 3 | 4 | #include "infra_types.h" 5 | #include "infra_defs.h" 6 | 7 | #define MQTT_DYNREG_TIMEOUT_MS (15 * 1000) 8 | 9 | int32_t IOT_Dynamic_Register(iotx_http_region_types_t region, iotx_dev_meta_info_t *meta); 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /components/linkkit/dynamic_register/dynreg_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _DYNREG_INTERNAL_H_ 2 | #define _DYNREG_INTERNAL_H_ 3 | 4 | #include "wrappers.h" 5 | 6 | #ifdef INFRA_LOG 7 | #include "infra_log.h" 8 | #define dynreg_info(...) log_info("dynreg", __VA_ARGS__) 9 | #define dynreg_err(...) log_err("dynreg", __VA_ARGS__) 10 | #define dynreg_dbg(...) log_debug("dynreg", __VA_ARGS__) 11 | #else 12 | #define dynreg_info(fmt, ...) LOGI("dynreg", fmt, ##__VA_ARGS__) 13 | #define dynreg_err(fmt, ...) LOGE("dynreg", fmt, ##__VA_ARGS__) 14 | #define dynreg_dbg(fmt, ...) LOGD("dynreg", fmt, ##__VA_ARGS__) 15 | #endif 16 | 17 | #ifdef INFRA_MEM_STATS 18 | #include "infra_mem_stats.h" 19 | #define dynreg_malloc(size) LITE_malloc(size, MEM_MAGIC, "dynreg") 20 | #define dynreg_free(ptr) LITE_free(ptr) 21 | #else 22 | #define dynreg_malloc(size) amp_malloc(size) 23 | #define dynreg_free(ptr) {amp_free((void *)ptr);ptr = NULL;} 24 | #endif 25 | 26 | #endif 27 | 28 | #ifdef MQTT_DYNAMIC_REGISTER 29 | #include "mqtt_api.h" 30 | void *wrapper_mqtt_init(iotx_mqtt_param_t *mqtt_params); 31 | int wrapper_mqtt_connect(void *client); 32 | int wrapper_mqtt_yield(void *client, int timeout_ms); 33 | int wrapper_mqtt_subscribe(void *client, 34 | const char *topicFilter, 35 | iotx_mqtt_qos_t qos, 36 | iotx_mqtt_event_handle_func_fpt topic_handle_func, 37 | void *pcontext); 38 | int wrapper_mqtt_release(void **pclient); 39 | #endif 40 | -------------------------------------------------------------------------------- /components/linkkit/infra/infra_activation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef ACTIVATION_H 6 | #define ACTIVATION_H 7 | 8 | #ifndef UINT32 9 | #define UINT32 unsigned int 10 | #endif 11 | 12 | #ifndef UINT8 13 | #define UINT8 unsigned char 14 | #endif 15 | 16 | #ifndef NULL 17 | #define NULL ((void *)0) 18 | #endif 19 | 20 | #define VERSION_NUM_SIZE 4 21 | #define RANDOM_NUM_SIZE 4 22 | #define MAC_ADDRESS_SIZE 8 23 | #define CHIP_CODE_SIZE 4 24 | #define INPUT_SIZE (VERSION_NUM_SIZE+RANDOM_NUM_SIZE+MAC_ADDRESS_SIZE+CHIP_CODE_SIZE) 25 | #define OUTPUT_SPACE_SIZE (INPUT_SIZE*2*2+1) 26 | 27 | /* active info*/ 28 | #define PROJECT_NAME "amp" 29 | #define MODULE_NAME amp_get_platform_type() 30 | /* 31 | input: version 4byte + random 4 byte + mac 8byte + chip_code 4byte 32 | output: output_buffer store the version info process. length at least OUTPUT_SPACE_SIZE 33 | return: 0 success, 1 failed 34 | */ 35 | extern UINT32 aos_get_version_info (UINT8 version_num[VERSION_NUM_SIZE], UINT8 random_num[RANDOM_NUM_SIZE], UINT8 mac_address[MAC_ADDRESS_SIZE], UINT8 chip_code[CHIP_CODE_SIZE], UINT8 *output_buffer, UINT32 output_buffer_size); 36 | 37 | #endif -------------------------------------------------------------------------------- /components/linkkit/infra/infra_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _INFRA_CONFIG_H_ 2 | #define _INFRA_CONFIG_H_ 3 | 4 | #define PLATFORM_HAS_MBEDTLS 5 | #define PLATFORM_HAS_STDINT 6 | #define PLATFORM_HAS_DYNMEM 7 | #define INFRA_STRING 8 | #define INFRA_NET 9 | #define INFRA_LIST 10 | // #define INFRA_LOG_NETWORK_PAYLOAD 11 | // #define INFRA_LOG 12 | #define INFRA_LOG_ALL_MUTED 13 | #define INFRA_LOG_MUTE_FLW 14 | #define INFRA_LOG_MUTE_DBG 15 | #define INFRA_LOG_MUTE_INF 16 | #define INFRA_LOG_MUTE_WRN 17 | #define INFRA_LOG_MUTE_ERR 18 | #define INFRA_LOG_MUTE_CRT 19 | #define INFRA_TIMER 20 | #define INFRA_CJSON 21 | #define INFRA_JSON_PARSER 22 | #define INFRA_SHA256 23 | #define INFRA_MD5 24 | #define INFRA_REPORT 25 | #define INFRA_HTTPC 26 | #define INFRA_COMPAT 27 | #define DEV_SIGN 28 | #define MQTT_COMM_ENABLED 29 | #define MQTT_DEFAULT_IMPL 30 | #define MQTT_DIRECT 31 | #define MQTT_AUTO_SUBSCRIBE 32 | // #define DYNAMIC_REGISTER 33 | #define LOG_REPORT_TO_CLOUD 34 | #define DEVICE_MODEL_ENABLED 35 | #define HAL_KV 36 | // #define SUPPORT_TLS 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /components/linkkit/infra/infra_defs.c: -------------------------------------------------------------------------------- 1 | 2 | #include "infra_config.h" 3 | #include "infra_types.h" 4 | #include "infra_defs.h" 5 | 6 | const char * g_infra_mqtt_domain[IOTX_MQTT_DOMAIN_NUMBER] = { 7 | "iot-as-mqtt.cn-shanghai.aliyuncs.com", /* Shanghai */ 8 | "iot-as-mqtt.ap-southeast-1.aliyuncs.com", /* Singapore */ 9 | "iot-as-mqtt.ap-northeast-1.aliyuncs.com", /* Japan */ 10 | "iot-as-mqtt.us-west-1.aliyuncs.com", /* America */ 11 | "iot-as-mqtt.eu-central-1.aliyuncs.com", /* Germany */ 12 | NULL, /* Custom */ 13 | }; 14 | 15 | const char *g_infra_http_domain[IOTX_HTTP_DOMAIN_NUMBER] = { 16 | "iot-auth.cn-shanghai.aliyuncs.com", /* Shanghai */ 17 | "iot-auth.ap-southeast-1.aliyuncs.com", /* Singapore */ 18 | "iot-auth.ap-southeast-1.aliyuncs.com", /* Japan */ 19 | "iot-auth.ap-southeast-1.aliyuncs.com", /* America */ 20 | "iot-auth.ap-southeast-1.aliyuncs.com", /* Germany */ 21 | NULL, /* Custom */ 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /components/linkkit/infra/infra_net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef _INFRA_NET_H_ 6 | #define _INFRA_NET_H_ 7 | 8 | #include "infra_types.h" 9 | 10 | /** 11 | * @brief The structure of network connection(TCP or SSL). 12 | * The user has to allocate memory for this structure. 13 | */ 14 | 15 | struct utils_network; 16 | typedef struct utils_network utils_network_t, *utils_network_pt; 17 | 18 | struct utils_network { 19 | const char *pHostAddress; 20 | uint16_t port; 21 | uint16_t ca_crt_len; 22 | 23 | /**< NULL, TCP connection; NOT NULL, SSL connection */ 24 | const char *ca_crt; 25 | /**< NOT NULL,iTLS connection*/ 26 | char *product_key; 27 | /**< connection handle: 0, NOT connection; NOT 0, handle of the connection */ 28 | uintptr_t handle; 29 | 30 | /**< Read data from server function pointer. */ 31 | int (*read)(utils_network_pt, char *, uint32_t, uint32_t); 32 | 33 | /**< Send data to server function pointer. */ 34 | int (*write)(utils_network_pt, const char *, uint32_t, uint32_t); 35 | 36 | /**< Disconnect the network */ 37 | int (*disconnect)(utils_network_pt); 38 | 39 | /**< Establish the network */ 40 | int (*connect)(utils_network_pt); 41 | }; 42 | 43 | int utils_net_read(utils_network_pt pNetwork, char *buffer, uint32_t len, uint32_t timeout_ms); 44 | int utils_net_write(utils_network_pt pNetwork, const char *buffer, uint32_t len, uint32_t timeout_ms); 45 | int iotx_net_disconnect(utils_network_pt pNetwork); 46 | int iotx_net_connect(utils_network_pt pNetwork); 47 | int iotx_net_init(utils_network_pt pNetwork, const char *host, uint16_t port, const char *ca_crt); 48 | int iotx_net_init_internal(utils_network_pt pNetwork, const char *host, uint16_t port, const char *ca_crt); 49 | 50 | #endif /* IOTX_COMMON_NET_H */ 51 | 52 | 53 | -------------------------------------------------------------------------------- /components/linkkit/infra/infra_string.h: -------------------------------------------------------------------------------- 1 | #ifndef _INFRA_STRING_H_ 2 | #define _INFRA_STRING_H_ 3 | 4 | #include "infra_types.h" 5 | 6 | int8_t infra_hex2char(uint8_t hex); 7 | void infra_hex2str(uint8_t *input, uint16_t input_len, char *output); 8 | void infra_int2str(uint32_t input, char output[10]); 9 | char *infra_strtok(char *str, const char *delim); 10 | int infra_randstr(char *random, int length); 11 | void LITE_hexstr_convert(char *input, int input_len, unsigned char *output, int output_len); 12 | int infra_str2int(const char *input, int *val); 13 | int32_t utils_str2uint(char *input, uint8_t input_len, uint32_t *output); 14 | void LITE_hexbuf_convert(unsigned char *digest, char *out, int in_len, int uppercase); 15 | int32_t infra_json_value(const char *input, uint32_t input_len, const char *key, uint32_t key_len, char **value, uint32_t *value_len); 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /components/linkkit/infra/infra_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | 8 | #ifndef _INFRA_TIMER_H_ 9 | #define _INFRA_TIMER_H_ 10 | 11 | #include "infra_types.h" 12 | 13 | typedef struct { 14 | uint32_t time; 15 | } iotx_time_t; 16 | 17 | 18 | void iotx_time_start(iotx_time_t *timer); 19 | 20 | uint32_t utils_time_spend(iotx_time_t *start); 21 | 22 | uint32_t iotx_time_left(iotx_time_t *end); 23 | 24 | uint32_t utils_time_is_expired(iotx_time_t *timer); 25 | 26 | void iotx_time_init(iotx_time_t *timer); 27 | 28 | void utils_time_countdown_ms(iotx_time_t *timer, uint32_t millisecond); 29 | 30 | uint32_t utils_time_get_ms(void); 31 | 32 | #endif /* _IOTX_COMMON_TIMER_H_ */ 33 | 34 | 35 | -------------------------------------------------------------------------------- /components/linkkit/infra/infra_types.h: -------------------------------------------------------------------------------- 1 | #ifndef _INFRA_TYPES_H_ 2 | #define _INFRA_TYPES_H_ 3 | 4 | #include 5 | #include "infra_config.h" 6 | 7 | #define IOT_TRUE (1) /* indicate boolean value true */ 8 | #define IOT_FALSE (0) /* indicate boolean value false */ 9 | 10 | #if !defined(PLATFORM_HAS_STDINT) 11 | 12 | typedef unsigned char uint8_t; 13 | typedef signed char int8_t; 14 | typedef unsigned short uint16_t; 15 | typedef signed short int16_t; 16 | typedef unsigned int uint32_t; 17 | typedef signed int int32_t; 18 | typedef unsigned long int uint64_t; 19 | typedef signed long int int64_t; 20 | typedef unsigned int uintptr_t; 21 | 22 | #else 23 | 24 | #include 25 | 26 | #endif /* #if !defined(PLATFORM_HAS_STDINT) */ 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /components/linkkit/mqtt/MQTTPublish.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef MQTTPUBLISH_H_ 6 | #define MQTTPUBLISH_H_ 7 | 8 | #if !defined(DLLImport) 9 | #define DLLImport 10 | #endif 11 | #if !defined(DLLExport) 12 | #define DLLExport 13 | #endif 14 | 15 | DLLExport int MQTTSerialize_publish(unsigned char *buf, int buflen, unsigned char dup, int qos, unsigned char retained, 16 | unsigned short packetid, 17 | MQTTString topicName, unsigned char *payload, int payloadlen); 18 | 19 | DLLExport int MQTTDeserialize_publish(unsigned char *dup, int *qos, unsigned char *retained, unsigned short *packetid, 20 | MQTTString *topicName, 21 | unsigned char **payload, int *payloadlen, unsigned char *buf, int len); 22 | 23 | /* DLLExport int MQTTSerialize_puback(unsigned char* buf, int buflen, unsigned short packetid); */ 24 | DLLExport int MQTTSerialize_pubrel(unsigned char *buf, int buflen, unsigned char dup, unsigned short packetid); 25 | DLLExport int MQTTSerialize_pubcomp(unsigned char *buf, int buflen, unsigned short packetid); 26 | 27 | #endif /* MQTTPUBLISH_H_ */ 28 | 29 | 30 | -------------------------------------------------------------------------------- /components/linkkit/mqtt/MQTTSubscribe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef MQTTSUBSCRIBE_H_ 6 | #define MQTTSUBSCRIBE_H_ 7 | 8 | #if !defined(DLLImport) 9 | #define DLLImport 10 | #endif 11 | #if !defined(DLLExport) 12 | #define DLLExport 13 | #endif 14 | 15 | DLLExport int MQTTSerialize_subscribe(unsigned char *buf, int buflen, unsigned char dup, unsigned short packetid, 16 | int count, MQTTString topicFilters[], int requestedQoSs[]); 17 | 18 | DLLExport int MQTTDeserialize_subscribe(unsigned char *dup, unsigned short *packetid, 19 | int maxcount, int *count, MQTTString topicFilters[], int requestedQoSs[], unsigned char *buf, int len); 20 | 21 | DLLExport int MQTTSerialize_suback(unsigned char *buf, int buflen, unsigned short packetid, int count, 22 | int *grantedQoSs); 23 | 24 | DLLExport int MQTTDeserialize_suback(unsigned short *packetid, int maxcount, int *count, int grantedQoSs[], 25 | unsigned char *buf, int len); 26 | 27 | 28 | #endif /* MQTTSUBSCRIBE_H_ */ 29 | 30 | 31 | -------------------------------------------------------------------------------- /components/linkkit/mqtt/MQTTUnsubscribe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef MQTTUNSUBSCRIBE_H_ 6 | #define MQTTUNSUBSCRIBE_H_ 7 | 8 | #if !defined(DLLImport) 9 | #define DLLImport 10 | #endif 11 | #if !defined(DLLExport) 12 | #define DLLExport 13 | #endif 14 | 15 | DLLExport int MQTTSerialize_unsubscribe(unsigned char *buf, int buflen, unsigned char dup, unsigned short packetid, 16 | int count, MQTTString topicFilters[]); 17 | 18 | DLLExport int MQTTDeserialize_unsubscribe(unsigned char *dup, unsigned short *packetid, int max_count, int *count, 19 | MQTTString topicFilters[], 20 | unsigned char *buf, int len); 21 | 22 | DLLExport int MQTTSerialize_unsuback(unsigned char *buf, int buflen, unsigned short packetid); 23 | 24 | DLLExport int MQTTDeserialize_unsuback(unsigned short *packetid, unsigned char *buf, int len); 25 | 26 | #endif /* MQTTUNSUBSCRIBE_H_ */ 27 | 28 | 29 | -------------------------------------------------------------------------------- /components/linkkit/mqtt/mqtt_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __IOTX_MQTT_INTERNAL_H__ 6 | #define __IOTX_MQTT_INTERNAL_H__ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "infra_state.h" 14 | #include "infra_compat.h" 15 | #include "infra_types.h" 16 | #include "infra_defs.h" 17 | #include "infra_string.h" 18 | #include "infra_list.h" 19 | #include "infra_log.h" 20 | #include "infra_report.h" 21 | #include "infra_net.h" 22 | #include "infra_sha256.h" 23 | 24 | #include "dev_sign_api.h" 25 | #include "mqtt_wrapper.h" 26 | #include "iotx_mqtt_config.h" 27 | #include "iotx_mqtt_client.h" 28 | 29 | #include "MQTTPacket.h" 30 | 31 | #ifdef INFRA_LOG 32 | #include "infra_log.h" 33 | #define mqtt_emerg(...) log_emerg("MQTT", __VA_ARGS__) 34 | #define mqtt_crit(...) log_crit("MQTT", __VA_ARGS__) 35 | #define mqtt_err(...) log_err("MQTT", __VA_ARGS__) 36 | #define mqtt_warning(...) log_warning("MQTT", __VA_ARGS__) 37 | #define mqtt_info(...) log_info("MQTT", __VA_ARGS__) 38 | #define mqtt_debug(...) log_debug("MQTT", __VA_ARGS__) 39 | #else 40 | #define mqtt_emerg(fmt, ...) LOGF("MQTT", fmt, ##__VA_ARGS__) 41 | #define mqtt_crit(fmt, ...) LOGF("MQTT", fmt, ##__VA_ARGS__) 42 | #define mqtt_err(fmt, ...) LOGE("MQTT", fmt, ##__VA_ARGS__) 43 | #define mqtt_warning(fmt, ...) LOGW("MQTT", fmt, ##__VA_ARGS__) 44 | #define mqtt_info(fmt, ...) LOGI("MQTT", fmt, ##__VA_ARGS__) 45 | #define mqtt_debug(fmt, ...) LOGD("MQTT", fmt, ##__VA_ARGS__) 46 | #endif 47 | 48 | #endif /* __IOTX_MQTT_INTERNAL_H__ */ 49 | 50 | -------------------------------------------------------------------------------- /components/linkkit/mqtt/mqtt_wrapper.h: -------------------------------------------------------------------------------- 1 | #include "infra_types.h" 2 | #include "infra_defs.h" 3 | // #include "wrappers_defs.h" 4 | // #include "wrappers.h" 5 | #include "mqtt_api.h" 6 | 7 | /* mqtt protocol wrapper */ 8 | void *wrapper_mqtt_init_internal(iotx_mqtt_param_t *mqtt_params); 9 | void *wrapper_mqtt_init(iotx_mqtt_param_t *mqtt_params); 10 | int wrapper_mqtt_connect(void *client); 11 | int wrapper_mqtt_yield(void *client, int timeout_ms); 12 | int wrapper_mqtt_check_state(void *client); 13 | int wrapper_mqtt_subscribe(void *client, 14 | const char *topicFilter, 15 | iotx_mqtt_qos_t qos, 16 | iotx_mqtt_event_handle_func_fpt topic_handle_func, 17 | void *pcontext); 18 | int wrapper_mqtt_subscribe_sync(void *client, 19 | const char *topic_filter, 20 | iotx_mqtt_qos_t qos, 21 | iotx_mqtt_event_handle_func_fpt topic_handle_func, 22 | void *pcontext, 23 | int timeout_ms); 24 | int wrapper_mqtt_unsubscribe(void *client, const char *topicFilter); 25 | int wrapper_mqtt_publish(void *client, const char *topicName, iotx_mqtt_topic_info_pt topic_msg); 26 | int wrapper_mqtt_release(void **pclient); 27 | int wrapper_mqtt_nwk_event_handler(void *client, iotx_mqtt_nwk_event_t event, iotx_mqtt_nwk_param_t *param); 28 | 29 | 30 | -------------------------------------------------------------------------------- /components/linkkit/sdk_include.h: -------------------------------------------------------------------------------- 1 | #ifndef _SDK_INCLUDE_H_ 2 | #define _SDK_INCLUDE_H_ 3 | 4 | #include "infra_types.h" 5 | #include "infra_defs.h" 6 | #include "infra_compat.h" 7 | #include "wrappers_defs.h" 8 | #include "wrappers.h" 9 | #include "mqtt_api.h" 10 | #include "dynreg_api.h" 11 | #include "dev_model_api.h" 12 | #include "dev_sign_api.h" 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /components/ota/Config.in: -------------------------------------------------------------------------------- 1 | menuconfig AOS_COMP_OTA 2 | bool "OTA Features" 3 | select MBEDTLS_CONFIG_CRYPTO_MD5 if AOS_COMP_MBEDTLS 4 | select AOS_COMP_CJSON 5 | select AOS_COMP_OTA_AGENT 6 | select OTA_CONFIG_BLE if AOS_COMP_BREEZE 7 | select CONFIG_COMP_BZ_HAL_CRYPTO_MEBDTLS if AOS_COMP_BREEZE 8 | select AOS_COMP_SDK_MQTT if !OTA_CONFIG_BLE && !OTA_CONFIG_SLAVE 9 | select AOS_COMP_HTTP if !OTA_CONFIG_BLE && !OTA_CONFIG_SLAVE 10 | default n 11 | help 12 | 13 | 14 | if AOS_COMP_OTA 15 | config OTA_CONFIG_RSA 16 | bool "RSA Verify Support" 17 | default n 18 | help 19 | select Y to support RSA Verify. 20 | 21 | if OTA_CONFIG_RSA 22 | choice 23 | prompt "Select signature" 24 | default OTA_CONFIG_LOCAL_RSA 25 | help 26 | choose where to sign 27 | 28 | config OTA_CONFIG_CLOUD_RSA 29 | bool "cloud sign" 30 | help 31 | signature in the cloud. 32 | 33 | config OTA_CONFIG_LOCAL_RSA 34 | bool "local sign" 35 | help 36 | signature in the alios studio. 37 | endchoice 38 | endif 39 | 40 | config CONFIG_AOS_OTA_AGENT 41 | bool "OTA agent fuction enable" 42 | source "components/dm/ota/ota_agent/Config.in" 43 | 44 | config OTA_FLASH_WRITE_CACHE_SIZE 45 | int "write flash cache size(bytes)" 46 | default 1024 47 | help 48 | This option sets the ota write flash cache size for 8-byte alignment. 49 | This option is limited by the board memory size. 50 | This value could be 512 1024 2048 4096 ... 51 | The default value is 1024 52 | 53 | endif 54 | -------------------------------------------------------------------------------- /components/ota/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libota.a 2 | MODULE = ota 3 | 4 | MOD_SOURCES := \ 5 | ota_agent/ota_service.c 6 | 7 | MOD_SOURCES += \ 8 | ota_agent/download/ota_download_http.c \ 9 | ota_agent/download/ota_download_file2fs_http.c \ 10 | ota_agent/transport/ota_transport_mqtt.c \ 11 | ota_agent/verify/ota_verify_hash.c \ 12 | ota_agent/verify/ota_verify_rsa.c \ 13 | ota_agent/tools/upack_data_file.c 14 | 15 | MOD_SOURCES += \ 16 | hal/ota_hal_ctrl.c \ 17 | hal/ota_hal_digest.c \ 18 | hal/ota_hal_os.c \ 19 | hal/ota_hal_param.c \ 20 | hal/ota_hal_trans.c \ 21 | hal/ota_hal_plat.c \ 22 | hal/ota_hal_fs_ctrl.c \ 23 | hal/ota_hal_fs_plat.c 24 | 25 | MOD_INCLUDES := \ 26 | . \ 27 | include \ 28 | hal \ 29 | ota_agent/tools \ 30 | ../ulog \ 31 | ../../adapter/include \ 32 | ../../adapter/include/peripheral \ 33 | ../../adapter/platform/linux \ 34 | ../../utils/mbedtls/include \ 35 | ../../utils/cJSON \ 36 | ../http/include \ 37 | ../linkkit/mqtt \ 38 | ../linkkit/infra \ 39 | ../linkkit 40 | 41 | include $(TOOLS_DIR)/rules.mk 42 | -------------------------------------------------------------------------------- /components/ota/hal/ota_hal_digest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef OTA_HAL_DIGEST_H 6 | #define OTA_HAL_DIGEST_H 7 | #include "ota_agent.h" 8 | 9 | /*Verify API*/ 10 | /*SHA256*/ 11 | void ota_sha256_free(ota_sha256_context *ctx); 12 | void ota_sha256_init(ota_sha256_context *ctx); 13 | void ota_sha256_starts(ota_sha256_context *ctx, int is224); 14 | void ota_sha256_update(ota_sha256_context *ctx, const unsigned char *input, unsigned int ilen); 15 | void ota_sha256_finish(ota_sha256_context *ctx, unsigned char output[32]); 16 | /*MD5*/ 17 | void ota_md5_free(ota_md5_context *ctx); 18 | void ota_md5_init(ota_md5_context *ctx); 19 | void ota_md5_starts(ota_md5_context *ctx); 20 | void ota_md5_update(ota_md5_context *ctx, const unsigned char *input, unsigned int ilen); 21 | void ota_md5_finish(ota_md5_context *ctx, unsigned char output[16]); 22 | /*RSA*/ 23 | const unsigned char *ota_rsa_pubkey_n(void); 24 | const unsigned char *ota_rsa_pubkey_e(void); 25 | unsigned int ota_rsa_pubkey_n_size(void); 26 | unsigned int ota_rsa_pubkey_e_size(void); 27 | int ota_rsa_pubkey_verify(const unsigned char *pubkey_n, 28 | const unsigned char *pubkey_e, 29 | unsigned int pubkey_n_size, 30 | unsigned int pubkey_e_size, 31 | const unsigned char *dig, 32 | unsigned int dig_size, 33 | const unsigned char *sig, 34 | unsigned int sig_size); 35 | #endif /*OTA_HAL_DIGEST_H*/ 36 | 37 | -------------------------------------------------------------------------------- /components/ota/hal/ota_hal_os.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef OTA_HAL_OS_H 6 | #define OTA_HAL_OS_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define ota_snprintf snprintf 13 | 14 | /*memory*/ 15 | void ota_free(void *ptr); 16 | void *ota_malloc(int size); 17 | void *ota_calloc(int n, int size); 18 | void *ota_realloc(void *ptr, int size); 19 | 20 | /*Semaphore*/ 21 | void *ota_semaphore_create(void); 22 | void ota_semaphore_post(void *sem); 23 | void ota_semaphore_destroy(void *sem); 24 | int ota_semaphore_wait(void *sem, int ms); 25 | 26 | /*Thread*/ 27 | int ota_thread_create( 28 | void **thread_handle, 29 | void *(*work_routine)(void *), 30 | void *arg, 31 | void *param, 32 | int stack_size); 33 | void ota_thread_exit(void *thread); 34 | void ota_msleep(int ms); 35 | 36 | /*Reboot*/ 37 | void ota_reboot(void); 38 | 39 | /* String */ 40 | int ota_to_capital(char *value, int len); 41 | int ota_str2hex(const char *src, char *dest, unsigned int dest_len); 42 | int ota_hex2str(char *dest_buf, const unsigned char *src_buf, unsigned int dest_len, unsigned int src_len); 43 | 44 | /*Base64*/ 45 | int ota_base64_decode(const unsigned char *input, unsigned int input_len, unsigned char *output, unsigned int *output_len); 46 | 47 | /*CRC16*/ 48 | typedef struct { 49 | unsigned short crc; 50 | } ota_crc16_ctx; 51 | void ota_crc16_init(ota_crc16_ctx *ctx); 52 | void ota_crc16_update(ota_crc16_ctx *ctx, const void *inSrc, unsigned int inLen); 53 | void ota_crc16_final(ota_crc16_ctx *ctx, unsigned short *outResult); 54 | unsigned short ota_get_data_crc16(const unsigned char *buf, unsigned int len); 55 | int ota_thread_destroy(void *ptread); 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #endif /*OTA_HAL_OS_H*/ 60 | -------------------------------------------------------------------------------- /components/ota/hal/ota_hal_trans.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include "ota_log.h" 7 | //#include 8 | #include "amp_platform.h" 9 | #include "ota_hal_trans.h" 10 | 11 | #ifndef OTA_SIGNAL_CHANNEL 12 | #define OTA_SIGNAL_CHANNEL 1 13 | #endif 14 | #include "infra/infra_defs.h" 15 | #include "mqtt/mqtt_api.h" 16 | #include "wrappers.h" 17 | #include "amp_socket.h" 18 | 19 | int close(int fd); 20 | int ota_hal_socket(void) 21 | { 22 | return amp_socket_open(AF_INET, SOCK_STREAM, 0); 23 | } 24 | 25 | int ota_hal_close(int fd) 26 | { 27 | return amp_socket_close(fd); 28 | } 29 | 30 | /*MQTT API*/ 31 | int ota_hal_mqtt_publish(void *mqtt_client, char *topic, int qos, void *data, int len) 32 | { 33 | return IOT_MQTT_Publish_Simple(mqtt_client, topic, qos, data, len); 34 | } 35 | 36 | int ota_hal_mqtt_subscribe(void *mqtt_client, char *topic, void *cb, void *ctx) 37 | { 38 | return IOT_MQTT_Subscribe_Sync(mqtt_client, topic, 0, cb, ctx, 1000); 39 | } 40 | 41 | int ota_hal_mqtt_deinit(void) 42 | { 43 | return IOT_MQTT_Destroy(NULL); 44 | } 45 | 46 | int ota_hal_mqtt_init(void) 47 | { 48 | return (IOT_MQTT_Construct(NULL) == NULL) ? -1 : 0; 49 | } 50 | -------------------------------------------------------------------------------- /components/ota/include/ota_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef OTA_LOG_H 6 | #define OTA_LOG_H 7 | #include 8 | #include 9 | #include "ulog.h" 10 | 11 | #define OTA_LOG_D(fmt, ...) LOGD("ota",fmt,##__VA_ARGS__) 12 | #define OTA_LOG_I(fmt, ...) LOGI("ota",fmt,##__VA_ARGS__) 13 | #define OTA_LOG_W(fmt, ...) LOGW("ota",fmt,##__VA_ARGS__) 14 | #define OTA_LOG_E(fmt, ...) LOGE("ota",fmt,##__VA_ARGS__) 15 | #endif /*OTA_LOG_H*/ 16 | -------------------------------------------------------------------------------- /components/ota/ota_agent/tools/upack_data_file.h: -------------------------------------------------------------------------------- 1 | #ifndef UPACK_DATA_FILE_H 2 | #define UPACK_DATA_FILE_H 3 | 4 | typedef struct DATA_FILE_PACK_HEAD { 5 | unsigned short file_numb; 6 | unsigned short pack_ver; 7 | unsigned int pack_size; 8 | } data_file_pack_head_t; 9 | 10 | typedef struct DATA_FILE_INFO{ 11 | unsigned int head_size; 12 | unsigned int file_size; 13 | char md5_vale[16]; 14 | } data_file_infor_t; 15 | 16 | /** 17 | * data_file_unpack data file unpack. 18 | * 19 | * @param[in] void *pack_file pack file name 20 | * @param[in] unsigned int pack_size pack file size 21 | * @param[in] void *upack_path unpack file store path 22 | * 23 | * @return 0 upack success. 24 | * @return -1 unpack failed. 25 | */ 26 | int data_file_unpack(void *pack_file, unsigned int pack_size, void *upack_path); 27 | #endif -------------------------------------------------------------------------------- /components/ota/ota_agent/tools/xz/include/xz_export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | #ifndef XZ_EXPORT_H 5 | #define XZ_EXPORT_H 6 | #include "aos/hal/flash.h" 7 | 8 | #define XZ_SUCCESS 0 9 | #define XZ_INPURT_PARAM_ERR -1 10 | #define XZ_MALLOC_FAILED -2 11 | #define XZ_READ_FLASH_FAILED -3 12 | #define XZ_WRITE_FLASH_FAILED -4 13 | #define XZ_ERASE_FLASH_FAILED -5 14 | #define XZ_CRC_ERROR -6 15 | #define XZ_UNPROCESS_FAILED -7 16 | #define XZ_VERIFY_FAILED -8 17 | #define XZ_FILE_IDENTIFY_FAILED -9 18 | 19 | int xz_file_uncompress(hal_partition_t des_partition, hal_partition_t src_partition, unsigned int xz_size, unsigned short xz_crc16); 20 | #endif /*XZ_EXPORT_H */ 21 | -------------------------------------------------------------------------------- /components/ota/ota_agent/tools/xz/include/xz_hal_plat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | #ifndef XZ_HAL_PLAT_H 5 | #define XZ_HAL_PLAT_H 6 | #include 7 | #include 8 | #include 9 | #include "aos/hal/flash.h" 10 | 11 | #define SECTOR_SIZE 0x1000 /* flash sector size */ 12 | #ifndef XZ_BUF_SIZE 13 | #define XZ_BUF_SIZE 2048 14 | #endif 15 | 16 | /* flash APIs */ 17 | int xz_flash_erase(hal_partition_t flash_partition, unsigned int offset, unsigned int len); 18 | int xz_flash_read_data(hal_partition_t flash_partition, unsigned int offset, unsigned char *buf, unsigned int len); 19 | int xz_flash_write_data(hal_partition_t flash_partition, unsigned int offset, unsigned char *buf, unsigned int len); 20 | 21 | #endif /*XZ_HAL_PLAT_H */ 22 | -------------------------------------------------------------------------------- /components/ota/ota_agent/tools/xz/include/xz_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Definitions for handling the .xz file format 3 | * 4 | * Author: Lasse Collin 5 | * 6 | * This file has been put into the public domain. 7 | * You can do whatever you want with this file. 8 | */ 9 | 10 | #ifndef XZ_STREAM_H 11 | #define XZ_STREAM_H 12 | 13 | #if defined(__KERNEL__) && !XZ_INTERNAL_CRC32 14 | #include 15 | #undef crc32 16 | #define xz_crc32(buf, size, crc) \ 17 | (~crc32_le(~(uint32_t)(crc), buf, size)) 18 | #endif 19 | 20 | /* 21 | * See the .xz file format specification at 22 | * http://tukaani.org/xz/xz-file-format.txt 23 | * to understand the container format. 24 | */ 25 | 26 | #define STREAM_HEADER_SIZE 12 27 | 28 | #define HEADER_MAGIC "\3757zXZ" 29 | #define HEADER_MAGIC_SIZE 6 30 | 31 | #define FOOTER_MAGIC "YZ" 32 | #define FOOTER_MAGIC_SIZE 2 33 | 34 | /* 35 | * Variable-length integer can hold a 63-bit unsigned integer or a special 36 | * value indicating that the value is unknown. 37 | * 38 | * Experimental: vli_type can be defined to uint32_t to save a few bytes 39 | * in code size (no effect on speed). Doing so limits the uncompressed and 40 | * compressed size of the file to less than 256 MiB and may also weaken 41 | * error detection slightly. 42 | */ 43 | typedef uint64_t vli_type; 44 | 45 | #define VLI_MAX ((vli_type)-1 / 2) 46 | #define VLI_UNKNOWN ((vli_type)-1) 47 | 48 | /* Maximum encoded size of a VLI */ 49 | #define VLI_BYTES_MAX (sizeof(vli_type) * 8 / 7) 50 | 51 | /* Integrity Check types */ 52 | enum xz_check { 53 | XZ_CHECK_NONE = 0, 54 | XZ_CHECK_CRC32 = 1, 55 | XZ_CHECK_CRC64 = 4, 56 | XZ_CHECK_SHA256 = 10 57 | }; 58 | 59 | /* Maximum possible Check ID */ 60 | #define XZ_CHECK_MAX 15 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /components/ota/ota_agent/tools/xz/src/xz_hal_plat.c: -------------------------------------------------------------------------------- 1 | #include "aos/hal/flash.h" 2 | #include "xz_hal_plat.h" 3 | 4 | int xz_flash_erase(hal_partition_t flash_partition, unsigned int offset, unsigned int len) 5 | { 6 | int ret = 0; 7 | ret = hal_flash_erase(flash_partition, offset, len); 8 | return ret; 9 | } 10 | 11 | int xz_flash_read_data(hal_partition_t flash_partition, unsigned int offset, unsigned char *buffer, unsigned int len) 12 | { 13 | int ret = 0; 14 | unsigned int tmp_offset = offset; 15 | ret = hal_flash_read(flash_partition, &tmp_offset, buffer, len); 16 | return ret; 17 | } 18 | 19 | int xz_flash_write_data(hal_partition_t flash_partition, unsigned int offset, unsigned char *buffer, unsigned int len) 20 | { 21 | int ret = 0; 22 | unsigned int tmp_offset = offset; 23 | ret = hal_flash_write(flash_partition, &tmp_offset, buffer, len); 24 | return ret; 25 | } -------------------------------------------------------------------------------- /components/ulog/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libulog.a 2 | MODULE = ulog 3 | 4 | MOD_SOURCES += \ 5 | ulog.c \ 6 | ulog_init.c \ 7 | ulog_utility.c 8 | 9 | MOD_INCLUDES := \ 10 | ../../adapter/include \ 11 | ../linkkit \ 12 | ../linkkit/infra \ 13 | . \ 14 | include \ 15 | ../../main 16 | 17 | include $(TOOLS_DIR)/rules.mk 18 | -------------------------------------------------------------------------------- /components/ulog/aos.mk: -------------------------------------------------------------------------------- 1 | NAME = libamp_ulog 2 | 3 | $(NAME)_SOURCES += \ 4 | ulog.c \ 5 | ulog_init.c \ 6 | ulog_utility.c 7 | 8 | $(NAME)_INCLUDES := \ 9 | ../../adapter/include \ 10 | ../linkkit \ 11 | ../linkkit/infra \ 12 | . \ 13 | include \ 14 | ../../main -------------------------------------------------------------------------------- /components/ulog/ulog_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef U_LOG_API__H 6 | #define U_LOG_API__H 7 | #include 8 | #include 9 | #include "ulog_config.h" 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | extern bool g_log_init; 15 | 16 | bool log_get_mutex(void); 17 | 18 | void log_release_mutex(void); 19 | 20 | void log_init_mutex(void); 21 | 22 | void on_sync_filter_level_change(const ulog_session_type_t session, const char level); 23 | void on_filter_change(const ulog_session_type_t session, const char level); 24 | 25 | uint8_t ulog_stop_filter_level(const ulog_session_type_t session); 26 | 27 | char* get_sync_stop_level(); 28 | 29 | int32_t ulog_fs_init(void); 30 | 31 | void on_filter_level_changes(const ulog_session_type_t session, const uint8_t level); 32 | 33 | bool check_pass_pop_out(const ulog_session_type_t session, const uint8_t level); 34 | 35 | void ulog_async_init(); 36 | 37 | int32_t pop_out_on_udp(const char* data, const uint16_t len); 38 | 39 | int32_t pop_out_on_fs(const char* data, const uint16_t len); 40 | 41 | void on_show_ulog_file(void); 42 | 43 | void update_net_cli(const char cmd, const char* param); 44 | 45 | void fs_control_cli(const char cmd, const char* param); 46 | 47 | void on_update_syslog_watcher_addr(const uint32_t ip_nl, const uint32_t port); 48 | void on_tcpip_service_on(const uint32_t on, const uint32_t off); 49 | void on_fs_record_pause(const uint32_t on, const uint32_t off); 50 | 51 | char* trim_file_path(const char* path); 52 | char *ulog_format_time(char *buffer, const int len); 53 | 54 | int http_start(const char *url, const unsigned short idx); 55 | void on_fs_upload(const uint32_t idx, const uint32_t start); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /*U_LOG_API__H*/ 62 | 63 | -------------------------------------------------------------------------------- /components/ulog/ulog_ring_fifo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include "ulog_ring_fifo.h" 6 | #include 7 | #include 8 | #include "ulog_config.h" 9 | 10 | static void *ulog_queue; 11 | static uint8_t* ulog_buffer; 12 | 13 | 14 | /** 15 | * This function will create a ring fifo for ulog. 16 | * 17 | * 18 | * @return 0: success. 19 | */ 20 | int uring_fifo_init() 21 | { 22 | int rc = -1; 23 | if (ulog_buffer == NULL) { 24 | ulog_buffer = amp_malloc(DEFAULT_ASYNC_BUF_SIZE); 25 | if (ulog_buffer != NULL) { 26 | ulog_queue = amp_queue_create(ulog_buffer, ULOG_SIZE); 27 | if (NULL == ulog_queue) { 28 | amp_free(ulog_buffer); 29 | ulog_buffer = NULL; 30 | } 31 | } 32 | } 33 | 34 | return rc; 35 | } 36 | 37 | /** 38 | * Thread Safe to put the msg into ring - fifo. 39 | * 40 | * @param[in] queue pointer to the queue. 41 | * @param[in] msg msg to send. 42 | * @param[in] size size of the msg. 43 | * 44 | * @return 0: success. 45 | */ 46 | int uring_fifo_push_s(const void* buf, const uint16_t len) 47 | { 48 | return amp_queue_send(ulog_queue, (void*)buf, len, 0); 49 | } 50 | 51 | int uring_fifo_pop_cb(pop_callback cb, void* cb_arg) 52 | { 53 | char tmp_buf[ULOG_SIZE]; 54 | unsigned int rcv_size = 0; 55 | int rc = amp_queue_recv(ulog_queue, tmp_buf, &rcv_size, 1000); 56 | if ((0 == rc) && (cb != NULL)) { 57 | cb(cb_arg, tmp_buf, (uint16_t)rcv_size); 58 | } 59 | return rc; 60 | } 61 | -------------------------------------------------------------------------------- /components/ulog/ulog_ring_fifo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef ULOG_RING_FIFO_H_ 6 | #define ULOG_RING_FIFO_H_ 7 | #include 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | typedef void (*pop_callback)(void*, void* src, const uint16_t len); 13 | 14 | extern int uring_fifo_push_s(const void* buf, const uint16_t len); 15 | 16 | extern int uring_fifo_pop_cb(pop_callback cb, void* cb_arg); 17 | 18 | extern int uring_fifo_init(void); 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /*ULOG_RING_FIFO_H_*/ 24 | -------------------------------------------------------------------------------- /components/und/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libund.a 2 | MODULE = und 3 | 4 | MOD_SOURCES := \ 5 | src/und_adapter.c \ 6 | src/und_manage.c \ 7 | src/und_packet.c \ 8 | src/und_report.c \ 9 | src/und_sched.c \ 10 | src/und.c 11 | 12 | MOD_INCLUDES := \ 13 | ../../adapter/include \ 14 | ../../adapter/platform/linux \ 15 | ../../main \ 16 | ../../utils/mbedtls/include \ 17 | ../linkkit \ 18 | ../linkkit/infra \ 19 | ../ulog \ 20 | include 21 | 22 | include $(TOOLS_DIR)/rules.mk 23 | -------------------------------------------------------------------------------- /components/und/include/und_adapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef UND_ADAPTER_H 6 | #define UND_ADAPTER_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | int und_conn_is_connected(); 13 | 14 | int und_conn_unregister_cb(char *topic); 15 | 16 | int und_conn_register_cb(char *topic, void *cb); 17 | 18 | /* 19 | * send und packet, to isolate the detail of protocol (MQTT/HTTP/COAP) 20 | */ 21 | int und_conn_send(char *topic, void *data, int len, int qos); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif /* end of UND_ADAPTER_H */ 28 | -------------------------------------------------------------------------------- /components/und/include/und_hal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef UND_HAL_H 6 | #define UND_HAL_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | struct und_wireless_info_t { 13 | int rssi; /* Received Signal Strength Indication */ 14 | int snr; /* Signal to Noise Ratio */ 15 | int per; /* Packet Error Rate (Unit: PPM, Part Per Million) */ 16 | }; 17 | 18 | /** 19 | * @brief Get wireless information from driver real time. 20 | * 21 | * @param[in] info @n Driver returns wireless information with info. 22 | * @return 0: success, otherwise: fail. 23 | * @see None. 24 | * @note None. 25 | */ 26 | // int amp_get_wireless_info(struct und_wireless_info_t *info); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif /* UND_HAL_H */ 33 | -------------------------------------------------------------------------------- /components/und/include/und_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef UND_LOG_H 6 | #define UND_LOG_H 7 | 8 | #include "infra_log.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | #if 1 14 | #define und_debug(FMT, args...) log_debug("[und]:", FMT, ##args) 15 | #define und_info(FMT, args...) log_info("[und]", FMT, ##args) 16 | #define und_warn(FMT, args...) log_warning("[und]", FMT, ##args) 17 | #define und_err(FMT, args...) log_err("[und]", FMT, ##args) 18 | #define und_crt(FMT, args...) log_crt("[und]", FMT, ##args) 19 | #else 20 | #define und_debug(FMT, args...) do {amp_printf("[und]:"); amp_printf(FMT "\r\n", ##args);} while(0) 21 | #define und_info(FMT, args...) do {amp_printf("[und]:"); amp_printf(FMT "\r\n", ##args);} while(0) 22 | #define und_warn(FMT, args...) do {amp_printf("[und]:"); amp_printf(FMT "\r\n", ##args);} while(0) 23 | #define und_err(FMT, args...) do {amp_printf("[und]:"); amp_printf(FMT "\r\n", ##args);} while(0) 24 | #define und_crt(FMT, args...) do {amp_printf("[und]:"); amp_printf(FMT "\r\n", ##args);} while(0) 25 | #endif 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* end of UND_LOG_H */ 32 | -------------------------------------------------------------------------------- /components/und/include/und_manage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef UND_MANAGE_H 6 | #define UND_MANAGE_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | int und_cap_manage_init(); 13 | 14 | int und_cap_manage_deinit(); 15 | 16 | int und_cap_manage_clear_kv(); 17 | 18 | int und_update_cap(int cap_idx, int reason_code, int wb, int sync); 19 | 20 | int und_collect_package(char *buf, int buf_len, int insert_split, int with_exception); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif /* end of UND_MANAGE_H */ 27 | -------------------------------------------------------------------------------- /components/und/include/und_packet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef UND_PACKET_H 6 | #define UND_PACKET_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define UND_TOPIC_REPORT_REPLY "/sys/%s/%s/_thing/diag/post_reply" 13 | #define UND_TOPIC_REPORT "/sys/%s/%s/_thing/diag/post" 14 | #define UND_METHOD_REPORT "thing.log.post" 15 | 16 | #define UND_ALINK_VER "1.0" 17 | #define UND_REPORT_FMT "{\"id\":\"%u\",\"version\":\"%s\",\"params\":%s}" 18 | #define UND_REPORT_PARAM_FMT "{\"p\":[%s],\"model\":\"format=simple|quantity=batch|time=history\"}" 19 | 20 | int und_packet_ctx_init(); 21 | 22 | int und_packet_ctx_deinit(); 23 | 24 | int und_build_topic(const char *fmt, char *topic_buf, int topic_buf_len); 25 | 26 | int und_build_packet_param(const char *content, char *param, int param_len); 27 | 28 | int und_build_packet(const char *ver, const char *param, char *buf, int buf_len); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* end of UND_PACKET_H */ 35 | -------------------------------------------------------------------------------- /components/und/include/und_platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef UND_PLATFORM_H 6 | #define UND_PLATFORM_H 7 | 8 | #include 9 | #include 10 | 11 | #ifdef BUILD_AOS 12 | #include "aos/kernel.h" 13 | #include "aos/kv.h" 14 | #else 15 | #include "wrappers.h" 16 | #endif 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #ifndef BUILD_AOS 23 | #define aos_malloc(size) amp_malloc(size) 24 | #define aos_free(ptr) amp_free(ptr) 25 | #define aos_kv_set amp_kv_set 26 | #define aos_kv_get amp_kv_get 27 | #define aos_kv_del amp_kv_del 28 | #endif 29 | 30 | #define aos_timer_create amp_timer_create 31 | #define aos_timer_start amp_timer_start 32 | #define aos_timer_stop amp_timer_stop 33 | #define aos_timer_delete amp_timer_delete 34 | #define aos_memset memset 35 | #define aos_strlen strlen 36 | #define aos_snprintf amp_snprintf 37 | 38 | #define undp_mutex_lock amp_mutex_lock 39 | #define undp_mutex_unlock amp_mutex_unlock 40 | #define undp_mutex_new amp_mutex_create 41 | #define undp_mutex_free amp_mutex_destroy 42 | #define undp_get_product_key HAL_GetProductKey 43 | #define undp_get_device_name HAL_GetDeviceName 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* UND_PLATFORM_H */ 50 | -------------------------------------------------------------------------------- /components/und/include/und_report.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef UND_REPORT_H 6 | #define UND_REPORT_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | int und_report_init(); 13 | 14 | int und_report_deinit(); 15 | 16 | int und_update_report(int cap_idx); 17 | 18 | int und_update_report_cycle(int fast); 19 | 20 | void und_targets_report(void *param); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif /* end of UND_REPORT_H */ 27 | -------------------------------------------------------------------------------- /components/und/include/und_sched.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef UND_SCHED_H 6 | #define UND_SCHED_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | int und_sched_init(void *sched_task); 13 | 14 | int und_sched_deinit(); 15 | 16 | int und_sched_start(int cycle_ms); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif /* end of UND_SCHED_H */ 23 | -------------------------------------------------------------------------------- /components/und/include/und_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef UND_TYPES_H 6 | #define UND_TYPES_H 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | enum { 16 | UND_PARAM_ERR = -3, 17 | UND_MEM_ERR = -2, 18 | UND_ERR = -1, 19 | UND_SUCCESS = 0, 20 | }; 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif /* end of UND_TYPES_H */ 27 | -------------------------------------------------------------------------------- /components/und/include/und_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef UND_UTILS_H 6 | #define UND_UTILS_H 7 | 8 | #include "und_log.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #define UND_INIT_SANITY_CHECK(param, uninit_val, err) \ 15 | do { \ 16 | if (!!((param) == (uninit_val))) { \ 17 | und_err("%s is not init", #param); \ 18 | return (err); \ 19 | } \ 20 | } while(0) 21 | 22 | #define UND_PARAM_RANGE_SANITY_CHECK(param, max, min, err) \ 23 | do { \ 24 | if ((param) > (max) || (param) < (min)) { \ 25 | und_err("Invalid param, out of range"); \ 26 | return (err); \ 27 | } \ 28 | } while(0) 29 | 30 | #define UND_PTR_SANITY_CHECK(ptr, err) \ 31 | do { \ 32 | if (NULL == (ptr)) { \ 33 | und_err("Invalid param, %s = %p", #ptr, ptr); \ 34 | return (err); \ 35 | } \ 36 | } while(0) 37 | 38 | #define UND_STR_PTR_SANITY_CHECK(ptr, err) \ 39 | do { \ 40 | UND_PTR_SANITY_CHECK(ptr, err); \ 41 | if (0 == aos_strlen((ptr))) { \ 42 | und_err("Invalid param, %s = '%s'", #ptr, (ptr)); \ 43 | return (err); \ 44 | } \ 45 | } while(0) 46 | 47 | #define UND_STR_PTR_MAXLEN_SANITY_CHECK(ptr, maxlen, err) \ 48 | do { \ 49 | UND_STR_PTR_SANITY_CHECK(ptr, err); \ 50 | if (maxlen < aos_strlen((ptr))) { \ 51 | und_err("Invalid param, %s = '%s'", #ptr, (ptr)); \ 52 | return (err); \ 53 | } \ 54 | } while(0) 55 | 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* end of UND_UTILS_H */ 62 | -------------------------------------------------------------------------------- /components/uvoice/include/uvoice_comb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __UVOICE_COMB_H__ 6 | #define __UVOICE_COMB_H__ 7 | 8 | 9 | int comb_add_amount(const char *amount, int index); 10 | int comb_add_number(const char *number, int index); 11 | int comb_add_file_source(const char *source, int index); 12 | int comb_add_http_source(const char *source, int index); 13 | 14 | int comb_alipay_number(double amount); 15 | int comb_receipt_play(const char *req); 16 | int comb_content_play(const char *req); 17 | int comb_play_stop(void); 18 | int comb_init(void); 19 | 20 | 21 | #endif /* __UVOICE_COMB_H__ */ 22 | -------------------------------------------------------------------------------- /components/uvoice/include/uvoice_event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __UVOICE_EVENT_H__ 6 | #define __UVOICE_EVENT_H__ 7 | 8 | 9 | #define UVOICE_EV_PLAYER 0x0111 10 | #define UVOICE_CODE_PLAYER_STATE 1 11 | #define UVOICE_CODE_PALYER_CACHE_CPLT 2 12 | #define UVOICE_CODE_PALYER_DLOAD_CPLT 3 13 | 14 | #define UVOICE_EV_RECORDER 0x0112 15 | #define UVOICE_CODE_RECORDER_STATE 1 16 | 17 | #define UVOICE_EV_SW 0x0113 18 | #define UVOICE_CODE_HEADPHONE 1 19 | #define UVOICE_CODE_HEADSET 2 20 | 21 | #define UVOICE_EV_ST 0x0114 22 | #define UVOICE_CODE_VAD_START 1 23 | #define UVOICE_CODE_VAD_END 2 24 | #define UVOICE_CODE_VOICE_WAKEUP 3 25 | 26 | #define UVOICE_EV_ASR_RESULT 0x0115 27 | 28 | typedef struct { 29 | uint16_t type; 30 | uint16_t code; 31 | int value; 32 | } uvoice_event_t; 33 | 34 | typedef void (*uvoice_event_cb)(uvoice_event_t *event, void *data); 35 | int uvoice_event_post(uint16_t type, uint16_t code, int value); 36 | int uvoice_event_register(uint16_t type, uvoice_event_cb cb, void *data); 37 | int uvoice_event_unregister(uint16_t type, uvoice_event_cb cb, void *data); 38 | 39 | 40 | #endif /* __UVOICE_EVENT_H__ */ 41 | 42 | -------------------------------------------------------------------------------- /components/uvoice/include/uvoice_init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __UVOICE_INIT_H__ 6 | #define __UVOICE_INIT_H__ 7 | 8 | 9 | int uvoice_init(void); 10 | 11 | int uvoice_free(void); 12 | 13 | 14 | #endif /* __UVOICE_INIT_H__ */ 15 | 16 | -------------------------------------------------------------------------------- /components/uvoice/include/uvoice_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __UVOICE_TYPES_H__ 6 | #define __UVOICE_TYPES_H__ 7 | 8 | 9 | typedef enum { 10 | MEDIA_FMT_UNKNOWN = 0, 11 | MEDIA_FMT_PCM, 12 | MEDIA_FMT_WAV, 13 | MEDIA_FMT_MP3, 14 | MEDIA_FMT_AAC, 15 | MEDIA_FMT_M4A, 16 | MEDIA_FMT_OGG, 17 | MEDIA_FMT_OPS, 18 | MEDIA_FMT_SPX, 19 | MEDIA_FMT_WMA, 20 | MEDIA_FMT_AMR, 21 | MEDIA_FMT_AMRWB, 22 | MEDIA_FMT_FLAC, 23 | MEDIA_FMT_COUNT, 24 | } media_format_t; 25 | 26 | typedef struct { 27 | char name[32]; 28 | char author[32]; 29 | char album[32]; 30 | char year[8]; 31 | int valid; 32 | unsigned char type; 33 | int32_t bitrate; 34 | int32_t media_size; 35 | int32_t duration; 36 | } media_info_t; 37 | 38 | typedef struct { 39 | int place; /* 0: none, 1: file, 2: mem */ 40 | int mem_size; /* cache memory size in KB */ 41 | char file_path[128]; /* cache file full path */ 42 | } cache_config_t; 43 | 44 | 45 | #endif /* __UVOICE_TYPES_H__ */ 46 | -------------------------------------------------------------------------------- /engine/duktape_engine/Config.in: -------------------------------------------------------------------------------- 1 | ################################################################### 2 | # Component enable/disable selection 3 | # in the updated build system, default is y and can not be disabled 4 | if AOS_CREATE_PROJECT 5 | config AOS_COMP_AMP_ENGINE_DUK 6 | bool 7 | default y 8 | # do NOT select depend component in this file 9 | # use $(NAME)_COMPONENTS in aos.mk 10 | endif 11 | 12 | # Backward compatibility 13 | if !AOS_CREATE_PROJECT 14 | config AOS_COMP_AMP_ENGINE_DUK 15 | bool "amp_engine_duk" 16 | default y 17 | help 18 | AliOS things mini program -- smart config support component 19 | endif -------------------------------------------------------------------------------- /engine/duktape_engine/addons/hardware/wdg/module_wdg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | /* #define LOG_NDEBUG 0 */ 6 | #include 7 | 8 | #include "amp_defines.h" 9 | #include "amp_hal_wdg.h" 10 | #include "board_mgr.h" 11 | #include "be_inl.h" 12 | 13 | #define MOD_STR "WDG" 14 | static wdg_dev_t wdg_dev; 15 | 16 | static duk_ret_t native_wdg_start(duk_context *ctx) 17 | { 18 | int ret = -1; 19 | int32_t timeout = 0; 20 | wdg_dev_t *handle = (wdg_dev_t *)&wdg_dev; 21 | 22 | if (!duk_is_number(ctx, 0)) { 23 | amp_warn(MOD_STR, "parameter must be number\n"); 24 | goto out; 25 | } 26 | 27 | timeout = duk_get_int(ctx, 0); 28 | if (timeout < 0) { 29 | amp_error(MOD_STR, "invalid timeout: %d\n", timeout); 30 | goto out; 31 | } 32 | handle->config.timeout = timeout; 33 | ret = amp_hal_wdg_init(handle); 34 | handle->config.timeout = (ret == 0) ? timeout : 0; 35 | 36 | out: 37 | duk_push_int(ctx, ret); 38 | return 1; 39 | } 40 | 41 | static duk_ret_t native_wdg_feed(duk_context *ctx) 42 | { 43 | wdg_dev_t *handle = (wdg_dev_t *)&wdg_dev; 44 | amp_hal_wdg_reload(handle); 45 | return 0; 46 | } 47 | 48 | static duk_ret_t native_wdg_stop(duk_context *ctx) 49 | { 50 | wdg_dev_t *handle = (wdg_dev_t *)&wdg_dev; 51 | amp_hal_wdg_finalize(handle); 52 | handle->config.timeout = 0; 53 | return 0; 54 | } 55 | 56 | void module_wdg_register(void) 57 | { 58 | duk_context *ctx = be_get_context(); 59 | 60 | duk_push_object(ctx); 61 | 62 | AMP_ADD_FUNCTION("start", native_wdg_start, 1); 63 | AMP_ADD_FUNCTION("stop", native_wdg_stop, 0); 64 | AMP_ADD_FUNCTION("feed", native_wdg_feed, 0); 65 | 66 | duk_put_prop_string(ctx, -2, "WDG"); 67 | } 68 | -------------------------------------------------------------------------------- /engine/duktape_engine/addons/libjs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | #ifndef __LIBJS_H 5 | #define __LIBJS_H 6 | 7 | #include 8 | #include 9 | 10 | #ifdef JSE_HIGHLEVEL_JSAPI 11 | 12 | typedef struct { 13 | char *name; 14 | char *content; 15 | }libjs_entry_t; 16 | 17 | extern libjs_entry_t LIBJS_ENTRIES[]; 18 | extern int libjs_num; 19 | 20 | #endif /* JSE_HIGHLEVEL_JSAPI */ 21 | #endif /* __LIBJS_H */ -------------------------------------------------------------------------------- /engine/duktape_engine/addons/utils/ui/module_ui.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "amp_system.h" 11 | #include "amp_network.h" 12 | #include "amp_defines.h" 13 | #include "amp_network.h" 14 | #include "amp_task.h" 15 | #include "be_inl.h" 16 | 17 | #define MOD_STR "UI" 18 | 19 | char g_app_path[128]; 20 | extern void amp_page_changed_set(void); 21 | 22 | duk_ret_t native_ui_redirect(duk_context *ctx) 23 | { 24 | char *path; 25 | if (!duk_is_string(ctx, 0)) { 26 | amp_warn(MOD_STR, "invalid parameter\n"); 27 | goto done; 28 | } 29 | 30 | path = duk_get_string(ctx, 0); 31 | if (path != NULL) { 32 | memset(&g_app_path[0], 0, sizeof(g_app_path)); 33 | snprintf(&g_app_path[0],128,"%s",path); 34 | amp_page_changed_set(); 35 | } 36 | 37 | amp_debug(MOD_STR, "native_ui_redirect success"); 38 | 39 | done: 40 | return 1; 41 | } 42 | 43 | void module_ui_register(void) 44 | { 45 | duk_context *ctx = be_get_context(); 46 | duk_push_object(ctx); 47 | 48 | duk_push_c_function(ctx, native_ui_redirect, 1); 49 | duk_put_prop_string(ctx, -2, "redirectTo"); 50 | 51 | duk_put_prop_string(ctx, -2, "UI"); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /engine/duktape_engine/addons/utils/ui/module_vm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "amp_system.h" 11 | #include "amp_network.h" 12 | #include "amp_defines.h" 13 | #include "amp_network.h" 14 | #include "amp_task.h" 15 | #include "be_inl.h" 16 | 17 | #define MOD_STR "MODEL" 18 | 19 | duk_ret_t native_model_setdata(duk_context *ctx); 20 | 21 | void module_vm_register(void) 22 | { 23 | duk_context *ctx = be_get_context(); 24 | duk_push_object(ctx); 25 | 26 | duk_push_c_function(ctx, native_model_setdata, 1); 27 | duk_put_prop_string(ctx, -2, "setData"); 28 | 29 | duk_put_prop_string(ctx, -2, "VM"); 30 | } 31 | -------------------------------------------------------------------------------- /engine/duktape_engine/repl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __AMP_REPL_H 6 | #define __AMP_REPL_H 7 | 8 | #include 9 | #include "duktape/duktape.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #define REPL_OK 0 16 | #define REPL_ERR_NOMEM -10000 17 | #define REPL_ERR_DENIED -10001 18 | #define REPL_ERR_INVALID -10002 19 | #define REPL_ERR_BADCMD -10003 20 | #define REPL_ERR_SYNTAX -10004 21 | 22 | /* repl prompt tag */ 23 | #ifndef AMP_REPL_PROMPT 24 | #define REPL_PROMPT "amp > " 25 | #else 26 | #define REPL_PROMPT AMP_REPL_PROMPT 27 | #endif 28 | 29 | /* repl port */ 30 | #ifndef AMP_REPL_STDIO 31 | #define STDIO_UART 0 32 | #else 33 | #define STDIO_UART AMP_REPL_STDIO 34 | #endif 35 | 36 | /* repl port bandrate */ 37 | #ifndef AMP_REPL_STDIO_BANDRATE 38 | #define STDIO_UART_BANDRATE 115200 39 | #else 40 | #define STDIO_UART_BANDRATE AMP_REPL_STDIO_BANDRATE 41 | #endif 42 | 43 | /* repl task stack size */ 44 | #ifndef AMP_REPL_STACK_SIZE 45 | #define REPL_STACK_SIZE 1024 46 | #else 47 | #define REPL_STACK_SIZE AMP_REPL_STACK_SIZE 48 | #endif 49 | 50 | #define REPL_INBUF_SIZE 256 51 | #define REPL_OUTBUF_SIZE 1024 52 | 53 | int32_t repl_printf(const char *buffer, ...); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif /* __AMP_REPL_H */ -------------------------------------------------------------------------------- /engine/duktape_engine/startup/app_entry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __APP_ENTRY_H 6 | #define __APP_ENTRY_H 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | typedef struct { 13 | /* options object */ 14 | int object; 15 | /* ref of globalData */ 16 | int global_data; 17 | /* ref of onLaunch() */ 18 | int on_launch; 19 | /* ref of onError() */ 20 | int on_error; 21 | /* ref of onExit() */ 22 | int on_exit; 23 | }app_options_t; 24 | 25 | extern void app_entry_register(void); 26 | extern void app_entry(void* data); 27 | 28 | #endif /* __APP_ENTRY_H */ -------------------------------------------------------------------------------- /engine/duktape_engine/startup/page_entry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef __PAGE_ENTRY_H 6 | #define __PAGE_ENTRY_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include "infra_list.h" 12 | #include "render.h" 13 | 14 | extern void page_list_init(void); 15 | extern void page_list_add(const char *route); 16 | extern void page_list_dump(void); 17 | extern void page_list_free(void); 18 | extern void page_entry_register(void); 19 | extern void page_entry(void *para); 20 | extern void page_exit(void *para); 21 | extern void page_update(void *para); 22 | 23 | #endif /* __PAGE_ENTRY_H */ 24 | -------------------------------------------------------------------------------- /engine/lite_engine/addons/timer/module_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef MODULE_TIMER_H 6 | #define MODULE_TIMER_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /** 13 | * register the add-on of RTC module 14 | * 15 | * @return void 16 | */ 17 | be_jse_symbol_t *timers_module_handle_cb(be_jse_vm_ctx_t *execInfo, 18 | be_jse_symbol_t *var, 19 | const char *name); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif /* MODULE_TIMER_H */ -------------------------------------------------------------------------------- /engine/lite_engine/include/be.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef BE_H 6 | #define BE_H 7 | 8 | #include "be_types.h" 9 | #include "be_utils.h" 10 | #include "be_executor.h" 11 | #include "be_symbol.h" 12 | 13 | #endif /* BE_H */ 14 | -------------------------------------------------------------------------------- /engine/lite_engine/include/be_addon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef BE_ADDON_H 6 | #define BE_ADDON_H 7 | 8 | #include "be.h" 9 | 10 | void module_builtin_load(void); 11 | void module_process_load(void); 12 | void module_wifi_register(void); 13 | /* 14 | * JS MQTT Class 15 | * 16 | * API: 17 | * MQTT.start(config, callback) 18 | * MQTT.subscribe("reply", function(message){}); 19 | * MQTT.unsubscribe("reply"); 20 | * MQTT.publish(topic, payload); 21 | * 22 | * Event: 23 | */ 24 | void module_mqtt_register(void); 25 | void module_adc_register(void); 26 | void module_dac_register(void); 27 | void module_gpio_register(void); 28 | void module_i2c_register(void); 29 | void module_ir_register(void); 30 | void module_lcd_register(void); 31 | void module_pwm_register(void); 32 | void module_rtc_register(void); 33 | void module_uart_register(void); 34 | void module_wdg_register(void); 35 | void module_http_register(void); 36 | void module_net_register(void); 37 | void module_udp_register(void); 38 | void module_fs_register(void); 39 | void module_miio_register(void); 40 | 41 | #endif /* BE_ADDON_H */ 42 | -------------------------------------------------------------------------------- /engine/lite_engine/include/be_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef BE_API_H 6 | #define BE_API_H 7 | 8 | #include "amp_defines.h" 9 | #include "be.h" 10 | 11 | typedef be_jse_symbol_t *(*BE_JSE_FUNCTION_EXECUTE_CB)( 12 | be_jse_vm_ctx_t *execInfo, be_jse_symbol_t *a, const char *name); 13 | 14 | be_jse_symbol_t *handle_function_call(be_jse_vm_ctx_t *execInfo, 15 | be_jse_symbol_t *a, const char *name); 16 | 17 | /* 18 | * 19 | * get JSEngine executor object 20 | * 21 | */ 22 | be_jse_executor_ctx_t *jsengine_get_executor(void); 23 | 24 | /* 25 | register custom JS Object, call after jsengine_init(). 26 | */ 27 | be_jse_node_t jsengine_native_object_register(const char *objectName); 28 | 29 | /* 30 | register custom JS native function. 31 | */ 32 | void jsengine_native_function_register(BE_JSE_FUNCTION_EXECUTE_CB extension); 33 | 34 | void jsengine_modules_register(BE_JSE_FUNCTION_EXECUTE_CB extension); 35 | 36 | /* 37 | void bone_engine_log(const char* file, const char* tag, 38 | int level, int line, const char* func, 39 | const char* format, ...); 40 | 41 | void bone_engine_set_log(BE_JSE_FUNCTION_LOG_CB cb); */ 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* BE_API_H */ 48 | -------------------------------------------------------------------------------- /engine/lite_engine/include/be_feature.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | /* 6 | * be_feature.h 7 | * 8 | * JavaScript feature macros 9 | * 10 | */ 11 | 12 | #ifndef BE_FEATURE_H 13 | #define BE_FEATURE_H 14 | 15 | #define USE_GLOBAL 16 | #define USE_INTEGER 17 | #define USE_MATH 18 | #define USE_JSON 19 | #define USE_STRING 20 | #define USE_ARRAY 21 | 22 | #define USE_PROCESS 23 | #define USE_MODULES 24 | 25 | /* #define BE_JSE_SILENT */ 26 | #ifdef JSE_ENGINE_LITE 27 | #define DUMP_SYMBL_USAGE 28 | #endif 29 | 30 | #define TRACE_JSE_INFO 31 | 32 | #endif /* BE_FEATURE_H */ 33 | -------------------------------------------------------------------------------- /engine/lite_engine/include/be_global.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef BE_GLOBAL_H 6 | #define BE_GLOBAL_H 7 | 8 | #include "be_feature.h" 9 | 10 | #define BE_JSE_SYMBOL_DATA_STRING_LEN 8 11 | #define BE_JSE_SYMBOL_DATA_STRING_MAX_LEN \ 12 | (BE_JSE_SYMBOL_DATA_STRING_LEN + sizeof(be_jse_node_t) * 3) 13 | #define BE_JSE_SYMBOL_STRING_OP_BUFFER_SIZE 256 14 | #define MAX_TOKEN_LENGTH 64 15 | #define BE_JSE_ERROR_BUF_SIZE 64 16 | #define BE_JSE_ERROR_TOKEN_BUF_SIZE 16 17 | 18 | #define BE_JSE_PARSE_MAX_SCOPES 32 19 | #define BE_JSE_PARSE_MAX_LOOPS 8192 20 | 21 | #define BE_JSE_PARSE_RETURN_VAR "return" 22 | #define BE_JSE_PARSE_THIS_OBJ "this" 23 | #define BE_JSE_PARSE_PROTOTYPE_CLASS "prototype" 24 | #define BE_JSE_PARSE_FUNCTION_CODE_NAME "#code#" 25 | #define BE_JSE_PARSE_FUNCTION_SCOPE_NAME "#scope#" 26 | #define BE_JSE_PARSE_MODULE_NAME "Modules" 27 | 28 | /* symbol table allocation, static or dynamic */ 29 | 30 | /* symbol table resizable */ 31 | #define RESIZABLE_JSE_SYMBOL_TABLE 1 32 | 33 | /* set symbol table size */ 34 | /* #define BE_JSE_SYMBOL_TABLE_SIZE 500 */ 35 | 36 | #define BE_JSE_SYMBOL_APPEND_STR_MAX_LEN (0x7FFFFFFF) 37 | 38 | #define BE_JSE_FUNC_UNHANDLED ((be_jse_symbol_t*)-1) 39 | 40 | #define BE_JSE_LOCK_SHIFT 8 41 | #define BE_JSE_LOCK_MAX 15 42 | #define BE_JSE_STRING_LEN_SHIFT 12 43 | #define BE_JSE_STRING_LEN_MAX 15 44 | 45 | #define BE_JSE_MAX_MODULES 60 46 | 47 | #define PACKED_FLAGS __attribute__((__packed__)) 48 | #define NO_INLINE __attribute__((noinline)) 49 | 50 | /* #define BE_JSE_SILENT */ 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* BE_GLOBAL_H */ 57 | -------------------------------------------------------------------------------- /engine/lite_engine/include/be_lex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | /* 6 | * be_lex.h 7 | * 8 | * JS lexical analyzer 9 | * supported lexer in be_lexer_token_type_e 10 | * 11 | */ 12 | 13 | #ifndef BE_LEX_H 14 | #define BE_LEX_H 15 | 16 | #include "be.h" 17 | #include "be_types.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /* lexer initialization */ 24 | void be_jse_lexer_init(be_jse_lexer_ctx_t *lex, const char *src, int startPos, 25 | int endPos); 26 | 27 | /* for analysis conditional variable in for/while */ 28 | void be_jse_lexer_init2(be_jse_lexer_ctx_t *lex, be_jse_lexer_ctx_t *initFrom, 29 | int startPos); 30 | void be_jse_lexer_deinit(be_jse_lexer_ctx_t *lex); 31 | void be_jse_lexer_reset(be_jse_lexer_ctx_t *lex); 32 | 33 | /* char operation */ 34 | bool lexer_token_cmp(be_jse_lexer_ctx_t *lex, int expected_token); 35 | char *lexer_get_token(be_jse_lexer_ctx_t *lex); 36 | void lexer_seekto_char(be_jse_lexer_ctx_t *lex, int seekToChar); 37 | void lexer_get_next_char(be_jse_lexer_ctx_t *lex); 38 | 39 | /* convert token to string, for debugging! */ 40 | void lexer_token_to_str(int token, char *str, size_t len); 41 | void lexer_dump_line_and_col(be_jse_lexer_ctx_t *lex, int charPos, int *line, 42 | int *col); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* BE_LEX_H */ 49 | -------------------------------------------------------------------------------- /engine/lite_engine/include/be_module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef BE_MODULE_H 6 | #define BE_MODULE_H 7 | 8 | #include "amp_defines.h" 9 | #include "be.h" 10 | #include "be_api.h" 11 | 12 | #ifdef SUPPORT_NODE_MODELES 13 | 14 | 15 | typedef struct { 16 | char* dirname; 17 | struct be_list_head lst; 18 | } BE_JSE_DIRNAME_s; 19 | 20 | struct be_list_head* bone_engine_dirname_get_head(void); 21 | /* get dirname */ 22 | BE_JSE_DIRNAME_s* bone_engine_dirname_get(void); 23 | /* push dirname */ 24 | void bone_engine_dirname_push(BE_JSE_DIRNAME_s* dirPtr); 25 | /* pop and delete dirname */ 26 | void bone_engine_dirname_pop_del(void); 27 | #endif 28 | 29 | void be_jse_module_load(const char* moduleName, 30 | BE_JSE_FUNCTION_EXECUTE_CB extension); 31 | 32 | #endif /* BE_MODULE_H */ 33 | -------------------------------------------------------------------------------- /engine/lite_engine/include/be_native_addon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | /* 6 | * the header file for jse native addon module 7 | */ 8 | 9 | #ifndef BE_NATIVE_ADDON_H 10 | #define BE_NATIVE_ADDON_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /* functions declare */ 17 | void module_wifi_register(void); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* BE_NATIVE_ADDON_H */ 24 | -------------------------------------------------------------------------------- /entry/amp_entry.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | extern int amp_main(); 9 | 10 | int main(void) 11 | { 12 | amp_main(); 13 | } 14 | -------------------------------------------------------------------------------- /example/adc.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var adc = require('adc'); 6 | 7 | // voltage 8 | var vol = adc.open({ 9 | id: 'ADC0' 10 | }); 11 | 12 | var value; 13 | // read voltage 14 | setInterval(function() { 15 | // read adc value 16 | value = vol.readValue(); 17 | 18 | console.log('adc value is ' + value); 19 | }, 1000); 20 | 21 | // vol.close(); -------------------------------------------------------------------------------- /example/fs.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var fs = require('fs'); 6 | 7 | var path = './test.data'; 8 | var file_content = 'this is amp fs test file'; 9 | 10 | // write file 11 | fs.writeSync(path, file_content); 12 | 13 | // read file 14 | var data = fs.readSync(path); 15 | console.log('fs read: ' + data); 16 | 17 | fs.unlinkSync(path); -------------------------------------------------------------------------------- /example/gpio.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var gpio = require('gpio'); 6 | 7 | var led = gpio.open({ 8 | id: 'led', 9 | success: function() { 10 | console.log('gpio: open led success') 11 | }, 12 | fail: function() { 13 | console.log('gpio: open led failed') 14 | } 15 | }); 16 | 17 | var key = gpio.open({ 18 | id: 'key', 19 | success: function() { 20 | console.log('gpio: open key success') 21 | }, 22 | fail: function() { 23 | console.log('gpio: open key failed') 24 | } 25 | }); 26 | 27 | var vol = 0; 28 | var irqCnt = 0; 29 | key.onIRQ({ 30 | cb: function() { 31 | irqCnt = irqCnt + 1; 32 | console.log('gpio: irq count ' + irqCnt); 33 | vol = 1 - vol; 34 | led.writeValue(vol); 35 | console.log('gpio: led set value ' + vol); 36 | 37 | vol = led.readValue(); 38 | console.log('gpio: led get value ' + vol); 39 | } 40 | }); 41 | 42 | console.log('gpio: ready to test') 43 | -------------------------------------------------------------------------------- /example/http.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | console.log('http: testing http...'); 6 | 7 | var http = require('http'); 8 | if (!(http && http.request)) { 9 | throw new Error("http: [failed] require(\'http\')"); 10 | } 11 | 12 | console.log('http: [success] require(\'http\')'); 13 | 14 | 15 | var request_url = 'http://appengine.oss-cn-hangzhou.aliyuncs.com/httpTest.txt'; 16 | var defaultMessage = 'this is AMP HTTP test file'; 17 | 18 | http.request({ 19 | url: request_url, 20 | method: 'GET', 21 | headers: { 22 | 'content-type':'application/json' 23 | }, 24 | success: function (data) { 25 | console.log('http: [debug] receive data is ' + data); 26 | if(data === defaultMessage) { 27 | console.log('http: [success] http.request'); 28 | } 29 | } 30 | }); -------------------------------------------------------------------------------- /example/i2c.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var i2c = require('i2c'); 6 | 7 | var memaddr = 0x18 8 | var msgbuf = [0x10, 0xee] 9 | // led灯 10 | var sensor = i2c.open({ 11 | id: 'I2C0', 12 | success: function() { 13 | console.log('open i2c success') 14 | }, 15 | fail: function() { 16 | console.log('open i2c failed') 17 | } 18 | }); 19 | 20 | sensor.write(msgbuf) 21 | var value = sensor.read(2) 22 | 23 | console.log('sensor value is ' + value) 24 | 25 | sensor.writeMem(memaddr, msgbuf) 26 | 27 | 28 | var vol = sensor.readMem(memaddr, 2) 29 | console.log('sensor read mem vol is ' + vol) 30 | 31 | 32 | sensor.close(); -------------------------------------------------------------------------------- /example/mqtt.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var mqtt = require('mqtt'); 6 | 7 | function ArrayToString(fileData) { 8 | var dataString = ""; 9 | for (var i = 0; i < fileData.length; i++) { 10 | dataString += String.fromCharCode(fileData[i]); 11 | } 12 | 13 | return dataString; 14 | } 15 | 16 | function onConnect() { 17 | // subscribe 18 | mqttClient.subscribe({ 19 | topic: '/hello', 20 | success: function() { 21 | console.log('subscribe [/hello] success'); 22 | } 23 | }); 24 | 25 | // publish 26 | setInterval(function () { 27 | mqttClient.publish({ 28 | topic: '/hello', 29 | message: 'this is AMP mqtt test', 30 | success: function() { 31 | console.log('publish [/hello] success'); 32 | } 33 | }); 34 | }, 2 * 1000); 35 | } 36 | 37 | // create mqtt client 38 | var mqttClient = mqtt.createClient({ 39 | host: 'mqtt.eclipse.org', 40 | port: 1883, 41 | username: 'aiot', 42 | password: '123', 43 | success: function() { 44 | console.log('mqtt connected'); 45 | }, 46 | fail: function() { 47 | console.log('mqtt connect failed'); 48 | } 49 | }); 50 | 51 | mqttClient.on('connect', function() { 52 | console.log('mqtt connected'); 53 | onConnect(); 54 | }); 55 | 56 | mqttClient.on('message', function(topic, payload) { 57 | console.log('[' + topic + '] message: ' + ArrayToString(payload)); 58 | }); -------------------------------------------------------------------------------- /example/network.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var network = require('network'); 6 | 7 | var net = network.openNetWorkClient(); 8 | 9 | function netinfo_print(){ 10 | var info = net.getInfo(); 11 | /* imsi 国际移动用户识别码 */ 12 | console.log('net imsi is: ' + info.imsi); 13 | 14 | /* imei 国际移动设备识别码 */ 15 | console.log('net imei is: ' + info.imei); 16 | 17 | /* iccid 集成电路卡识别码 */ 18 | console.log('net iccid is: ' + info.iccid); 19 | 20 | /* cid 基站编号 */ 21 | console.log('net cid is: ' + info.cid); 22 | 23 | /* lac 位置区域码 */ 24 | console.log('net lac is: ' + info.lac); 25 | 26 | /* mcc 移动国家代码(中国的为460 */ 27 | console.log('net mcc is: ' + info.mcc); 28 | 29 | /* mnc 移动网络号码(中国移动为00,中国联通为01) */ 30 | console.log('net mnc is: ' + info.mnc); 31 | 32 | /* rssi 接收的信号强度值 */ 33 | console.log('net rssi is: ' + info.rssi); 34 | } 35 | 36 | 37 | /** 获取网络类型 38 | * 目前支持两种类型:wifi cellular(蜂窝网) 39 | */ 40 | var type = net.getType(); 41 | console.log('net type is: ' + type); 42 | 43 | /** 获取网络状态 44 | * 目前支持两种状态:connect disconnect(蜂窝网) 45 | */ 46 | var status = net.getStatus(); 47 | console.log('net status is: ' + status); 48 | 49 | if (status == 'connect') { 50 | netinfo_print(); 51 | } else { 52 | net.on('connect', function() { 53 | netinfo_print(); 54 | }) 55 | } 56 | 57 | net.on('disconnect', function(){ 58 | console.log('device is disconnect'); 59 | }); -------------------------------------------------------------------------------- /example/promise.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | console.log(Promise); 6 | 7 | function test_setTimeout() { 8 | return new Promise(function (resolve, reject) { 9 | console.log('=================setTimeout'); 10 | setTimeout(function () { 11 | console.log('=================setTimeout---------------done'); 12 | resolve(""); 13 | }, 1000); 14 | }); 15 | } 16 | 17 | function test_http() { 18 | return new Promise(function (resolve, reject) { 19 | console.log('=================http'); 20 | HTTP.request("http://appengine.oss-cn-hangzhou.aliyuncs.com/httpTest.txt", function(data){ 21 | resolve(data); 22 | }); 23 | }); 24 | } 25 | 26 | test_setTimeout() 27 | .then(function(){ 28 | // setInterval异步测试返回 29 | return test_http(); 30 | }) 31 | .then(function(data){ 32 | // http异步测试返回 33 | console.log("接收到 HTTP 数据:", data); 34 | }); -------------------------------------------------------------------------------- /example/pwm.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var pwm = require('pwm'); 6 | 7 | var pwm1 = pwm.open({ 8 | id: 'pwm1', 9 | success: function() { 10 | console.log('pwm: open pwm success') 11 | }, 12 | fail: function() { 13 | console.log('pwm: open pwm failed') 14 | } 15 | }); 16 | 17 | var freq = pwm1.getOption().freq 18 | var duty = pwm1.getOption().duty 19 | 20 | console.log('pwm: pwm default config freq is ' + freq + ' duty is ' + duty) 21 | 22 | duty = 0; 23 | var cnt = 10; 24 | var loop = 10; 25 | var timer = setInterval(function(){ 26 | if (duty >= 100) { 27 | duty = 0; 28 | } 29 | duty = duty + 20; 30 | 31 | pwm1.setOption({ 32 | freq: 100, 33 | duty: duty 34 | }) 35 | 36 | console.log('pwm: pwm test count ' + cnt) 37 | cnt = cnt - 1; 38 | if (cnt == 0) { 39 | pwm1.close(); 40 | console.log('pwm: pwm test finish ') 41 | loop--; 42 | if (loop == 0) { 43 | clearInterval(timer); 44 | } 45 | else { 46 | pwm1 = pwm.open({ 47 | id: 'pwm1', 48 | success: function() { 49 | console.log('pwm: open pwm success') 50 | }, 51 | fail: function() { 52 | console.log('pwm: open pwm failed') 53 | } 54 | }); 55 | } 56 | 57 | cnt = 10; 58 | } 59 | 60 | }, 1000) 61 | -------------------------------------------------------------------------------- /example/rtc.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var rtc = require('rtc'); 6 | 7 | rtc.start(); 8 | 9 | var current_time = rtc.getTime(); 10 | console.log('rtc1: current time is ' + current_time); 11 | 12 | var my_date = new Date(); 13 | my_date.setFullYear(2008,7,9); 14 | 15 | rtc.setTime(my_date); 16 | 17 | console.log('Date is ' + my_date.toUTCString()); 18 | 19 | current_time = rtc.getTime(); 20 | console.log('rtc2: current time is ' + current_time); 21 | 22 | rtc.close(); -------------------------------------------------------------------------------- /example/spi.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var spi = require('spi'); 6 | 7 | var msgbuf = [0x10, 0xee] 8 | // led灯 9 | var sensor = spi.open({ 10 | id: 'spi', 11 | success: function() { 12 | console.log('open spi success') 13 | }, 14 | fail: function() { 15 | console.log('open spi failed') 16 | } 17 | }); 18 | 19 | sensor.write(msgbuf) 20 | var value = sensor.read(2) 21 | 22 | console.log('sensor value is ' + value) 23 | 24 | 25 | sensor.close(); -------------------------------------------------------------------------------- /example/system.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | console.log('system version is: ' + system.version()) 6 | console.log('system platform is: ' + system.platform()) 7 | console.log('system uptime is: ' + system.uptime()) 8 | console.log('system heapTotal is: ' + system.memory().heapTotal) 9 | console.log('system heapUsed is: ' + system.memory().heapUsed) 10 | -------------------------------------------------------------------------------- /example/tcp.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var tcp = require('tcp'); 6 | 7 | var tcpServerHost = ''; 8 | var tcpServerPort = 0; 9 | 10 | function onConnect() { 11 | tcpClient.send({ 12 | message: 'hello, this is tcp client test', 13 | success: function() { 14 | console.log('tcp send success'); 15 | }, 16 | fail: function() { 17 | console.log('tcp send failed'); 18 | } 19 | }); 20 | } 21 | var tcpClient = tcp.createClient({ 22 | host: tcpServerHost, 23 | port: tcpServerPort, 24 | success: function() { 25 | console.log('tcp client connect success'); 26 | }, 27 | fail: function() { 28 | console.log('tcp client connect failed'); 29 | } 30 | }); 31 | 32 | tcpClient.on('message', function(data) { 33 | console.log('tcp receive data: ' + data); 34 | tcpClient.close(); 35 | }); 36 | 37 | tcpClient.on('connect', function() { 38 | console.log('tcp client connected'); 39 | onConnect(); 40 | }); 41 | 42 | tcpClient.on('close', function() { 43 | console.log('tcp client closed'); 44 | }); 45 | 46 | tcpClient.on('error', function(err) { 47 | console.log('tcp client error: ' + err); 48 | }); -------------------------------------------------------------------------------- /example/uart.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var uart = require('uart'); 6 | 7 | var msgbuf = 'this is amp uart test' 8 | // led灯 9 | var serial = uart.open({ 10 | id: 'serial', 11 | success: function() { 12 | console.log('open spi success') 13 | }, 14 | fail: function() { 15 | console.log('open spi failed') 16 | } 17 | }); 18 | 19 | serial.write(msgbuf) 20 | var value = serial.read() 21 | 22 | console.log('sensor value is ' + value) 23 | 24 | serial.on('data', function(len, data) { 25 | console.log('uart receive data len is : ' + len + ' data is: ' + data); 26 | }) 27 | 28 | serial.close(); -------------------------------------------------------------------------------- /example/udp.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var udp = require('udp'); 6 | 7 | var udpSocket = udp.createSocket(); 8 | 9 | function arrayToString(fileData) { 10 | var dataString = ""; 11 | for (var i = 0; i < fileData.length; i++) { 12 | dataString += String.fromCharCode(fileData[i]); 13 | } 14 | 15 | return dataString; 16 | } 17 | 18 | udpSocket.on('message', function(data, rinfo) { 19 | console.log('receive data from ' + rinfo.host + ' port: ' + rinfo.port); 20 | console.log('udp socket just receive data is: ' + arrayToString(data)); 21 | udpClient.close(); 22 | }); 23 | 24 | udpSocket.on('close', function() { 25 | console.log('udp close'); 26 | }); 27 | 28 | udpSocket.on('error', function(err) { 29 | console.log('udp error ' + err); 30 | }); 31 | 32 | setInterval(function() { 33 | udpSocket.send({ 34 | address: '127.0.0.1', 35 | port: 50000, 36 | message: 'hello, this is amp', 37 | success: function() { 38 | console.log('send success'); 39 | } 40 | }); 41 | }, 2000); 42 | 43 | 44 | // bind port & start to receive message 45 | udpSocket.bind(); -------------------------------------------------------------------------------- /example/wdg.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var dog = require('wdg'); 6 | 7 | // led灯 8 | dog.start(2000); 9 | 10 | dog.feed(); 11 | 12 | dog.stop(); -------------------------------------------------------------------------------- /libjs/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "es2015" 4 | ], 5 | "plugins": [] 6 | } -------------------------------------------------------------------------------- /libjs/README.md: -------------------------------------------------------------------------------- 1 | ### libjs 2 | 把native的JS接口封装成更人性化更贴近前端开发的JSAPI 3 | 4 | ### 使用 5 | 6 | **安装依赖** 7 | ```js 8 | npm install 9 | ``` 10 | 11 | **生成libjs c源码** 12 | > 进行了babel转译(ES6 => ES5)和minify操作。生成的文件为`../engine/duktape_engine/addons/libjs.c`。 13 | 14 | ```js 15 | npm run build 16 | ``` 17 | 18 | **监测文件改动** 19 | ```js 20 | npm run watch 21 | ``` 22 | 23 | ### 参考资料 24 | * babel转换工具(web):https://babeljs.io/repl 25 | * js minify 工具(web):https://jsminify.org/ 26 | -------------------------------------------------------------------------------- /libjs/build.js: -------------------------------------------------------------------------------- 1 | const watch = require('node-watch'); 2 | const minify = require('@node-minify/core'); 3 | const babelMinify = require('@node-minify/babel-minify'); 4 | const fse = require('fs-extra'); 5 | 6 | let watchFile = false; 7 | process.argv.forEach((val, index) => { 8 | if(val === '--watch'){ 9 | watchFile = true; 10 | } 11 | }); 12 | 13 | fse.ensureDirSync('../build/bin/node_modules'); 14 | 15 | minify({ 16 | compressor: babelMinify, 17 | input: 'lib/*.js', 18 | output: '../build/bin/node_modules/$1.js', 19 | options: { 20 | babelrc: '.babelrc' 21 | }, 22 | callback: function(err, min) { 23 | console.log('minify updated'); 24 | } 25 | }); 26 | 27 | if(watchFile) { 28 | console.log('watching...'); 29 | watch('./lib', { recursive: true }, function(evt, name) { 30 | console.log('%s changed.', name); 31 | minify({ 32 | compressor: babelMinify, 33 | input: 'lib/*.js', 34 | output: '../build/bin/node_modules/$1.js', 35 | options: { 36 | babelrc: '.babelrc' 37 | }, 38 | callback: function(err, min) { 39 | console.log('minify updated'); 40 | } 41 | }); 42 | }); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /libjs/init/process.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | globalThis = new Function('return this;')(); 3 | globalThis.process = system; 4 | })(); -------------------------------------------------------------------------------- /libjs/lib/adc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | class HW_ADC { 4 | constructor(options) { 5 | if (!options || !options.id) { 6 | throw new Error('options is invalid'); 7 | } 8 | 9 | this.options = { 10 | id: options.id 11 | }; 12 | 13 | this.success = options.success || function(){}; 14 | this.fail = options.fail || function(){}; 15 | this._open(); 16 | } 17 | 18 | _open() { 19 | this.adcInstance = __native.ADC.open(this.options.id); 20 | if (!this.adcInstance) { 21 | this.fail(); 22 | return; 23 | } 24 | this.success(); 25 | } 26 | 27 | readValue() { 28 | if (!this.adcInstance) { 29 | throw new Error('adc not init'); 30 | } 31 | 32 | return __native.ADC.read(this.adcInstance); 33 | }; 34 | 35 | close() { 36 | if (!this.adcInstance) { 37 | throw new Error('adc not init'); 38 | } 39 | 40 | __native.ADC.close(this.adcInstance); 41 | }; 42 | } 43 | 44 | function open(options) { 45 | return new HW_ADC(options); 46 | } 47 | 48 | module.exports = { 49 | open, 50 | } -------------------------------------------------------------------------------- /libjs/lib/audio.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | class AudioSystem { 4 | play(source) { 5 | if (!source) { 6 | throw new Error('invalid params'); 7 | } 8 | return __native.Audio.play(source); 9 | }; 10 | 11 | pause() { 12 | return __native.Audio.pause(); 13 | }; 14 | 15 | resume() { 16 | return __native.Audio.resume(); 17 | }; 18 | 19 | stop() { 20 | return __native.Audio.stop(); 21 | }; 22 | 23 | volume(device, volume) { 24 | if (!device || !volume) { 25 | throw new Error('invalid params'); 26 | } 27 | return __native.Audio.volume(device, volume); 28 | }; 29 | 30 | setGain(gain) { 31 | if (!gain) { 32 | throw new Error('invalid params'); 33 | } 34 | return __native.Audio.setGain(gain); 35 | }; 36 | 37 | getGain() { 38 | return __native.Audio.getGain(); 39 | }; 40 | 41 | mute(state) { 42 | if (!state) { 43 | throw new Error('invalid params'); 44 | } 45 | return __native.Audio.mute(state); 46 | }; 47 | } 48 | 49 | function create() { 50 | return new AudioSystem(); 51 | } 52 | 53 | module.exports = { 54 | create, 55 | } -------------------------------------------------------------------------------- /libjs/lib/battery.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const EventEmitter = require('events'); 4 | 5 | module.exports = new class UTILS_Battery extends EventEmitter { 6 | constructor(){ 7 | super(); 8 | } 9 | 10 | getConnectState() { 11 | return __native.Battery.getConnectState(); 12 | } 13 | 14 | getVoltage() { 15 | return __native.Battery.getVoltage(); 16 | } 17 | 18 | getLevel() { 19 | return __native.Battery.getLevel(); 20 | } 21 | 22 | getTemperature() { 23 | return __native.Battery.getTemperature(); 24 | } 25 | } -------------------------------------------------------------------------------- /libjs/lib/can.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const EventEmitter = require('events'); 4 | 5 | class HW_CAN extends EventEmitter{ 6 | constructor(options) { 7 | super(); 8 | 9 | if (!options || !options.id) { 10 | throw new Error('options is invalid'); 11 | } 12 | this.options = { 13 | id: options.id 14 | }; 15 | 16 | this.success = options.success || function(){}; 17 | this.fail = options.fail || function(){}; 18 | this._open(); 19 | this._onData(); 20 | } 21 | 22 | _open() { 23 | this.canInstance = __native.CAN.open(this.options.id); 24 | if (!this.canInstance) { 25 | this.fail(); 26 | return; 27 | } 28 | this.success(); 29 | } 30 | 31 | receive() { 32 | if (!this.canInstance) { 33 | throw new Error('can not init'); 34 | } 35 | return __native.CAN.receive(this.canInstance); 36 | }; 37 | 38 | _onData() { 39 | if (!this.canInstance) { 40 | throw new Error("can not init"); 41 | } 42 | __native.CAN.receive(this.canInstance, function(type, id, data){ 43 | this.emit('data', type, id, data); 44 | }.bind(this)); 45 | }; 46 | 47 | send(txheader, data) { 48 | if (!this.canInstance || !data) { 49 | throw new Error('can not init or params is invalid'); 50 | } 51 | __native.CAN.send(this.canInstance, txheader, data); 52 | }; 53 | 54 | close() { 55 | if (!this.canInstance) { 56 | throw new Error('can not init'); 57 | } 58 | __native.CAN.close(this.canInstance); 59 | }; 60 | } 61 | 62 | function open(options) { 63 | return new HW_CAN(options); 64 | } 65 | 66 | module.exports = { 67 | open, 68 | } -------------------------------------------------------------------------------- /libjs/lib/charger.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const EventEmitter = require('events'); 4 | 5 | module.exports = new class UTILS_Charger extends EventEmitter { 6 | constructor(){ 7 | super(); 8 | this._onConnect(); 9 | } 10 | 11 | _onConnect() { 12 | __native.Charger.onConnect(function(state) { 13 | this.emit('connect', state); 14 | }.bind(this)); 15 | }; 16 | 17 | getState() { 18 | return __native.Charger.getState(); 19 | } 20 | 21 | getConnectState() { 22 | return __native.Charger.getConnectState(); 23 | } 24 | 25 | getCurrent() { 26 | return __native.Charger.getCurrent(); 27 | } 28 | 29 | switch(onoff) { 30 | return __native.Charger.switch(onoff); 31 | } 32 | } -------------------------------------------------------------------------------- /libjs/lib/dac.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | class HW_DAC { 4 | constructor(options) { 5 | if (!options || !options.id) { 6 | throw new Error('options is invalid'); 7 | } 8 | this.options = { 9 | id: options.id 10 | }; 11 | 12 | this.success = options.success || function(){}; 13 | this.fail = options.fail || function(){}; 14 | this._open(); 15 | } 16 | 17 | _open() { 18 | this.dacInstance = __native.DAC.open(this.options.id); 19 | if (!this.dacInstance) { 20 | this.fail(); 21 | return; 22 | } 23 | this.success(); 24 | } 25 | 26 | readValue() { 27 | if (!this.dacInstance) { 28 | throw new Error('dac not init'); 29 | } 30 | return __native.DAC.getVol(this.dacInstance); 31 | }; 32 | 33 | writeValue(value) { 34 | if (!this.dacInstance || !value) { 35 | throw new Error('dac not init or params is invalid'); 36 | } 37 | __native.DAC.setVol(this.dacInstance, value); 38 | }; 39 | 40 | close() { 41 | if (!this.dacInstance) { 42 | throw new Error('dac not init'); 43 | } 44 | __native.DAC.close(this.dacInstance); 45 | }; 46 | } 47 | 48 | function open(options) { 49 | return new HW_DAC(options); 50 | } 51 | 52 | module.exports = { 53 | open, 54 | } -------------------------------------------------------------------------------- /libjs/lib/device.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var kv = require('kv'); 4 | function setDeviceInfo(pk, ps) { 5 | if (!pk || !ps) { 6 | throw new Error('params is invalid'); 7 | } 8 | 9 | var productkey_key = '_amp_internal_productkey'; 10 | var productsecret_key = '_amp_internal_productsecret'; 11 | 12 | kv.setStorageSync(productkey_key, pk); 13 | kv.setStorageSync(productsecret_key, ps); 14 | } 15 | 16 | function setToken(token) { 17 | if(!token) { 18 | throw new Error("invalid params"); 19 | } 20 | 21 | var token_key = '_amp_device_token'; 22 | kv.setStorageSync(token_key, token); 23 | } 24 | 25 | module.exports = { 26 | setDeviceInfo, 27 | setToken 28 | } -------------------------------------------------------------------------------- /libjs/lib/fs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function writeSync(path, data, options) { 4 | if (!path || !data) { 5 | throw new Error('params is invalid'); 6 | } 7 | options = options || {flag: 'w'}; 8 | __native.FS.write(path, data, options); 9 | } 10 | 11 | function readSync(path) { 12 | if(!path) { 13 | throw new Error("invalid params"); 14 | } 15 | var content = __native.FS.read(path); 16 | if (!content) { 17 | throw 'file open error'; 18 | } 19 | 20 | return content; 21 | } 22 | 23 | function unlinkSync(path) { 24 | if(!path) { 25 | throw new Error("invalid params"); 26 | } 27 | __native.FS.delete(path); 28 | } 29 | 30 | module.exports = { 31 | writeSync, 32 | readSync, 33 | unlinkSync 34 | } -------------------------------------------------------------------------------- /libjs/lib/gpio.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | class HW_GPIO { 4 | constructor(options) { 5 | if (!options || !options.id) { 6 | throw new Error("options is invalid"); 7 | } 8 | this.options = { 9 | id: options.id 10 | }; 11 | 12 | this.success = options.success || function(){}; 13 | this.fail = options.fail || function(){}; 14 | this._open(); 15 | } 16 | 17 | _open() { 18 | this.gpioInstance = __native.GPIO.open(this.options.id); 19 | if (!this.gpioInstance) { 20 | this.fail(); 21 | return; 22 | } 23 | this.success(); 24 | } 25 | 26 | writeValue(level) { 27 | if (!this.gpioInstance) { 28 | throw new Error("gpio not init"); 29 | } 30 | __native.GPIO.write(this.gpioInstance, level); 31 | } 32 | 33 | toggle() { 34 | if (!this.gpioInstance) { 35 | throw new Error("gpio not init"); 36 | } 37 | __native.GPIO.toggle(this.gpioInstance); 38 | } 39 | 40 | onIRQ(options) { 41 | if (!this.gpioInstance || !options || !options.cb) { 42 | throw new Error("gpio not init or params is invalid"); 43 | } 44 | __native.GPIO.on(this.gpioInstance, options.cb); 45 | } 46 | 47 | readValue() { 48 | if (!this.gpioInstance) { 49 | throw new Error("gpio not init"); 50 | } 51 | return __native.GPIO.read(this.gpioInstance); 52 | }; 53 | 54 | close() { 55 | if (!this.gpioInstance) { 56 | throw new Error("gpio not init"); 57 | } 58 | __native.GPIO.close(this.gpioInstance); 59 | }; 60 | } 61 | 62 | function open(options) { 63 | return new HW_GPIO(options); 64 | } 65 | 66 | module.exports = { 67 | open, 68 | } -------------------------------------------------------------------------------- /libjs/lib/http.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = __native.HTTP; -------------------------------------------------------------------------------- /libjs/lib/keypad.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const EventEmitter = require('events'); 4 | 5 | module.exports = new class Keypad extends EventEmitter { 6 | constructor(){ 7 | super(); 8 | this._on(); 9 | } 10 | 11 | open() { 12 | return __native.Keypad.open(); 13 | }; 14 | 15 | close() { 16 | this.removeAllListeners('keypadEvent'); 17 | return __native.Keypad.close(); 18 | }; 19 | 20 | _on() { 21 | __native.Keypad.on(function(code, value) { 22 | this.emit('keypadEvent', code, value); 23 | }.bind(this)); 24 | }; 25 | 26 | } -------------------------------------------------------------------------------- /libjs/lib/kv.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = __native.KV; -------------------------------------------------------------------------------- /libjs/lib/location.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | class ADVANCED_LOCATION { 4 | constructor() {} 5 | 6 | getAccessApInfo() { 7 | var ap_info; 8 | ap_info = __native.LOCATION.accessedWifi(); 9 | return ap_info; 10 | } 11 | 12 | getScannedApInfo() { 13 | var ap_info; 14 | ap_info = __native.LOCATION.scannedWifi(); 15 | return ap_info; 16 | } 17 | 18 | getAccessedLbsInfo() { 19 | var lbs_info; 20 | lbs_info = __native.LOCATION.accessedLbs(); 21 | return lbs_info; 22 | } 23 | 24 | getNearLbsInfo() { 25 | var near_lbs_info; 26 | near_lbs_info = __native.LOCATION.nearbts(); 27 | return near_lbs_info; 28 | } 29 | 30 | } 31 | 32 | function open() { 33 | return new ADVANCED_LOCATION(); 34 | } 35 | 36 | module.exports = { 37 | open, 38 | } -------------------------------------------------------------------------------- /libjs/lib/pwm.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | class HW_PWM { 4 | constructor(options) { 5 | if (!options || !options.id) { 6 | throw new Error("options is invalid"); 7 | } 8 | this.options = { 9 | id: options.id 10 | }; 11 | 12 | this.success = options.success || function(){}; 13 | this.fail = options.fail || function(){}; 14 | this._open(); 15 | } 16 | 17 | _open() { 18 | this.pwmInstance = __native.PWM.open(this.options.id); 19 | if (!this.pwmInstance) { 20 | this.fail(); 21 | return; 22 | } 23 | this.success(); 24 | } 25 | 26 | set(options) { 27 | if (!this.pwmInstance || !options) { 28 | throw new Error("pwm not init or params is invalid"); 29 | } 30 | __native.PWM.setConfig(this.pwmInstance, options); 31 | }; 32 | 33 | get() { 34 | if (!this.pwmInstance) { 35 | throw new Error("pwm not init"); 36 | } 37 | return __native.PWM.getConfig(this.pwmInstance); 38 | }; 39 | 40 | close() { 41 | if (!this.pwmInstance) { 42 | throw new Error("pwm not init"); 43 | } 44 | __native.PWM.close(this.pwmInstance); 45 | }; 46 | } 47 | 48 | function open(options) { 49 | return new HW_PWM(options); 50 | } 51 | 52 | module.exports = { 53 | open, 54 | } -------------------------------------------------------------------------------- /libjs/lib/rtc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function start() { 4 | __native.RTC.open(); 5 | } 6 | 7 | function setTime(time) { 8 | if (!time) { 9 | throw new Error('params is invalid'); 10 | } 11 | 12 | if (!(time instanceof Date)) { 13 | throw new Error('params is invalid'); 14 | } 15 | 16 | var date = { 17 | year: time.getYear(), 18 | month: time.getMonth(), 19 | day: time.getDate(), 20 | hour: time.getHours(), 21 | minute: time.getMinutes(), 22 | second: time.getSeconds() 23 | } 24 | __native.RTC.setTime(date); 25 | } 26 | 27 | function getTime() { 28 | var time = __native.RTC.getTime(); 29 | console.log(time); 30 | return new Date(parseInt(time.year) + 1900, parseInt(time.month), parseInt(time.day), parseInt(time.hour), parseInt(time.minute), parseInt(time.second)); 31 | } 32 | 33 | function close() { 34 | __native.RTC.close(); 35 | } 36 | 37 | module.exports = { 38 | start, 39 | setTime, 40 | getTime, 41 | close 42 | } -------------------------------------------------------------------------------- /libjs/lib/spi.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | class HW_SPI { 4 | constructor(options) { 5 | if (!options || !options.id) { 6 | throw new Error("options is invalid"); 7 | } 8 | this.options = { 9 | id: options.id 10 | }; 11 | 12 | this.success = options.success || function(){}; 13 | this.fail = options.fail || function(){}; 14 | this._open(); 15 | } 16 | 17 | _open() { 18 | this.spiInstance = __native.SPI.open(this.options.id); 19 | if (!this.spiInstance) { 20 | this.fail(); 21 | return; 22 | } 23 | this.success(); 24 | } 25 | 26 | write(data) { 27 | if (!this.spiInstance || !data) { 28 | throw new Error("spi not init or params is invalid"); 29 | } 30 | __native.SPI.write(this.spiInstance, data); 31 | } 32 | 33 | read(bytes) { 34 | if (!this.spiInstance || !bytes) { 35 | throw new Error("spi not init or params is invalid"); 36 | } 37 | return __native.SPI.read(this.spiInstance, bytes); 38 | }; 39 | 40 | readWrite(sendData, bytes) { 41 | if (!this.spiInstance || !sendData ||!bytes) { 42 | throw new Error("spi not init or params is invalid"); 43 | } 44 | return __native.SPI.sendRecv(this.spiInstance, sendData, bytes); 45 | }; 46 | 47 | close() { 48 | if (!this.spiInstance) { 49 | throw new Error("spi not init"); 50 | } 51 | __native.SPI.close(this.spiInstance); 52 | }; 53 | } 54 | 55 | function open(options) { 56 | return new HW_SPI(options); 57 | } 58 | 59 | module.exports = { 60 | open, 61 | } -------------------------------------------------------------------------------- /libjs/lib/tts.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const EventEmitter = require('events'); 4 | 5 | module.exports = new class TTSSystem extends EventEmitter { 6 | constructor(){ 7 | super(); 8 | } 9 | 10 | play(content, encode) { 11 | if (!content) { 12 | throw new Error('invalid params'); 13 | } 14 | return __native.TTS.play(content, encode); 15 | }; 16 | 17 | stop() { 18 | return __native.TTS.stop(); 19 | }; 20 | 21 | getState() { 22 | return __native.TTS.getState(); 23 | }; 24 | 25 | setPitch(type) { 26 | if (!type) { 27 | throw new Error('invalid params'); 28 | } 29 | return __native.TTS.setPitch(type); 30 | }; 31 | 32 | setSpeed(speed) { 33 | if (!speed) { 34 | throw new Error('invalid params'); 35 | } 36 | return __native.TTS.setSpeed(speed); 37 | }; 38 | 39 | getSpeed() { 40 | return __native.TTS.getSpeed(); 41 | }; 42 | 43 | setVolume(volume) { 44 | if (!volume) { 45 | throw new Error('invalid params'); 46 | } 47 | return __native.TTS.setVolume(volume); 48 | }; 49 | 50 | getVolume() { 51 | return __native.TTS.getVolume(); 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /libjs/lib/ui.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = __native.UI; 4 | 5 | 6 | -------------------------------------------------------------------------------- /libjs/lib/und.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = __native.UND; -------------------------------------------------------------------------------- /libjs/lib/vm.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = __native.VM; -------------------------------------------------------------------------------- /libjs/lib/wdg.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function start(timeout) { 4 | if (!timeout) { 5 | throw new Error('params is invalid'); 6 | } 7 | __native.WDG.start(timeout); 8 | } 9 | 10 | function feed() { 11 | __native.WDG.feed(); 12 | } 13 | 14 | function stop() { 15 | __native.WDG.stop(); 16 | } 17 | 18 | module.exports = { 19 | start, 20 | feed, 21 | stop 22 | } -------------------------------------------------------------------------------- /libjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "build": "node ./generator.js" 4 | }, 5 | "devDependencies": { 6 | "@babel/core": "^7.9.0", 7 | "@babel/node": "^7.8.7", 8 | "babel-cli": "^6.26.0", 9 | "babel-preset-es2015": "^6.24.1" 10 | }, 11 | "dependencies": { 12 | "@node-minify/babel-minify": "^5.3.0", 13 | "@node-minify/core": "^5.3.0", 14 | "@node-minify/uglify-js": "^5.3.0", 15 | "fs-extra": "^9.0.0", 16 | "node-watch": "^0.6.3" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /main/Config.in: -------------------------------------------------------------------------------- 1 | ################################################################### 2 | # Component enable/disable selection 3 | # in the updated build system, default is y and can not be disabled 4 | if AOS_CREATE_PROJECT 5 | config AOS_COMP_AMP_MAIN 6 | bool 7 | default y 8 | # do NOT select depend component in this file 9 | # use $(NAME)_COMPONENTS in aos.mk 10 | endif 11 | 12 | # Backward compatibility 13 | if !AOS_CREATE_PROJECT 14 | config AOS_COMP_AMP_MAIN 15 | bool "amp_main" 16 | default y 17 | help 18 | AliOS things mini program -- smart config support component 19 | endif 20 | -------------------------------------------------------------------------------- /main/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libmain.a 2 | MODULE = main 3 | 4 | MOD_SOURCES += \ 5 | amp_main.c \ 6 | amp_engine.c \ 7 | amp_task.c 8 | 9 | MOD_INCLUDES := \ 10 | ../adapter/include \ 11 | ../adapter/include/peripheral \ 12 | ../adapter/platform/linux \ 13 | ../utils/mbedtls/include \ 14 | ../utils/cJSON \ 15 | ../components/linkkit \ 16 | ../components/linkkit/infra \ 17 | ../components/ulog \ 18 | ../services/board_mgr \ 19 | ../services/recovery \ 20 | ../services/app_mgr \ 21 | ../services/amp_utils 22 | 23 | include $(TOOLS_DIR)/rules.mk 24 | -------------------------------------------------------------------------------- /main/amp_task.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef AMP_TASK_H 6 | #define AMP_TASK_H 7 | 8 | #include 9 | 10 | typedef void (*amp_engine_call_t)(void *data); 11 | 12 | typedef enum { 13 | AMP_TASK_MSG_CALLBACK = 0, /* default JSE callback */ 14 | AMP_TASK_MSG_EXIT = 1, 15 | AMP_TASK_MSG_TYPE_MAX 16 | } amp_task_msg_type_t; 17 | 18 | typedef enum { 19 | AMP_TIMER_ONCE = 0, /* one shot timer */ 20 | AMP_TIMER_REPEAT /* repeat timer */ 21 | } amp_timer_type_t; 22 | 23 | typedef struct { 24 | amp_task_msg_type_t type; 25 | amp_engine_call_t callback; 26 | void *param; 27 | } amp_task_msg_t; 28 | 29 | int32_t amp_task_schedule_call(amp_engine_call_t call, void *arg); 30 | 31 | /** 32 | * 33 | * JSEngine task initialization 34 | * 35 | */ 36 | int32_t amp_task_init(void); 37 | 38 | /** 39 | * JSEngine yield task, for asynchronous event process 40 | * 41 | */ 42 | int32_t amp_task_yield(uint32_t timeout); 43 | 44 | void timer_list_clear(void); 45 | 46 | void *amp_task_timer_action(uint32_t ms, amp_engine_call_t action, 47 | void *arg, amp_timer_type_t type); 48 | 49 | int32_t amp_task_cancel_timer(void *timerid); 50 | 51 | int32_t amp_task_exit_call(amp_engine_call_t call, void *arg); 52 | 53 | void amp_task_main(); 54 | 55 | int32_t amp_task_deinit(); 56 | 57 | #endif /* AMP_TASK_H */ 58 | -------------------------------------------------------------------------------- /main/aos.mk: -------------------------------------------------------------------------------- 1 | NAME = libamp_main 2 | 3 | $(NAME)_MBINS_TYPE := kernel 4 | $(NAME)_VERSION := 1.0.0 5 | $(NAME)_SUMMARY := amp component main 6 | 7 | $(NAME)_SOURCES += \ 8 | amp_main.c \ 9 | amp_engine.c \ 10 | amp_task.c 11 | 12 | $(NAME)_INCLUDES := \ 13 | ../adapter/include \ 14 | ../adapter/include/peripheral \ 15 | ../adapter/platform/aos-haas100 \ 16 | ../utils/mbedtls/include \ 17 | ../utils/cJSON \ 18 | ../components/linkkit \ 19 | ../components/linkkit/infra \ 20 | ../components/ulog \ 21 | ../services/board_mgr \ 22 | ../services/recovery \ 23 | ../services/app_mgr 24 | 25 | -------------------------------------------------------------------------------- /services/Config.in: -------------------------------------------------------------------------------- 1 | ################################################################### 2 | # Component enable/disable selection 3 | # in the updated build system, default is y and can not be disabled 4 | if AOS_CREATE_PROJECT 5 | config AOS_COMP_AMP_SERVICES 6 | bool 7 | default y 8 | # do NOT select depend component in this file 9 | # use $(NAME)_COMPONENTS in aos.mk 10 | endif 11 | 12 | # Backward compatibility 13 | if !AOS_CREATE_PROJECT 14 | config AOS_COMP_AMP_SERVICES 15 | bool "amp_services" 16 | default y 17 | help 18 | AliOS things mini program -- smart config support component 19 | endif 20 | -------------------------------------------------------------------------------- /services/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libservices.a 2 | MODULE = services 3 | 4 | MOD_SOURCES += \ 5 | app_mgr/app_mgr.c \ 6 | app_mgr/app_ntp.c \ 7 | app_mgr/ota_socket.c 8 | 9 | MOD_SOURCES += \ 10 | board_mgr/board_info.c \ 11 | board_mgr/board_mgr.c 12 | 13 | MOD_SOURCES += \ 14 | recovery/recovery.c \ 15 | recovery/ymodem.c 16 | 17 | MOD_SOURCES += \ 18 | amp_utils/amp_utils.c \ 19 | 20 | MOD_INCLUDES := \ 21 | ../main \ 22 | ../adapter/include \ 23 | ../adapter/include/peripheral \ 24 | ../adapter/platform/linux \ 25 | ../utils/mbedtls/include \ 26 | ../utils/cJSON \ 27 | ../components/linkkit \ 28 | ../components/linkkit/infra \ 29 | ../components/linkkit/dev_model \ 30 | ../components/linkkit/dev_sign \ 31 | ../components/linkkit/mqtt \ 32 | ../components/ulog \ 33 | ../components/das/include \ 34 | ../components/ota/include \ 35 | amp_utils \ 36 | app_mgr \ 37 | board_mgr \ 38 | recovery 39 | 40 | include $(TOOLS_DIR)/rules.mk 41 | -------------------------------------------------------------------------------- /services/amp_utils/amp_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef AMP_UTILS_H 6 | #define AMP_UTILS_H 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #if defined(__cplusplus) 13 | extern "C" { 14 | #endif 15 | 16 | unsigned char hex2num(unsigned char ch); 17 | char itoch(int val); 18 | void num2hex(unsigned char ch, unsigned char *hex); 19 | int end_with(char *str1, char *str2); 20 | void hexdump(const char *title, const void *buff, const int len); 21 | int amp_version_get(char *version); 22 | int amp_app_version_get(char *version); 23 | 24 | #ifdef SUPPORT_NODE_MODELES 25 | char *getFilePath(char *name); 26 | char *getClearPath(char *path); 27 | char *getNodeModulePath(char *path); 28 | #endif 29 | 30 | #if defined(__cplusplus) 31 | } 32 | #endif 33 | 34 | #endif /* JSE_UTILS_H */ 35 | -------------------------------------------------------------------------------- /services/aos.mk: -------------------------------------------------------------------------------- 1 | NAME = libamp_services 2 | 3 | $(NAME)_MBINS_TYPE := kernel 4 | $(NAME)_VERSION := 1.0.0 5 | $(NAME)_SUMMARY := amp component services 6 | 7 | $(NAME)_SOURCES += \ 8 | app_mgr/app_mgr.c \ 9 | app_mgr/app_ntp.c \ 10 | app_mgr/app_management_center.c \ 11 | app_mgr/ota_socket.c 12 | 13 | $(NAME)_SOURCES += \ 14 | board_mgr/board_info.c \ 15 | board_mgr/board_mgr.c 16 | 17 | $(NAME)_SOURCES += \ 18 | recovery/recovery.c \ 19 | recovery/ymodem.c 20 | 21 | $(NAME)_SOURCES += \ 22 | amp_utils/amp_utils.c \ 23 | 24 | $(NAME)_INCLUDES := \ 25 | ../main \ 26 | ../adapter/include \ 27 | ../adapter/include/peripheral \ 28 | ../adapter/platform/aos-haas100 \ 29 | ../utils/mbedtls/include \ 30 | ../utils/cJSON \ 31 | ../components/linkkit \ 32 | ../components/linkkit/infra \ 33 | ../components/linkkit/dev_model \ 34 | ../components/linkkit/dev_sign \ 35 | ../components/linkkit/mqtt \ 36 | ../components/ota/include \ 37 | ../components/ulog \ 38 | ../components/das/include \ 39 | amp_utils \ 40 | app_mgr \ 41 | board_mgr \ 42 | recovery 43 | 44 | -------------------------------------------------------------------------------- /services/app_mgr/app_ntp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | #ifndef NTP_H 7 | #define NTP_H 8 | 9 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 10 | extern "C" { 11 | #endif 12 | 13 | 14 | #define TOPIC_NTP "/ext/ntp/%s/%s/request" 15 | #define TOPIC_NTP_REPLY "/ext/ntp/%s/%s/response" 16 | 17 | #define NTP_TIME_STR_MAX_LEN (20) 18 | 19 | int app_ntp_time_request(void *handle, iotx_dev_meta_info_t meta_info, void (*)(const char *ntp_offset_time_ms)); 20 | 21 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /services/app_mgr/ota_socket.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "amp_network.h" 10 | #include "amp_tcp.h" 11 | #include "amp_defines.h" 12 | #include "app_mgr.h" 13 | #include "ota_socket.h" 14 | 15 | #define MOD_STR "OTA_SOCKET" 16 | int ota_socket_check_conn(int sock) 17 | { 18 | if (sock < 0) { 19 | amp_error(MOD_STR, "ota_socket_check_conn: invalid socket fd\n"); 20 | return -1; 21 | } 22 | /* 23 | struct pollfd fd = { .fd = sock, .events = POLLOUT }; 24 | int ret = 0; 25 | socklen_t len = 0; 26 | 27 | while (poll(&fd, 1, -1) == -1) { 28 | if (errno != EINTR ) { 29 | return -1; 30 | } 31 | } 32 | 33 | len = sizeof(ret); 34 | if (getsockopt (sock, SOL_SOCKET, SO_ERROR, &ret, &len) == -1 || 35 | ret != 0) { 36 | return -1; 37 | } 38 | */ 39 | return 0; 40 | } 41 | 42 | int ota_socket_connect(int port, char *host_addr) 43 | { 44 | return amp_tcp_establish(host_addr, port); 45 | } 46 | 47 | int ota_socket_send(int socket, const char *buf, size_t len) 48 | { 49 | return amp_tcp_write(socket, buf, len, TCP_SEND_TIMEOUT); 50 | } 51 | 52 | int ota_socket_recv(int socket, char *buf, size_t len) 53 | { 54 | return amp_tcp_read(socket, buf, len, TCP_RECV_TIMEOUT); 55 | } 56 | 57 | void ota_socket_close(int socket) 58 | { 59 | amp_tcp_destroy(socket); 60 | } -------------------------------------------------------------------------------- /services/app_mgr/ota_socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef BE_OTA_SOCKET_H 6 | #define BE_OTA_SOCKET_H 7 | 8 | #include 9 | #include 10 | 11 | #define TCP_SEND_TIMEOUT 3000 12 | #define TCP_RECV_TIMEOUT 3000 13 | 14 | int ota_socket_connect(int port, char *host_addr); 15 | 16 | int ota_socket_send(int socket, const char *buf, size_t len); 17 | 18 | int ota_socket_recv(int socket, char *buf, size_t len); 19 | 20 | void ota_socket_close(int socket); 21 | 22 | int ota_socket_check_conn(int sock); 23 | #endif /* BE_OTA_SOCKET_H */ 24 | -------------------------------------------------------------------------------- /services/board_mgr/board_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef BE_BOARD_INFO_H 6 | #define BE_BOARD_INFO_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include 13 | 14 | #define DEVICE_KEY_TAG "DEVICE_KEY" 15 | #define DEVICE_NAME_TAG "DEVICE_NAME" 16 | #define DEVICE_SECRET_TAG "DEVICE_SECRET" 17 | 18 | /** 19 | * set config info of the board 20 | * 21 | * @param[in] deviceKey the key of a product 22 | * @param[in] deviceName the name of a product 23 | *@param[in] deviceSecret the secret of a product 24 | * @return 0 is ok, others fail 25 | */ 26 | 27 | int8_t board_setDeviceInfo(char *deviceKey, char *deviceName, 28 | char *deviceSecret); 29 | 30 | /** 31 | * get config info of the board 32 | * 33 | * @param[out] deviceKey the key of a product 34 | * @param[out] deviceName the name of a product 35 | *@param[out] deviceSecret the secret of a product 36 | * @return 0 is ok, others fail 37 | */ 38 | 39 | int8_t board_getDeviceInfo(char **productKey, char **deviceName, 40 | char **deviceSecret); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif /* BE_BOARD_INFO_H */ 47 | -------------------------------------------------------------------------------- /services/recovery/recovery.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Alibaba Group Holding Limited 3 | */ 4 | 5 | #ifndef AMP_RECOVERY_H 6 | #define AMP_RECOVERY_H 7 | 8 | #include 9 | #include 10 | #include "amp_config.h" 11 | 12 | /* recovery switch & status led. default for esp32 */ 13 | #ifndef AMP_REC_UART 14 | #define AMP_REC_UART 2 15 | #endif 16 | 17 | #ifndef AMP_STATUS_IO 18 | #define AMP_STATUS_IO 33 19 | #endif 20 | 21 | #ifndef AMP_STATUS_IO_ON 22 | #define AMP_STATUS_IO_ON 1 23 | #endif 24 | 25 | /* recovery switch */ 26 | #ifndef AMP_REC_IO 27 | #define AMP_REC_IO 11 28 | #endif 29 | 30 | #ifndef AMP_REC_IO_ON 31 | #define AMP_REC_IO_ON 1 32 | #endif 33 | 34 | typedef enum{ 35 | AMP_STATUS_NORMAL = 0, 36 | AMP_STATUS_SERVICE_AVAILABLE, // 1 37 | AMP_STATUS_RECOVERY, // 2 38 | AMP_STATUS_UPDATING, // 3 39 | AMP_STATUS_JSERROR, // 4 40 | AMP_STATUS_COREDUMP, // 5 41 | AMP_STATUS_END 42 | }AMP_STATUS; 43 | 44 | int amp_recovery_init(void); 45 | 46 | int amp_recovery_entry(void); 47 | 48 | void amp_status_set(AMP_STATUS status); 49 | 50 | void uart_send_byte(unsigned char c); 51 | 52 | unsigned char uart_recv_byte(unsigned char *c); 53 | 54 | #endif /* AMP_RECOVERY_H */ -------------------------------------------------------------------------------- /test/host/tcpServer.js: -------------------------------------------------------------------------------- 1 | var net = require('net'); 2 | 3 | var HOST = ''; 4 | var PORT = 0; 5 | 6 | var server = net.createServer(); 7 | server.listen(PORT, HOST); 8 | // console.log(server); 9 | console.log('Server listening on ' + HOST + ':' + PORT); 10 | 11 | server.on('connection', function(sock) { 12 | console.log('CONNECTED: ' + sock.remoteAddress +':'+ sock.remotePort); 13 | // 为这个socket实例添加一个"data"事件处理函数 14 | sock.on('data', function(data) { 15 | console.log('DATA ' + sock.remoteAddress + ': ' + data); 16 | // 回发该数据,客户端将收到来自服务端的数据 17 | sock.write('AMP tcp server reply'); 18 | }); 19 | 20 | // 为这个socket实例添加一个"close"事件处理函数 21 | sock.on('close', function(data) { 22 | console.log('CLOSED: ' + 23 | sock.remoteAddress + ' ' + sock.remotePort); 24 | }); 25 | 26 | }); -------------------------------------------------------------------------------- /test/host/udpServer.js: -------------------------------------------------------------------------------- 1 | const dgram = require('dgram'); 2 | const server = dgram.createSocket('udp4'); //创建udp服务器 3 | 4 | //以下server.on 都是在监听不同信号 5 | server.on('close',()=>{ 6 | console.log('socket已关闭'); 7 | }); 8 | 9 | server.on('error',(err)=>{ 10 | console.log(err); 11 | }); 12 | 13 | server.on('listening',()=>{ 14 | console.log('socket正在监听中...'); 15 | }); 16 | 17 | server.on('message',(msg,rinfo)=>{ 18 | console.log(`receive message: ${msg} from ${rinfo.address}:${rinfo.port}`); 19 | var message = 'AMP udp server reply'; 20 | server.send(message,rinfo.port,rinfo.address); 21 | }); 22 | 23 | server.bind(50000); //绑定端口,不绑定的话也可以send数据但是无法接受 24 | 25 | -------------------------------------------------------------------------------- /test/network.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | var network = require('network'); 6 | 7 | var net = network.openNetWorkClient(); 8 | 9 | function netinfo_print(){ 10 | var info = net.getInfo(); 11 | /* imsi 国际移动用户识别码 */ 12 | console.log('net imsi is: ' + info.imsi); 13 | 14 | /* imei 国际移动设备识别码 */ 15 | console.log('net imei is: ' + info.imei); 16 | 17 | /* iccid 集成电路卡识别码 */ 18 | console.log('net iccid is: ' + info.iccid); 19 | 20 | /* cid 基站编号 */ 21 | console.log('net cid is: ' + info.cid); 22 | 23 | /* lac 位置区域码 */ 24 | console.log('net lac is: ' + info.lac); 25 | 26 | /* mcc 移动国家代码(中国的为460 */ 27 | console.log('net mcc is: ' + info.mcc); 28 | 29 | /* mnc 移动网络号码(中国移动为00,中国联通为01) */ 30 | console.log('net mnc is: ' + info.mnc); 31 | 32 | /* rssi 接收的信号强度值 */ 33 | console.log('net rssi is: ' + info.rssi); 34 | } 35 | 36 | 37 | /** 获取网络类型 38 | * 目前支持两种类型:wifi cellular(蜂窝网) 39 | */ 40 | var type = net.getType(); 41 | console.log('net type is: ' + type); 42 | 43 | /** 获取网络状态 44 | * 目前支持两种状态:connect disconnect(蜂窝网) 45 | */ 46 | var status = net.getStatus(); 47 | console.log('net status is: ' + status); 48 | 49 | if (status == 'connect') { 50 | netinfo_print(); 51 | } else { 52 | net.on('connect', function() { 53 | netinfo_print(); 54 | }) 55 | } 56 | 57 | net.on('disconnect', function(){ 58 | console.log('device is disconnect'); 59 | }); -------------------------------------------------------------------------------- /test/test_fs.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | /* 本测试case,测试fs的接口,接口返回值等 */ 6 | console.log('testing fs...'); 7 | // 测试 fs 模块 8 | var fs = require('fs'); 9 | if(!(fs && fs.writeSync && fs.readSync && fs.unlinkSync)){ 10 | throw new Error("[failed] require(\'fs\')"); 11 | } 12 | console.log('[success] require(\'fs\')'); 13 | 14 | // 测试 fs 写入 15 | if(fs.writeSync('./aiot.txt', 'amp')){ 16 | throw new Error("[failed] fs.writeSync()"); 17 | } 18 | console.log("[success] fs.writeSync()"); 19 | 20 | // 测试 fs 读取 21 | fs.readSync('./aiot.txt'); 22 | var value = fs.readSync('./aiot.txt'); 23 | if(!value || value !== 'amp'){ 24 | throw new Error("[failed] fs.readSync()"); 25 | } 26 | 27 | function testWrongFile() { 28 | try{ 29 | fs.readSync('./aiot1.txt') 30 | } catch (e) { 31 | return true; 32 | } 33 | throw new Error("[failed] fs.readSync()"); 34 | } 35 | 36 | if (testWrongFile()) { 37 | console.log("[success] fs.readSync()"); 38 | } 39 | // 测试 fs 清除 40 | if(fs.unlinkSync('./aiot.txt') || fs.unlinkSync('./aiot.txt') !== undefined){ 41 | throw new Error("[failed] fs.unlinkSync()"); 42 | } 43 | console.log("[success] fs.unlinkSync()"); -------------------------------------------------------------------------------- /test/test_http.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | console.log('http: testing http...'); 6 | 7 | var http = require('http'); 8 | if (!(http && http.request)) { 9 | throw new Error("http: [failed] require(\'http\')"); 10 | } 11 | 12 | console.log('http: [success] require(\'http\')'); 13 | 14 | 15 | var request_url = 'http://appengine.oss-cn-hangzhou.aliyuncs.com/httpTest.txt'; 16 | var defaultMessage = 'this is AMP HTTP test file'; 17 | 18 | http.request({ 19 | url: request_url, 20 | method: 'GET', 21 | headers: { 22 | 'content-type':'application/json' 23 | }, 24 | success: function (data) { 25 | console.log('http: [debug] receive data is ' + data); 26 | if(data === defaultMessage) { 27 | console.log('http: [success] http.request'); 28 | } 29 | } 30 | }); -------------------------------------------------------------------------------- /test/test_kv.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 | */ 4 | 5 | /* 本测试case,测试kv的接口,接口返回值等 */ 6 | console.log('testing kv...'); 7 | // 测试 kv 模块 8 | var kv = require('kv'); 9 | if(!(kv && kv.setStorageSync && kv.getStorageSync && kv.removeStorageSync)){ 10 | throw new Error("[failed] require(\'kv\')"); 11 | } 12 | console.log('[success] require(\'kv\')'); 13 | 14 | // 测试 kv 写入 15 | if(kv.setStorageSync('aiot', 'amp')){ 16 | throw new Error("[failed] kv.setStorageSync()"); 17 | } 18 | console.log("[success] kv.setStorageSync()"); 19 | 20 | // 测试 kv 读取 21 | kv.getStorageSync('aiot'); 22 | var value = kv.getStorageSync('aiot'); 23 | if(!value || value !== 'amp'){ 24 | throw new Error("[failed] kv.getStorageSync()"); 25 | } 26 | if(kv.getStorageSync('aiot1') == 0){ 27 | throw new Error("[failed] kv.getStorageSync()"); 28 | } 29 | console.log("[success] kv.getStorageSync()"); 30 | 31 | // 测试 kv 修改 32 | if(kv.setStorageSync('aiot', 'alios-things')){ 33 | throw new Error("[failed] kv modify"); 34 | } 35 | var value2 = kv.getStorageSync('aiot'); 36 | if(!value2 || value2 !== 'alios-things'){ 37 | throw new Error("[failed] kv modify"); 38 | } 39 | console.log("[success] kv modify"); 40 | 41 | // 测试 kv 清除 42 | if(kv.removeStorageSync('aiot') || kv.getStorageSync('aiot') !== undefined){ 43 | throw new Error("[failed] kv.removeStorageSync()"); 44 | } 45 | console.log("[success] kv.removeStorageSync()"); -------------------------------------------------------------------------------- /tools/config.mk: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------- 2 | # tool chain define 3 | #--------------------------------------------------------- 4 | 5 | CC = gcc 6 | CXX = g++ 7 | AR = ar 8 | LD = ld 9 | OBJCOPY = objcopy 10 | 11 | #--------------------------------------------------------- 12 | # shell command 13 | #--------------------------------------------------------- 14 | ECHO = @echo 15 | MKDIR = mkdir -p 16 | MV = @mv -r 17 | RM = @rm -rf 18 | MAKE = @make -j8 19 | 20 | #--------------------------------------------------------- 21 | # complier flags 22 | #--------------------------------------------------------- 23 | 24 | ARFLAGS = rcs 25 | 26 | 27 | #--------------------------------------------------------- 28 | # link libs 29 | #--------------------------------------------------------- 30 | LIBS = -ln -lrt -lpthread -lutil -------------------------------------------------------------------------------- /tools/rules.mk: -------------------------------------------------------------------------------- 1 | 2 | include $(TOOLS_DIR)/config.mk 3 | 4 | SUB_ALL_SRCS := $(MOD_SOURCES) 5 | 6 | SUB_ALL_OBJS := $(patsubst %.c,%.o,$(SUB_ALL_SRCS)) 7 | 8 | $(foreach inc, $(MOD_INCLUDES), $(eval SUB_ALL_INCS += -I$(inc))) 9 | 10 | all: $(LIBS_DIR)/$(TARGET) 11 | 12 | $(LIBS_DIR)/$(TARGET): $(SUB_ALL_OBJS) 13 | $(ECHO) "Archiving $@ ..." 14 | $(AR) $(ARFLAGS) $@ $^ 15 | 16 | $(SUB_ALL_OBJS): %.o: %.c 17 | $(ECHO) Compiling $< ... 18 | $(CC) -c -o $@ $< $(SUB_ALL_INCS) $(CCFLAGS) -------------------------------------------------------------------------------- /utils/cJSON/Config.in: -------------------------------------------------------------------------------- 1 | ################################################################### 2 | # Component enable/disable selection 3 | # in the updated build system, default is y and can not be disabled 4 | if AOS_CREATE_PROJECT 5 | config AOS_COMP_AMP_UTILS_CJSON 6 | bool 7 | default y 8 | # do NOT select depend component in this file 9 | # use $(NAME)_COMPONENTS in aos.mk 10 | endif 11 | 12 | # Backward compatibility 13 | if !AOS_CREATE_PROJECT 14 | config AOS_COMP_AMP_UTILS_CJSON 15 | bool "amp_utils_cjson" 16 | default y 17 | help 18 | AliOS things mini program -- smart config support component 19 | endif 20 | -------------------------------------------------------------------------------- /utils/cJSON/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libcjson.a 2 | MODULE = cJSON 3 | 4 | MOD_SOURCES := \ 5 | cJSON.c 6 | 7 | MOD_INCLUDES := \ 8 | ./ 9 | 10 | include $(TOOLS_DIR)/rules.mk 11 | -------------------------------------------------------------------------------- /utils/cJSON/aos.mk: -------------------------------------------------------------------------------- 1 | NAME = libamp_cjson 2 | 3 | $(NAME)_MBINS_TYPE := kernel 4 | $(NAME)_VERSION := 0.0.1 5 | $(NAME)_SUMMARY := amp component cJSON 6 | 7 | $(NAME)_SOURCES := \ 8 | cJSON.c 9 | 10 | $(NAME)_INCLUDES := \ 11 | ./ 12 | 13 | -------------------------------------------------------------------------------- /utils/mbedtls/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libmbedtls.a 2 | MODULE = mbedtls 3 | 4 | MOD_SOURCES := \ 5 | library/aes.c \ 6 | library/asn1parse.c \ 7 | library/base64.c \ 8 | library/bignum.c \ 9 | library/cipher_wrap.c \ 10 | library/cipher.c \ 11 | library/ctr_drbg.c \ 12 | library/debug.c \ 13 | library/entropy_poll.c \ 14 | library/entropy.c \ 15 | library/error.c \ 16 | library/md_wrap.c \ 17 | library/md.c \ 18 | library/md5.c \ 19 | library/net_sockets.c \ 20 | library/oid.c \ 21 | library/pem.c \ 22 | library/pk_wrap.c \ 23 | library/pk.c \ 24 | library/pkparse.c \ 25 | library/platform.c \ 26 | library/rsa.c \ 27 | library/sha1.c \ 28 | library/sha256.c \ 29 | library/ssl_ciphersuites.c \ 30 | library/ssl_cli.c \ 31 | library/ssl_cookie.c \ 32 | library/ssl_tls.c \ 33 | library/timing.c \ 34 | library/x509_crt.c \ 35 | library/x509.c 36 | 37 | MOD_INCLUDES := \ 38 | ../../adapter/platform/linux \ 39 | ../../adapter/include \ 40 | include 41 | 42 | include $(TOOLS_DIR)/rules.mk 43 | -------------------------------------------------------------------------------- /utils/mbedtls/include/mbedtls/net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 | */ 4 | 5 | 6 | 7 | 8 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) 9 | #include "mbedtls/net_sockets.h" 10 | #if defined(MBEDTLS_DEPRECATED_WARNING) 11 | #warning "Deprecated header file: Superseded by mbedtls/net_sockets.h" 12 | #endif /* MBEDTLS_DEPRECATED_WARNING */ 13 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ 14 | --------------------------------------------------------------------------------