2019-05-17 09:15:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
2019-11-11 23:45:21 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-05-17 09:15:25 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-16 08:43:57 +00:00
|
|
|
#include "bh_platform.h"
|
2019-05-17 09:15:25 +00:00
|
|
|
#include "app_manager_host.h"
|
|
|
|
#include "app_manager.h"
|
|
|
|
#include "app_manager_export.h"
|
|
|
|
#include "coap_ext.h"
|
|
|
|
|
|
|
|
/* host communication interface */
|
|
|
|
static host_interface host_commu;
|
|
|
|
|
|
|
|
/* IMRTLink Two leading bytes */
|
2021-10-21 05:58:34 +00:00
|
|
|
static unsigned char leadings[] = { (unsigned char)0x12, (unsigned char)0x34 };
|
2019-05-17 09:15:25 +00:00
|
|
|
|
|
|
|
/* IMRTLink Receiving Phase */
|
|
|
|
typedef enum recv_phase_t {
|
2021-03-03 12:19:24 +00:00
|
|
|
Phase_Non_Start,
|
|
|
|
Phase_Leading,
|
|
|
|
Phase_Type,
|
|
|
|
Phase_Size,
|
|
|
|
Phase_Payload,
|
|
|
|
Phase_Ignoring
|
2019-05-17 09:15:25 +00:00
|
|
|
} recv_phase_t;
|
|
|
|
|
|
|
|
/* IMRTLink Receive Context */
|
|
|
|
typedef struct recv_context_t {
|
|
|
|
recv_phase_t phase;
|
|
|
|
bh_link_msg_t message;
|
|
|
|
int size_in_phase;
|
|
|
|
} recv_context_t;
|
|
|
|
|
|
|
|
/* Current IMRTLink receive context */
|
|
|
|
static recv_context_t recv_ctx;
|
|
|
|
|
|
|
|
/* Lock for device write */
|
|
|
|
static korp_mutex host_lock;
|
|
|
|
|
|
|
|
static bool enable_log = false;
|
|
|
|
|
2021-10-21 05:58:34 +00:00
|
|
|
static bool
|
|
|
|
is_little_endian()
|
2019-05-17 09:15:25 +00:00
|
|
|
{
|
|
|
|
long i = 0x01020304;
|
2021-10-21 05:58:34 +00:00
|
|
|
unsigned char *c = (unsigned char *)&i;
|
2019-05-17 09:15:25 +00:00
|
|
|
return (*c == 0x04) ? true : false;
|
|
|
|
}
|
|
|
|
|
2021-10-21 05:58:34 +00:00
|
|
|
static void
|
|
|
|
exchange32(uint8 *pData)
|
2019-05-17 09:15:25 +00:00
|
|
|
{
|
|
|
|
uint8 value = *pData;
|
|
|
|
*pData = *(pData + 3);
|
|
|
|
*(pData + 3) = value;
|
|
|
|
|
|
|
|
value = *(pData + 1);
|
|
|
|
*(pData + 1) = *(pData + 2);
|
|
|
|
*(pData + 2) = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return:
|
|
|
|
* 1: complete message received
|
|
|
|
* 0: incomplete message received
|
|
|
|
*/
|
2021-10-21 05:58:34 +00:00
|
|
|
static int
|
|
|
|
on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
2019-05-17 09:15:25 +00:00
|
|
|
{
|
|
|
|
if (ctx->phase == Phase_Non_Start) {
|
|
|
|
ctx->message.payload_size = 0;
|
|
|
|
|
|
|
|
if (ctx->message.payload) {
|
2020-03-10 11:54:44 +00:00
|
|
|
APP_MGR_FREE(ctx->message.payload);
|
2019-05-17 09:15:25 +00:00
|
|
|
ctx->message.payload = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch == leadings[0]) {
|
|
|
|
if (enable_log)
|
|
|
|
app_manager_printf("##On byte arrive: got leading 0\n");
|
|
|
|
ctx->phase = Phase_Leading;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2021-03-03 12:19:24 +00:00
|
|
|
}
|
|
|
|
else if (ctx->phase == Phase_Leading) {
|
2019-05-17 09:15:25 +00:00
|
|
|
if (ch == leadings[1]) {
|
|
|
|
if (enable_log)
|
|
|
|
app_manager_printf("##On byte arrive: got leading 1\n");
|
|
|
|
ctx->phase = Phase_Type;
|
2021-10-21 05:58:34 +00:00
|
|
|
}
|
|
|
|
else
|
2019-05-17 09:15:25 +00:00
|
|
|
ctx->phase = Phase_Non_Start;
|
|
|
|
|
|
|
|
return 0;
|
2021-03-03 12:19:24 +00:00
|
|
|
}
|
|
|
|
else if (ctx->phase == Phase_Type) {
|
2019-05-17 09:15:25 +00:00
|
|
|
if (ctx->size_in_phase++ == 0) {
|
|
|
|
if (enable_log)
|
|
|
|
app_manager_printf("##On byte arrive: got type 0\n");
|
|
|
|
ctx->message.message_type = ch;
|
2021-03-03 12:19:24 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-05-17 09:15:25 +00:00
|
|
|
if (enable_log)
|
|
|
|
app_manager_printf("##On byte arrive: got type 1\n");
|
|
|
|
ctx->message.message_type |= (ch << 8);
|
|
|
|
ctx->message.message_type = ntohs(ctx->message.message_type);
|
|
|
|
ctx->phase = Phase_Size;
|
|
|
|
ctx->size_in_phase = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2021-03-03 12:19:24 +00:00
|
|
|
}
|
|
|
|
else if (ctx->phase == Phase_Size) {
|
2021-10-21 05:58:34 +00:00
|
|
|
unsigned char *p = (unsigned char *)&ctx->message.payload_size;
|
2019-05-17 09:15:25 +00:00
|
|
|
|
|
|
|
if (enable_log)
|
|
|
|
app_manager_printf("##On byte arrive: got payload_size, byte %d\n",
|
2021-03-03 12:19:24 +00:00
|
|
|
ctx->size_in_phase);
|
2019-05-17 09:15:25 +00:00
|
|
|
p[ctx->size_in_phase++] = ch;
|
|
|
|
|
|
|
|
if (ctx->size_in_phase == sizeof(ctx->message.payload_size)) {
|
|
|
|
ctx->message.payload_size = ntohl(ctx->message.payload_size);
|
|
|
|
ctx->phase = Phase_Payload;
|
|
|
|
|
|
|
|
if (enable_log)
|
|
|
|
app_manager_printf("##On byte arrive: payload_size: %d\n",
|
2021-03-03 12:19:24 +00:00
|
|
|
ctx->message.payload_size);
|
2019-05-17 09:15:25 +00:00
|
|
|
if (ctx->message.payload) {
|
2020-03-10 11:54:44 +00:00
|
|
|
APP_MGR_FREE(ctx->message.payload);
|
2019-05-17 09:15:25 +00:00
|
|
|
ctx->message.payload = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* message completion */
|
|
|
|
if (ctx->message.payload_size == 0) {
|
|
|
|
ctx->phase = Phase_Non_Start;
|
|
|
|
if (enable_log)
|
2021-03-03 12:19:24 +00:00
|
|
|
app_manager_printf("##On byte arrive: receive end, "
|
|
|
|
"payload_size is 0.\n");
|
2019-05-17 09:15:25 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
if (ctx->message.message_type != INSTALL_WASM_APP) {
|
|
|
|
ctx->message.payload =
|
2021-10-21 05:58:34 +00:00
|
|
|
(char *)APP_MGR_MALLOC(ctx->message.payload_size);
|
2019-05-17 09:15:25 +00:00
|
|
|
if (!ctx->message.payload) {
|
|
|
|
ctx->phase = Phase_Non_Start;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->phase = Phase_Payload;
|
|
|
|
ctx->size_in_phase = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2021-03-03 12:19:24 +00:00
|
|
|
}
|
|
|
|
else if (ctx->phase == Phase_Payload) {
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
if (ctx->message.message_type == INSTALL_WASM_APP) {
|
2019-05-17 09:15:25 +00:00
|
|
|
int received_size;
|
|
|
|
module_on_install_request_byte_arrive_func module_on_install =
|
2021-10-21 05:58:34 +00:00
|
|
|
g_module_interfaces[Module_WASM_App]->module_on_install;
|
2019-05-17 09:15:25 +00:00
|
|
|
|
|
|
|
ctx->size_in_phase++;
|
|
|
|
|
|
|
|
if (module_on_install != NULL) {
|
|
|
|
if (module_on_install(ch, ctx->message.payload_size,
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
&received_size)) {
|
2019-05-17 09:15:25 +00:00
|
|
|
if (received_size == ctx->message.payload_size) {
|
|
|
|
/* whole wasm app received */
|
|
|
|
ctx->phase = Phase_Non_Start;
|
|
|
|
return 1;
|
|
|
|
}
|
2021-03-03 12:19:24 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-05-17 09:15:25 +00:00
|
|
|
/* receive or handle fail */
|
2021-03-03 12:19:24 +00:00
|
|
|
if (ctx->size_in_phase < ctx->message.payload_size) {
|
|
|
|
ctx->phase = Phase_Ignoring;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ctx->phase = Phase_Non_Start;
|
|
|
|
ctx->size_in_phase = 0;
|
|
|
|
}
|
2019-05-17 09:15:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-03-03 12:19:24 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-05-17 09:15:25 +00:00
|
|
|
ctx->phase = Phase_Non_Start;
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
ctx->size_in_phase = 0;
|
2019-05-17 09:15:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-03-03 12:19:24 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-05-17 09:15:25 +00:00
|
|
|
ctx->message.payload[ctx->size_in_phase++] = ch;
|
|
|
|
|
|
|
|
if (ctx->size_in_phase == ctx->message.payload_size) {
|
|
|
|
ctx->phase = Phase_Non_Start;
|
|
|
|
if (enable_log)
|
2021-03-03 12:19:24 +00:00
|
|
|
app_manager_printf("##On byte arrive: receive end, "
|
|
|
|
"payload_size is %d.\n",
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
ctx->message.payload_size);
|
2019-05-17 09:15:25 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2021-03-03 12:19:24 +00:00
|
|
|
else if (ctx->phase == Phase_Ignoring) {
|
|
|
|
ctx->size_in_phase++;
|
|
|
|
if (ctx->size_in_phase == ctx->message.payload_size) {
|
|
|
|
if (ctx->message.payload)
|
|
|
|
APP_MGR_FREE(ctx->message.payload);
|
|
|
|
memset(ctx, 0, sizeof(*ctx));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2019-05-17 09:15:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-21 05:58:34 +00:00
|
|
|
int
|
|
|
|
aee_host_msg_callback(void *msg, uint32_t msg_len)
|
2019-05-17 09:15:25 +00:00
|
|
|
{
|
|
|
|
unsigned char *p = msg, *p_end = p + msg_len;
|
|
|
|
|
|
|
|
/*app_manager_printf("App Manager receive %d bytes from Host\n", msg_len);*/
|
|
|
|
|
|
|
|
for (; p < p_end; p++) {
|
|
|
|
int ret = on_imrt_link_byte_arrive(*p, &recv_ctx);
|
|
|
|
|
|
|
|
if (ret == 1) {
|
|
|
|
if (recv_ctx.message.payload) {
|
|
|
|
int msg_type = recv_ctx.message.message_type;
|
|
|
|
|
|
|
|
if (msg_type == REQUEST_PACKET) {
|
|
|
|
request_t request;
|
|
|
|
memset(&request, 0, sizeof(request));
|
|
|
|
|
|
|
|
if (!unpack_request(recv_ctx.message.payload,
|
2021-10-21 05:58:34 +00:00
|
|
|
recv_ctx.message.payload_size,
|
|
|
|
&request))
|
2019-05-17 09:15:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
request.sender = ID_HOST;
|
|
|
|
|
|
|
|
am_dispatch_request(&request);
|
2020-11-30 08:03:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-10-21 05:58:34 +00:00
|
|
|
app_manager_printf("unexpected host msg type: %d\n",
|
|
|
|
msg_type);
|
2019-05-17 09:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-03-10 11:54:44 +00:00
|
|
|
APP_MGR_FREE(recv_ctx.message.payload);
|
2019-05-17 09:15:25 +00:00
|
|
|
recv_ctx.message.payload = NULL;
|
|
|
|
recv_ctx.message.payload_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&recv_ctx, 0, sizeof(recv_ctx));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-21 05:58:34 +00:00
|
|
|
bool
|
|
|
|
app_manager_host_init(host_interface *interface)
|
2019-05-17 09:15:25 +00:00
|
|
|
{
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_init(&host_lock);
|
2019-05-17 09:15:25 +00:00
|
|
|
memset(&recv_ctx, 0, sizeof(recv_ctx));
|
|
|
|
|
|
|
|
host_commu.init = interface->init;
|
|
|
|
host_commu.send = interface->send;
|
|
|
|
host_commu.destroy = interface->destroy;
|
|
|
|
|
|
|
|
if (host_commu.init != NULL)
|
2021-10-21 05:58:34 +00:00
|
|
|
return host_commu.init();
|
2019-05-17 09:15:25 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-21 05:58:34 +00:00
|
|
|
int
|
|
|
|
app_manager_host_send_msg(int msg_type, const char *buf, int size)
|
2019-05-17 09:15:25 +00:00
|
|
|
{
|
|
|
|
/* send an IMRT LINK message contains the buf as payload */
|
|
|
|
if (host_commu.send != NULL) {
|
|
|
|
int size_s = size, n;
|
|
|
|
char header[16];
|
|
|
|
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_lock(&host_lock);
|
2019-05-17 09:15:25 +00:00
|
|
|
/* leading bytes */
|
|
|
|
bh_memcpy_s(header, 2, leadings, 2);
|
|
|
|
|
|
|
|
/* message type */
|
2021-03-03 12:19:24 +00:00
|
|
|
/* TODO: check if use network byte order!!! */
|
2021-10-21 05:58:34 +00:00
|
|
|
*((uint16 *)(header + 2)) = htons(msg_type);
|
2019-05-17 09:15:25 +00:00
|
|
|
|
|
|
|
/* payload length */
|
|
|
|
if (is_little_endian())
|
2021-10-21 05:58:34 +00:00
|
|
|
exchange32((uint8 *)&size_s);
|
2019-05-17 09:15:25 +00:00
|
|
|
|
|
|
|
bh_memcpy_s(header + 4, 4, &size_s, 4);
|
|
|
|
n = host_commu.send(NULL, header, 8);
|
|
|
|
if (n != 8) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_unlock(&host_lock);
|
2019-05-17 09:15:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* payload */
|
|
|
|
n = host_commu.send(NULL, buf, size);
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_unlock(&host_lock);
|
2019-05-17 09:15:25 +00:00
|
|
|
|
2020-06-02 06:53:06 +00:00
|
|
|
app_manager_printf("sent %d bytes to host\n", n);
|
2019-05-17 09:15:25 +00:00
|
|
|
return n;
|
2021-03-03 12:19:24 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-06-02 06:53:06 +00:00
|
|
|
app_manager_printf("no send api provided\n");
|
2019-05-17 09:15:25 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|