xref: /OK3568_Linux_fs/yocto/meta-rockchip/recipes-devtools/brcm-tools/files/dhd_priv.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <sys/ioctl.h>
9 #include <linux/socket.h>
10 #include <netpacket/packet.h>
11 #include <net/if.h>
12 
13 #define VERSION	"1.2"
14 
15 #define TAG "dhd_priv: "
16 #if defined(ANDROID)
17 #include <signal.h>
18 #include <unistd.h>
19 #include <errno.h>
20 #include <fcntl.h>
21 #include "cutils/misc.h"
22 #include "cutils/log.h"
23 #define DHD_PRINTF(...) {__android_log_print(ANDROID_LOG_DEBUG,TAG ,__VA_ARGS__); printf(__VA_ARGS__);}
24 #else
25 #define DHD_PRINTF printf
26 #endif
27 
28 typedef struct dhd_priv_cmd {
29 	char *buf;
30 	int used_len;
31 	int total_len;
32 } dhd_priv_cmd;
33 
34 /*
35 terence 20161127
36 */
37 
38 int
main(int argc,char ** argv)39 main(int argc, char **argv)
40 {
41 	struct ifreq ifr;
42 	dhd_priv_cmd priv_cmd;
43 	int ret = 0;
44 	int ioctl_sock; /* socket for ioctl() use */
45 	char buf[500]="";
46 	int i=0;
47 
48 	DHD_PRINTF(TAG "Version = %s\n", VERSION);
49 
50 	DHD_PRINTF("argv: ");
51 	while (argv[i]) {
52 		DHD_PRINTF("%s ", argv[i]);
53 		i++;
54 	}
55 	DHD_PRINTF("\n");
56 
57 	if (!argv[1]) {
58 		DHD_PRINTF("Please input right cmd\n");
59 		return 0;
60 	}
61 
62 	while (*++argv) {
63 		strcat(buf, *argv);
64 		if (*(argv+1))
65 			strcat(buf, " ");
66 	}
67 
68 	ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
69 	if (ioctl_sock < 0) {
70 		DHD_PRINTF(TAG "socket(PF_INET,SOCK_DGRAM)\n");
71 		return -1;
72 	}
73 
74 	memset(&ifr, 0, sizeof(ifr));
75 	memset(&priv_cmd, 0, sizeof(priv_cmd));
76 	strncpy(ifr.ifr_name, "wlan0", sizeof(ifr.ifr_name));
77 
78 	priv_cmd.buf = buf;
79 	priv_cmd.used_len = 500;
80 	priv_cmd.total_len = 500;
81 	ifr.ifr_data = &priv_cmd;
82 
83 	if ((ret = ioctl(ioctl_sock, SIOCDEVPRIVATE + 1, &ifr)) < 0) {
84 		DHD_PRINTF(TAG "failed to issue private commands %d\n", ret);
85 	} else {
86 		DHD_PRINTF(TAG "buf = %s, len = %d, ret = %d\n", buf, strlen(buf), ret);
87 	}
88 
89 	close(ioctl_sock);
90 	return ret;
91 }
92 
93