-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | 66 | ||||
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | 3 |
2 files changed, 62 insertions, 7 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc index d462488..def1a4b 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | |||
@@ -26,56 +26,108 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) | |||
26 | wl_logerr("Cannot set interface to promisc mode: %s", strerror(errno)); | 26 | wl_logerr("Cannot set interface to promisc mode: %s", strerror(errno)); |
27 | return 0; | 27 | return 0; |
28 | } | 28 | } |
29 | wl_loginfo("Interface set to promisc mode"); | 29 | wl_loginfo("Interface set to promisc mode"); |
30 | 30 | ||
31 | /* Check the cardtype and executes the commands to go into monitor mode */ | 31 | /* Check the cardtype and executes the commands to go into monitor mode */ |
32 | if (cardtype == CARD_TYPE_CISCO) | 32 | if (cardtype == CARD_TYPE_CISCO) |
33 | { | 33 | { |
34 | /* bring the sniffer into rfmon mode */ | 34 | /* bring the sniffer into rfmon mode */ |
35 | snprintf(CiscoRFMON, sizeof(CiscoRFMON) - 1, DEFAULT_PATH, device); | 35 | snprintf(CiscoRFMON, sizeof(CiscoRFMON) - 1, DEFAULT_PATH, device); |
36 | if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL) | 36 | if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL) |
37 | { | 37 | { |
38 | wl_logerr("Cannot open config file: %s", strerror(errno)); | 38 | wl_logerr("Cannot open config file: %s", strerror(errno)); |
39 | return 0; | 39 | return 0; |
40 | } | 40 | } |
41 | fputs ("Mode: r",CISCO_CONFIG_FILE); | 41 | fputs ("Mode: r",CISCO_CONFIG_FILE); |
42 | fputs ("Mode: y",CISCO_CONFIG_FILE); | 42 | fputs ("Mode: y",CISCO_CONFIG_FILE); |
43 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); | 43 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); |
44 | fclose(CISCO_CONFIG_FILE); | 44 | fclose(CISCO_CONFIG_FILE); |
45 | } | 45 | } |
46 | else if (cardtype == CARD_TYPE_NG) | 46 | else if (cardtype == CARD_TYPE_NG) |
47 | { | 47 | { |
48 | char wlanngcmd[62]; | 48 | char wlanngcmd[62]; |
49 | snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device); | 49 | snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device); |
50 | if (system(wlanngcmd) != 0) | 50 | if (system(wlanngcmd) != 0) |
51 | { | 51 | { |
52 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 52 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
53 | return 0; | 53 | return 0; |
54 | } | 54 | } |
55 | } | 55 | } |
56 | else if (cardtype == CARD_TYPE_HOSTAP) | 56 | else if (cardtype == CARD_TYPE_HOSTAP) |
57 | { | 57 | { |
58 | wl_logerr("Got a host-ap card, nothing is implemented now"); | 58 | wl_logerr("Got a host-ap card, nothing is implemented now"); |
59 | char hostapcmd[250]; | 59 | char hostapcmd[250]; |
60 | snprintf(hostapcmd, sizeof(hostapcmd) -1, "%s %s monitor 2", IWPRIV_PATH, device); | 60 | snprintf(hostapcmd, sizeof(hostapcmd) -1, "%s %s monitor 2", IWPRIV_PATH, device); |
61 | if (system(hostapcmd) !=0) | 61 | if (system(hostapcmd) !=0) |
62 | { | 62 | { |
63 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 63 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
64 | return 0; | 64 | return 0; |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | return 1; | 68 | return 1; |
69 | } | 69 | } |
70 | 70 | ||
71 | /* Set card into promisc mode */ | 71 | /* Set card into promisc mode */ |
72 | int card_set_promisc_up (const char *device) | 72 | int card_set_promisc_up (const char *device) |
73 | { | 73 | { |
74 | char ifconfigcmd[48]; | 74 | struct ifconf ifc; |
75 | int retval=0; | 75 | struct ifreq ifr_x[50]; |
76 | 76 | u_int i; | |
77 | snprintf(ifconfigcmd, sizeof(ifconfigcmd) - 1, SBIN_PATH, device); | 77 | int sockfd, err; |
78 | retval = system(ifconfigcmd); | 78 | err=0; |
79 | 79 | /* opening a socket for issuing the iocalls */ | |
80 | return (retval ? 0 : 1); | 80 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); |
81 | |||
82 | if (sockfd < 0) | ||
83 | { | ||
84 | /* In case of an error - mjm proove that please*/ | ||
85 | perror("socket"); | ||
86 | return 1; | ||
87 | } | ||
88 | /* Define room for 50 interfaces */ | ||
89 | ifc.ifc_len = 50 * sizeof(struct ifreq); | ||
90 | ifc.ifc_req = ifr_x; | ||
91 | /* Get the config of the interfaces */ | ||
92 | err = ioctl(sockfd, SIOCGIFCONF, &ifc); | ||
93 | if (err == -1) return 1; | ||
94 | |||
95 | /* For each interface*/ | ||
96 | for (i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) | ||
97 | { | ||
98 | /* To complete , should get the IP, if no is assigned, asign one */ | ||
99 | /*err = ioctl(sockfd, SIOCGIFADDR, &ifr_x[i]); | ||
100 | if (err == -1) perror("SIOCGIFADDR: "); | ||
101 | printf ("Address: %s\n",Sock_ntop_host(ifr_x[i].ifr_addr.sa_family,sizeof(ifr_x[i].ifr_addr.sa_family))); | ||
102 | */ | ||
103 | if(strncmp(ifr_x[i].ifr_name,device,5) == 0) | ||
104 | { | ||
105 | /* Get the flags */ | ||
106 | err = ioctl(sockfd, SIOCGIFFLAGS, &ifr_x[i]); | ||
107 | if (err == -1) | ||
108 | { | ||
109 | perror("SIOCGIFFLAGS: "); | ||
110 | return 1; | ||
111 | } | ||
112 | /* Check if the Interface is UP and PROMISC */ | ||
113 | if (ifr_x[i].ifr_flags & IFF_PROMISC && ifr_x[i].ifr_flags & IFF_UP) | ||
114 | { | ||
115 | /* only debug text */ | ||
116 | printf ("%s is PROMISC and UP \n",ifr_x[i].ifr_name); | ||
117 | } | ||
118 | else | ||
119 | { | ||
120 | /* Set the promisc flag to the interface */ | ||
121 | ifr_x[i].ifr_flags=ifr_x[i].ifr_flags+IFF_PROMISC; | ||
122 | err = ioctl(sockfd, SIOCSIFFLAGS, &ifr_x[i]); | ||
123 | if (err == -1) | ||
124 | { | ||
125 | /* Could not set the interface into promisc mode */ | ||
126 | perror("SIOCSIFFLAGS: "); | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | /* All is fine */ | ||
132 | return 0; | ||
81 | } | 133 | } |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh index 9721b39..7678202 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | |||
@@ -1,37 +1,40 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef CARDMODE_HH | 3 | #ifndef CARDMODE_HH |
4 | #define CARDMODE_HH | 4 | #define CARDMODE_HH |
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <errno.h> | 8 | #include <errno.h> |
9 | #include <sys/types.h> | 9 | #include <sys/types.h> |
10 | #include <sys/time.h> | 10 | #include <sys/time.h> |
11 | #include <sys/socket.h> | 11 | #include <sys/socket.h> |
12 | #include <netinet/in.h> | 12 | #include <netinet/in.h> |
13 | #include <sys/ioctl.h> | ||
14 | #include <linux/if.h> | ||
15 | |||
13 | 16 | ||
14 | extern "C" | 17 | extern "C" |
15 | { | 18 | { |
16 | #include <net/bpf.h> | 19 | #include <net/bpf.h> |
17 | #include <pcap.h> | 20 | #include <pcap.h> |
18 | } | 21 | } |
19 | 22 | ||
20 | /* Defines, used for the card setup */ | 23 | /* Defines, used for the card setup */ |
21 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" | 24 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" |
22 | #define CARD_TYPE_CISCO1 | 25 | #define CARD_TYPE_CISCO1 |
23 | #define CARD_TYPE_NG 2 | 26 | #define CARD_TYPE_NG 2 |
24 | #define CARD_TYPE_HOSTAP3 | 27 | #define CARD_TYPE_HOSTAP3 |
25 | 28 | ||
26 | /* only for now, until we have the daemon running */ | 29 | /* only for now, until we have the daemon running */ |
27 | /*the config file should provide these information */ | 30 | /*the config file should provide these information */ |
28 | #define CARD_TYPE CARD_TYPE_HOSTAP | 31 | #define CARD_TYPE CARD_TYPE_HOSTAP |
29 | #define SBIN_PATH "/sbin/ifconfig %s promisc up" | 32 | #define SBIN_PATH "/sbin/ifconfig %s promisc up" |
30 | #define WLANCTL_PATH "/sbin/wlanctl-ng" | 33 | #define WLANCTL_PATH "/sbin/wlanctl-ng" |
31 | #define IWPRIV_PATH "/sbin/iwpriv" | 34 | #define IWPRIV_PATH "/sbin/iwpriv" |
32 | 35 | ||
33 | /* Prototypes */ | 36 | /* Prototypes */ |
34 | int card_into_monitormode (pcap_t **, char *, int); | 37 | int card_into_monitormode (pcap_t **, char *, int); |
35 | int card_set_promisc_up (const char *); | 38 | int card_set_promisc_up (const char *); |
36 | 39 | ||
37 | #endif /* CARDMODE_HH */ | 40 | #endif /* CARDMODE_HH */ |