| 1059 | } |
| 1060 | |
| 1061 | rt_err_t rt_wlan_disconnect(void) |
| 1062 | { |
| 1063 | rt_err_t err; |
| 1064 | struct rt_wlan_complete_des *complete; |
| 1065 | rt_uint32_t recved = 0, set = 0; |
| 1066 | |
| 1067 | /* ap dev Can't be empty */ |
| 1068 | if (_sta_is_null()) |
| 1069 | { |
| 1070 | return -RT_EIO; |
| 1071 | } |
| 1072 | RT_WLAN_LOG_D("%s is run", __FUNCTION__); |
| 1073 | |
| 1074 | /* run disconnect */ |
| 1075 | MGNT_LOCK(); |
| 1076 | /* create event wait complete */ |
| 1077 | complete = rt_wlan_complete_create("disc"); |
| 1078 | if (complete == RT_NULL) |
| 1079 | { |
| 1080 | MGNT_UNLOCK(); |
| 1081 | return -RT_ENOMEM; |
| 1082 | } |
| 1083 | err = rt_wlan_dev_disconnect(_sta_mgnt.device); |
| 1084 | if (err != RT_EOK) |
| 1085 | { |
| 1086 | RT_WLAN_LOG_E("wifi disconnect fail"); |
| 1087 | rt_wlan_complete_delete(complete); |
| 1088 | MGNT_UNLOCK(); |
| 1089 | return err; |
| 1090 | } |
| 1091 | /* Initializing events that need to wait */ |
| 1092 | set |= 0x1 << RT_WLAN_DEV_EVT_DISCONNECT; |
| 1093 | /* Check whether there is a waiting event */ |
| 1094 | rt_wlan_complete_wait(complete, set, RT_WLAN_CONNECT_WAIT_MS, &recved); |
| 1095 | rt_wlan_complete_delete(complete); |
| 1096 | /* check event */ |
| 1097 | set = 0x1 << RT_WLAN_DEV_EVT_DISCONNECT; |
| 1098 | if (!(recved & set)) |
| 1099 | { |
| 1100 | RT_WLAN_LOG_E("disconnect failed!"); |
| 1101 | MGNT_UNLOCK(); |
| 1102 | return -RT_ERROR; |
| 1103 | } |
| 1104 | RT_WLAN_LOG_I("disconnect success!"); |
| 1105 | MGNT_UNLOCK(); |
| 1106 | return err; |
| 1107 | } |
| 1108 | |
| 1109 | rt_bool_t rt_wlan_is_connected(void) |
| 1110 | { |
no test coverage detected