1 /* 2 * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 */ 4 #include "dev_bind_internal.h" 5 #ifdef WIFI_PROVISION_ENABLED 6 #ifndef AWSS_DISABLE_REGISTRAR 7 #include "awss_enrollee.h" 8 #endif 9 #endif 10 11 #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 12 extern "C" { 13 #endif 14 15 static void *awss_bind_mutex = NULL; 16 int awss_start_bind(); 17 awss_report_cloud()18int awss_report_cloud() 19 { 20 if (awss_bind_mutex == NULL) { 21 awss_bind_mutex = HAL_MutexCreate(); 22 if (awss_bind_mutex == NULL) { 23 return -1; 24 } 25 } 26 27 HAL_MutexLock(awss_bind_mutex); 28 awss_cmp_online_init(); 29 HAL_MutexUnlock(awss_bind_mutex); 30 #ifdef DEVICE_MODEL_ENABLED 31 if (awss_check_reset()) { 32 return awss_report_reset_to_cloud(); 33 } 34 #endif 35 awss_start_bind(); 36 return 0; 37 } 38 awss_start_bind()39int awss_start_bind() 40 { 41 static int awss_bind_inited = 0; 42 43 if (awss_bind_mutex == NULL) { 44 awss_bind_mutex = HAL_MutexCreate(); 45 if (awss_bind_mutex == NULL) 46 return -1; 47 } 48 49 HAL_MutexLock(awss_bind_mutex); 50 if (awss_bind_inited == 1) { 51 HAL_MutexUnlock(awss_bind_mutex); 52 return 0; 53 } 54 55 awss_report_token(); 56 57 awss_cmp_local_init(AWSS_LC_INIT_BIND); 58 #ifndef DEV_BIND_DISABLE_NOTIFY 59 awss_dev_bind_notify_stop(); 60 awss_dev_bind_notify(); 61 #endif 62 #ifdef WIFI_PROVISION_ENABLED 63 #ifndef AWSS_DISABLE_REGISTRAR 64 awss_registrar_init(); 65 #endif 66 AWSS_DISP_STATIS(); 67 AWSS_REPORT_STATIS("RDA5981"); 68 #endif 69 AWSS_DB_DISP_STATIS(); 70 AWSS_DB_REPORT_STATIS("RDA5981"); 71 awss_bind_inited = 1; 72 HAL_MutexUnlock(awss_bind_mutex); 73 return 0; 74 } 75 awss_bind_deinit()76int awss_bind_deinit() 77 { 78 if (awss_bind_mutex) { 79 HAL_MutexLock(awss_bind_mutex); 80 } 81 82 #ifdef DEVICE_MODEL_ENABLED 83 awss_stop_report_reset(); 84 #endif 85 awss_stop_report_token(); 86 awss_cmp_online_deinit(); 87 #ifndef DEV_BIND_DISABLE_NOTIFY 88 awss_dev_bind_notify_stop(); 89 #endif 90 awss_cmp_local_deinit(1); 91 #ifdef WIFI_PROVISION_ENABLED 92 #ifndef AWSS_DISABLE_REGISTRAR 93 awss_registrar_deinit(); 94 #endif 95 AWSS_CLEAR_STATIS(); 96 #endif 97 AWSS_DB_CLEAR_STATIS(); 98 99 if (awss_bind_mutex) { 100 HAL_MutexUnlock(awss_bind_mutex); 101 HAL_MutexDestroy(awss_bind_mutex); 102 } 103 104 awss_bind_mutex = NULL; 105 106 return 0; 107 } 108 109 #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 110 } 111 #endif 112