• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "app_promis.h"
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 
21 #include <hi_wifi_api.h>
22 #include <hi_errno.h>
23 #include <hi_at.h>
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif
30 
31 /* Description: Packet receiving and reporting in promiscuous mode */
hi_promis_recv(void * recv_buf,int frame_len,signed char rssi)32 int hi_promis_recv(void* recv_buf, int frame_len, signed char rssi)
33 {
34     hi_at_printf("resv buf: %u , len: %d , rssi: %c\r\n", *(unsigned int*)recv_buf, frame_len, rssi);
35 
36     return HI_ERR_SUCCESS;
37 }
38 
39 /* Description: Enable the promiscuous mode */
hi_promis_start(const char * ifname)40 unsigned int hi_promis_start(const char *ifname)
41 {
42     int ret;
43     hi_wifi_ptype_filter filter = {0};
44 
45     filter.mdata_en = 1;
46     filter.udata_en = 1;
47     filter.mmngt_en = 1;
48     filter.umngt_en = 1;
49 
50     hi_wifi_promis_set_rx_callback(hi_promis_recv);
51 
52     ret = hi_wifi_promis_enable(ifname, 1, &filter);
53     if (ret != HI_ERR_SUCCESS) {
54         hi_at_printf("hi_wifi_promis_enable:: set error!\r\n");
55         return ret;
56     }
57 
58     hi_at_printf("start promis SUCCESS!\r\n");
59 
60     return HI_ERR_SUCCESS;
61 }
62 
63 /* Description: Disable the promiscuous mode */
hi_promis_stop(const char * ifname)64 unsigned int hi_promis_stop(const char *ifname)
65 {
66     int ret;
67     hi_wifi_ptype_filter filter = {0};
68 
69     ret = hi_wifi_promis_enable(ifname, 0, &filter);
70     if (ret != HI_ERR_SUCCESS) {
71         hi_at_printf("hi_wifi_promis_enable:: set error!\r\n");
72         return ret;
73     }
74 
75     hi_at_printf("stop promis SUCCESS!\r\n");
76 
77     return HI_ERR_SUCCESS;
78 }
79 
80 #ifdef __cplusplus
81 #if __cplusplus
82     }
83 #endif
84 #endif
85