1 /*
2  * Copyright (C) 2015-2019 Alibaba Group Holding Limited
3  */
4 
5 #include <string.h>
6 #include <stdarg.h>
7 
8 #include "amp_config.h"
9 #include "aos_system.h"
10 #include "amp_defines.h"
11 #include "be_inl.h"
12 
13 #define MOD_STR  "BLECFGNET"
14 
native_blecfgnet_start(duk_context * ctx)15 static duk_ret_t native_blecfgnet_start(duk_context *ctx)
16 {
17     int ret = -1;
18     ret = BleCfg_run();
19     if (ret != 0) {
20         amp_warn(MOD_STR, "ble config net start failed");
21     }
22 
23 out:
24     duk_push_int(ctx, ret);
25     return 1;
26 }
27 
native_blecfgnet_recovery_wifi(duk_context * ctx)28 static duk_ret_t native_blecfgnet_recovery_wifi(duk_context *ctx)
29 {
30     int ret = -1;
31     ret = BleCfg_recovery_wifi();
32     if (ret != 0) {
33         amp_warn(MOD_STR, "ble config net recovery wifi failed");
34     }
35 
36 out:
37     duk_push_int(ctx, ret);
38     return 1;
39 }
40 
native_blecfgnet_recovery_devinfo(duk_context * ctx)41 static duk_ret_t native_blecfgnet_recovery_devinfo(duk_context *ctx)
42 {
43     int ret = -1;
44     ret = BleCfg_recovery_devinfo();
45     if (ret != 0) {
46         amp_warn(MOD_STR, "ble config net recovery device info failed");
47     }
48 
49 out:
50     duk_push_int(ctx, ret);
51     return 1;
52 }
53 
module_blecfgnet_register(void)54 void module_blecfgnet_register(void)
55 {
56     duk_context *ctx = be_get_context();
57 
58     duk_push_object(ctx);
59 
60     AMP_ADD_FUNCTION("start",           native_blecfgnet_start, 0);
61     AMP_ADD_FUNCTION("recoveryWifi",    native_blecfgnet_recovery_wifi, 0);
62     AMP_ADD_FUNCTION("recoveryDevInfo", native_blecfgnet_recovery_devinfo, 0);
63 
64     duk_put_prop_string(ctx, -2, "BLECFGNET");
65 }
66