blob: 604e2444f5481f2e5cd23f0429ff89705040e280
1 | #include <stdlib.h> |
2 | #include <stdio.h> |
3 | #include <stdarg.h> |
4 | #include <string.h> |
5 | |
6 | #include <sys/types.h> |
7 | #include <errno.h> |
8 | |
9 | #include <unistd.h> |
10 | |
11 | #include <sys/socket.h> |
12 | #include <netinet/in.h> |
13 | |
14 | #include <sys/un.h> |
15 | #include "pppoe_ctrl.h" |
16 | |
17 | |
18 | static char pppd_connect_cmd[512]; |
19 | static char pppoe_plugin_cmd[] = {"'pppoe -p /system/etc/ppp/pppoe.pid -I eth0 -T 80 -U -m 1412'" }; |
20 | static char pppd_options[] = {"debug logfd 1 noipdefault noauth default-asyncmap defaultroute nodetach mtu 1492 mru 1492 noaccomp nodeflate nopcomp novj novjccomp lcp-echo-interval 20 lcp-echo-failure 3"}; |
21 | |
22 | static int usage() |
23 | { |
24 | fprintf(stderr,"ppp_cli connect <user> <pwd>\n"); |
25 | fprintf(stderr,"ppp_cli disconnect\n"); |
26 | |
27 | return -1; |
28 | } |
29 | |
30 | |
31 | int main(int argc, char *argv[]) |
32 | { |
33 | int i; |
34 | struct pppoe_ctrl * ctrl; |
35 | |
36 | if (argc < 2 || (0 != strcmp( "connect", argv[1]) && |
37 | 0 != strcmp( "disconnect", argv[1]) )) { |
38 | usage(); |
39 | return -2; |
40 | } |
41 | |
42 | ctrl = pppoe_ctrl_open("/dev/socket/pppd"); |
43 | if (ctrl == NULL) { |
44 | printf("Failed to connect to pppd\n"); |
45 | return -1; |
46 | } |
47 | |
48 | if (0 == strcmp( "connect", argv[1])) { |
49 | sprintf(pppd_connect_cmd, "pppd pty %s %s user %s password %s &", |
50 | pppoe_plugin_cmd, pppd_options, argv[2], argv[3] ); |
51 | |
52 | } |
53 | else if (0 == strcmp( "disconnect", argv[1])) { |
54 | sprintf(pppd_connect_cmd, "ppp-stop"); |
55 | } |
56 | |
57 | |
58 | pppoe_ctrl_request(ctrl, pppd_connect_cmd, strlen(pppd_connect_cmd)); |
59 | |
60 | pppoe_ctrl_close(ctrl); |
61 | exit(0); |
62 | } |
63 |