hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<sys/time.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<fcntl.h>
#include<pthread.h>
#define MAXLINE 4096
 
static void prepare_set_wifi(void)
{
    int fd, size;
    char buf[200];
 
    fd = open("/proc/tcp_params", O_RDONLY);
 
    memset(buf, 0, 200);
    size = read(fd, buf, 200);
 
    system(buf);
    usleep(300 * 100);
    system("dhd_priv wl tcpka_conn_sess_info 1");
    usleep(300 * 100);
    system("dhd_priv wl tcpka_conn_dump 1");
 
}
 
int main(int argc, char** argv)
{
    int   sockfd, n;
    char  recvline[4096], sendline[4096];
    struct sockaddr_in  servaddr;
   int fd, size, send_count = 0;
   char buf[200];
   char recvbuffer[200];
   char sendbuf[2] = {0xc0, 0x00};
 
    if( argc != 2){
        printf("usage: ./client <ipaddress>\n");
        return 0;
    }
 
    if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
        printf("create socket error: %s(errno: %d)\n", strerror(errno),errno);
        return 0;
    }
 
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(5150);
    if ( inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0) {
        printf("inet_pton error for %s\n",argv[1]);
        return 0;
    }
 
    char timestamp = 0;
    setsockopt(sockfd, SOL_SOCKET, SO_TIMESTAMP, (const char*)&timestamp, sizeof(char));
 
    if (connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0) {
        printf("connect error: %s (errno: %d)\n",strerror(errno),errno);
        return 0;
    }
 
    prepare_set_wifi();
 
    printf("connected to server \n");
 
    while (1) {
       if (send_count == 5) {
            system("dhd_priv wl tcpka_conn_sess_info 1");
            usleep(100 * 100);
            system("dhd_priv wl tcpka_conn_dump 0");
            usleep(100 * 100);
            system("dhd_priv wl tcpka_conn_enable 1 1 30 3 8");
            usleep(100 * 100);
            system("dhd_priv setsuspendmode 1");
            usleep(100 * 100);
            system("tb_poweroff &");
            while(1);
        }
 
        if (send(sockfd, "hellp tcp", 9, 0) != 9) {
           printf("send msg error: %s(errno: %d)\n", strerror(errno), errno);
           return 0;
        }
        send_count++;
        sleep(1);
    }
    close(sockfd);
    return 0;
}