wlan-ng.h File Reference

#include <wlan/p80211types.h>
#include <wlan/p80211msg.h>
#include <wlan/p80211meta.h>
#include <wlan/p80211metamsg.h>
#include <wlan/p80211metastruct.h>
#include <wlan/p80211metadef.h>
#include <wlan/p80211ioctl.h>
#include <wlan/p80211hdr.h>
#include <wlan/p80211mgmt.h>
#include <wlan/version.h>

Include dependency graph for wlan-ng.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int selectChannelWLAN (char *devname, int channel)
int shutCardWLAN (char *devname)
int openCardWLAN (char *devname)
int getPacketWLAN (p80211_caphdr_t *wlan_header, UINT8 *buf, int maxlen)
int openPacketWLAN (char *devname)
void closePacketWLAN (void)


Function Documentation

int selectChannelWLAN ( char *  devname,
int  channel 
)

Definition at line 163 of file wlan-ng.c.

References p80211msg_lnxreq_wlansniff::channel, p80211item_uint32::data, debug, p80211msg_lnxreq_wlansniff::devname, DEVNAME_LEN, p80211item_uint32::did, DIDmsg_lnxreq_wlansniff, DIDmsg_lnxreq_wlansniff_channel, DIDmsg_lnxreq_wlansniff_enable, DIDmsg_lnxreq_wlansniff_keepwepflags, DIDmsg_lnxreq_wlansniff_prismheader, DIDmsg_lnxreq_wlansniff_resultcode, do_ioctl(), p80211msg_lnxreq_wlansniff::enable, ERROR_CANT_SET_CHANNEL, fatal(), p80211msg_lnxreq_wlansniff::keepwepflags, p80211item_uint32::len, p80211msg_lnxreq_wlansniff::msgcode, p80211msg_lnxreq_wlansniff::msglen, P80211ENUM_msgitem_status_no_value, P80211ENUM_truth_false, P80211ENUM_truth_true, PrintScaleChannel(), p80211msg_lnxreq_wlansniff::prismheader, p80211msg_lnxreq_wlansniff::resultcode, ScanResult_t::SChannel, and p80211item_uint32::status.

Referenced by selectChannel().

00164 {
00165   INT result = 0;
00166 
00167 #ifdef WITH_SYSTEMCALL
00168   char CmdSystem[128];
00169 #endif
00170 
00171   debug(3, "%s#%d : devname=%s , channel=%02d\n", __FUNCTION__, __LINE__,
00172         devname, channel);
00173 
00174   PrintScaleChannel(channel);
00175 
00176   debug(3, "%s#%d : Define SChannel = %02d\n", __FUNCTION__, __LINE__,
00177         channel);
00178   Res.SChannel = channel;
00179 
00180 /*  No more stop monitor mode before change channel
00181 #ifdef LWNG_20
00182 
00183 #ifndef WITH_SYSTEMCALL
00184   // Stop Sniff function if wlan-ng driver version is greater or egual to 0.2.0
00185   memset (&lnxreq_wlansniff, 0, sizeof (p80211msg_lnxreq_wlansniff_t));
00186   lnxreq_wlansniff.msgcode = DIDmsg_lnxreq_wlansniff;
00187   lnxreq_wlansniff.msglen = sizeof (p80211msg_lnxreq_wlansniff_t);
00188   strncpy ((char *) lnxreq_wlansniff.devname, devname, DEVNAME_LEN - 1);
00189 
00190   lnxreq_wlansniff.enable.did = DIDmsg_lnxreq_wlansniff_enable;
00191   lnxreq_wlansniff.enable.data = P80211ENUM_truth_false;
00192   lnxreq_wlansniff.enable.len = 4;
00193 
00194   lnxreq_wlansniff.channel.did = DIDmsg_lnxreq_wlansniff_channel;
00195   lnxreq_wlansniff.channel.status = P80211ENUM_msgitem_status_no_value;
00196   lnxreq_wlansniff.channel.len = 4;
00197 
00198   lnxreq_wlansniff.prismheader.did = DIDmsg_lnxreq_wlansniff_prismheader;
00199   lnxreq_wlansniff.prismheader.status = P80211ENUM_msgitem_status_no_value;
00200   lnxreq_wlansniff.prismheader.len = 4;
00201 
00202   lnxreq_wlansniff.wlanheader.did = DIDmsg_lnxreq_wlansniff_wlanheader;
00203   lnxreq_wlansniff.wlanheader.status = P80211ENUM_msgitem_status_no_value;
00204   lnxreq_wlansniff.wlanheader.len = 4;
00205 
00206   lnxreq_wlansniff.keepwepflags.did = DIDmsg_lnxreq_wlansniff_keepwepflags;
00207   lnxreq_wlansniff.keepwepflags.status = P80211ENUM_msgitem_status_no_value;
00208   lnxreq_wlansniff.keepwepflags.len = 4;
00209 
00210   lnxreq_wlansniff.stripfcs.did = DIDmsg_lnxreq_wlansniff_stripfcs;
00211   lnxreq_wlansniff.stripfcs.status = P80211ENUM_msgitem_status_no_value;
00212   lnxreq_wlansniff.stripfcs.len = 4;
00213 
00214   lnxreq_wlansniff.packet_trunc.did = DIDmsg_lnxreq_wlansniff_packet_trunc;
00215   lnxreq_wlansniff.packet_trunc.status = P80211ENUM_msgitem_status_no_value;
00216   lnxreq_wlansniff.packet_trunc.len = 4;
00217 
00218   lnxreq_wlansniff.resultcode.did = DIDmsg_lnxreq_wlansniff_resultcode;
00219   lnxreq_wlansniff.resultcode.status = P80211ENUM_msgitem_status_no_value;
00220   lnxreq_wlansniff.resultcode.len = 4;
00221 
00222   result = do_ioctl (devname, (UINT8 *) & lnxreq_wlansniff, sizeof(p80211msg_lnxreq_wlansniff_t));
00223 #else
00224   sprintf (CmdSystem,
00225      "wlanctl-ng %s lnxreq_wlansniff enable=false > /dev/null",
00226      devname);
00227   result = system (CmdSystem);
00228 #endif  // WITH_SYSTEMCALL
00229 
00230   debug (3, "#%d : lnxreq_wlansniff enable=false\n", __LINE__);
00231 
00232   if (result) {
00233     warning ("Warning : Exit from monitor mode failed\n");
00234   }
00235 #endif  // LWNG_20
00236 */
00237 
00238   // Second part
00239   // put in monitor mode with the good channel
00240 
00241 #ifndef WITH_SYSTEMCALL
00242   memset(&lnxreq_wlansniff, 0, sizeof(p80211msg_lnxreq_wlansniff_t));
00243   lnxreq_wlansniff.msgcode = DIDmsg_lnxreq_wlansniff;
00244   lnxreq_wlansniff.msglen = sizeof(p80211msg_lnxreq_wlansniff_t);
00245 
00246   strncpy((char *) lnxreq_wlansniff.devname, devname, DEVNAME_LEN - 1);
00247 
00248   lnxreq_wlansniff.enable.did = DIDmsg_lnxreq_wlansniff_enable;
00249   lnxreq_wlansniff.enable.data = P80211ENUM_truth_true;
00250   lnxreq_wlansniff.enable.len = 4;
00251 
00252   lnxreq_wlansniff.channel.did = DIDmsg_lnxreq_wlansniff_channel;
00253   lnxreq_wlansniff.channel.data = channel;
00254   lnxreq_wlansniff.channel.len = 4;
00255 
00256   lnxreq_wlansniff.prismheader.did = DIDmsg_lnxreq_wlansniff_prismheader;
00257   lnxreq_wlansniff.prismheader.data = P80211ENUM_truth_true;
00258   lnxreq_wlansniff.prismheader.len = 4;
00259 
00260   lnxreq_wlansniff.keepwepflags.did = DIDmsg_lnxreq_wlansniff_keepwepflags;
00261   lnxreq_wlansniff.keepwepflags.data = P80211ENUM_truth_false;
00262   lnxreq_wlansniff.keepwepflags.len = 4;
00263 
00264   lnxreq_wlansniff.resultcode.did = DIDmsg_lnxreq_wlansniff_resultcode;
00265   lnxreq_wlansniff.resultcode.status = P80211ENUM_msgitem_status_no_value;
00266   lnxreq_wlansniff.resultcode.len = 4;
00267 
00268   result =
00269       do_ioctl(devname, (UINT8 *) & lnxreq_wlansniff,
00270                sizeof(p80211msg_lnxreq_wlansniff_t));
00271 #else
00272   sprintf(CmdSystem,
00273           "wlanctl-ng %s lnxreq_wlansniff enable=true channel=%d "
00274           "keepwepflags=false prismheader=true > /dev/null", devname,
00275           channel);
00276   result = system(CmdSystem);
00277 
00278 #endif
00279 
00280   debug(3,
00281         "%s#%d : lnxreq_wlansniff enable=true channel=%02d "
00282         "keepwepflags=false prismheader=true\n", __FUNCTION__, __LINE__,
00283         channel);
00284 
00285   // Check result
00286   if (result) {
00287     fatal
00288         (ERROR_CANT_SET_CHANNEL, "Fatal error : change to Channel %d failed (%s:%d)\n",
00289          channel, __FUNCTION__, __LINE__);
00290   }
00291 
00292   return result;
00293 }

int shutCardWLAN ( char *  devname  ) 

Definition at line 298 of file wlan-ng.c.

References p80211msg_lnxreq_wlansniff::channel, p80211item_uint32::data, debug, p80211msg_lnxreq_wlansniff::devname, DEVNAME_LEN, p80211item_uint32::did, DIDmsg_lnxreq_wlansniff, DIDmsg_lnxreq_wlansniff_channel, DIDmsg_lnxreq_wlansniff_enable, DIDmsg_lnxreq_wlansniff_resultcode, do_ioctl(), p80211msg_lnxreq_wlansniff::enable, IfconfigSetFlags(), p80211item_uint32::len, p80211msg_lnxreq_wlansniff::msgcode, p80211msg_lnxreq_wlansniff::msglen, P80211ENUM_msgitem_status_no_value, P80211ENUM_truth_false, p80211msg_lnxreq_wlansniff::resultcode, and p80211item_uint32::status.

Referenced by shutCard().

00299 {
00300   INT result = 0;
00301 #ifdef WITH_SYSTEMCALL
00302   char CmdSystem[128];
00303 #endif
00304 
00305   /* Down interface */
00306   IfconfigSetFlags(devname, 0);
00307 
00308 #ifndef WITH_SYSTEMCALL
00309   /* Stop Sniff function */
00310   memset(&lnxreq_wlansniff, 0, sizeof(p80211msg_lnxreq_wlansniff_t));
00311 
00312   lnxreq_wlansniff.msgcode = DIDmsg_lnxreq_wlansniff;
00313   lnxreq_wlansniff.msglen = sizeof(p80211msg_lnxreq_wlansniff_t);
00314 
00315   strncpy((char *) lnxreq_wlansniff.devname, devname, DEVNAME_LEN - 1);
00316 
00317   lnxreq_wlansniff.enable.did = DIDmsg_lnxreq_wlansniff_enable;
00318   lnxreq_wlansniff.enable.data = P80211ENUM_truth_false;
00319   lnxreq_wlansniff.enable.len = 4;
00320 
00321   lnxreq_wlansniff.channel.did = DIDmsg_lnxreq_wlansniff_channel;
00322   lnxreq_wlansniff.channel.status = P80211ENUM_msgitem_status_no_value;
00323   lnxreq_wlansniff.channel.len = 4;
00324 
00325   lnxreq_wlansniff.resultcode.did = DIDmsg_lnxreq_wlansniff_resultcode;
00326   lnxreq_wlansniff.resultcode.status = P80211ENUM_msgitem_status_no_value;
00327   lnxreq_wlansniff.resultcode.len = 4;
00328 
00329   result =
00330       do_ioctl(lnxreq_wlansniff.devname, (UINT8 *) & lnxreq_wlansniff,
00331                sizeof(p80211msg_lnxreq_wlansniff_t));
00332 #else
00333   sprintf(CmdSystem,
00334           "wlanctl-ng %s lnxreq_wlansniff enable=false > /dev/null",
00335           dev, channel);
00336   result = system(CmdSystem);
00337 #endif
00338 
00339   debug(3, "%s#%d : lnxreq_wlansniff enable=false\n", __FUNCTION__,
00340         __LINE__);
00341 
00342   return result;
00343 
00344 }

int openCardWLAN ( char *  devname  ) 

Definition at line 346 of file wlan-ng.c.

References p80211msg_lnxreq_wlansniff::channel, p80211item_uint32::data, debug, p80211msg_lnxreq_wlansniff::devname, p80211msg_lnxreq_ifstate::devname, DEVNAME_LEN, p80211item_uint32::did, DIDmsg_lnxreq_ifstate, DIDmsg_lnxreq_ifstate_ifstate, DIDmsg_lnxreq_ifstate_resultcode, DIDmsg_lnxreq_wlansniff, DIDmsg_lnxreq_wlansniff_channel, DIDmsg_lnxreq_wlansniff_enable, DIDmsg_lnxreq_wlansniff_resultcode, do_ioctl(), p80211msg_lnxreq_wlansniff::enable, ERROR_IF_CANT_INIT, fatal(), IfconfigSetFlags(), p80211msg_lnxreq_ifstate::ifstate, p80211item_uint32::len, p80211msg_lnxreq_wlansniff::msgcode, p80211msg_lnxreq_ifstate::msgcode, p80211msg_lnxreq_wlansniff::msglen, p80211msg_lnxreq_ifstate::msglen, P80211ENUM_ifstate_enable, P80211ENUM_msgitem_status_no_value, P80211ENUM_resultcode_refused, P80211ENUM_resultcode_success, P80211ENUM_truth_false, p80211msg_lnxreq_wlansniff::resultcode, p80211msg_lnxreq_ifstate::resultcode, p80211item_uint32::status, and warning().

Referenced by openCard().

00347 {
00348   INT result = 0;
00349 #ifdef WITH_SYSTEMCALL
00350   char CmdSystem[32];
00351 #endif
00352 
00353 #ifndef WITH_SYSTEMCALL
00354   /* put interface state UP  */
00355   memset(&lnxreq_ifstate, 0, sizeof(p80211msg_lnxreq_ifstate_t));
00356   lnxreq_ifstate.msgcode = DIDmsg_lnxreq_ifstate;
00357   lnxreq_ifstate.msglen = sizeof(p80211msg_lnxreq_ifstate_t);
00358 
00359   strncpy((char *) lnxreq_ifstate.devname, devname, DEVNAME_LEN - 1);
00360 
00361   lnxreq_ifstate.ifstate.did = DIDmsg_lnxreq_ifstate_ifstate;
00362   lnxreq_ifstate.ifstate.len = 4;
00363   lnxreq_ifstate.ifstate.data = P80211ENUM_ifstate_enable;
00364 
00365   lnxreq_ifstate.resultcode.did = DIDmsg_lnxreq_ifstate_resultcode;
00366   lnxreq_ifstate.resultcode.len = 4;
00367   lnxreq_ifstate.resultcode.status = P80211ENUM_msgitem_status_no_value;
00368 
00369   result =
00370       do_ioctl(devname, (UINT8 *) & lnxreq_ifstate,
00371                sizeof(p80211msg_lnxreq_ifstate_t));
00372 #else
00373   sprintf(CmdSystem,
00374           "wlanctl-ng %s lnxreq_ifstate ifstate=enable > /dev/null",
00375           dev, channel);
00376   result = system(CmdSystem);
00377 #endif
00378 
00379   debug(3, "%s#%d : lnxreq_ifstate ifstate=enable\n", __FUNCTION__,
00380         __LINE__);
00381   // Check result
00382   if (result) {
00383     fatal(ERROR_IF_CANT_INIT, "Warning : Change state of interface to enable failed\n");
00384   }
00385 #ifndef WITH_SYSTEMCALL
00386 
00387   /* Stop Sniff function */
00388   memset(&lnxreq_wlansniff, 0, sizeof(p80211msg_lnxreq_wlansniff_t));
00389   lnxreq_wlansniff.msgcode = DIDmsg_lnxreq_wlansniff;
00390   lnxreq_wlansniff.msglen = sizeof(p80211msg_lnxreq_wlansniff_t);
00391 
00392   strncpy((char *) lnxreq_wlansniff.devname, devname, DEVNAME_LEN - 1);
00393 
00394   lnxreq_wlansniff.enable.did = DIDmsg_lnxreq_wlansniff_enable;
00395   lnxreq_wlansniff.enable.data = P80211ENUM_truth_false;
00396   lnxreq_wlansniff.enable.len = 4;
00397 
00398   lnxreq_wlansniff.channel.did = DIDmsg_lnxreq_wlansniff_channel;
00399   lnxreq_wlansniff.channel.status = P80211ENUM_msgitem_status_no_value;
00400   lnxreq_wlansniff.channel.len = 4;
00401 
00402   lnxreq_wlansniff.resultcode.did = DIDmsg_lnxreq_wlansniff_resultcode;
00403   lnxreq_wlansniff.resultcode.status = P80211ENUM_msgitem_status_no_value;
00404   lnxreq_wlansniff.resultcode.len = 4;
00405 
00406   result =
00407       do_ioctl(devname, (UINT8 *) & lnxreq_wlansniff,
00408                sizeof(p80211msg_lnxreq_wlansniff_t));
00409 #else
00410   sprintf(CmdSystem,
00411           "wlanctl-ng %s lnxreq_wlansniff enable=false channel= > /dev/null");
00412   result = system(CmdSystem);
00413 #endif
00414   debug(3, "%s#%d : lnxreq_wlansniff enable=false channel= \n",
00415         __FUNCTION__, __LINE__);
00416   if ((result)
00417       && (lnxreq_wlansniff.msgcode != P80211ENUM_resultcode_success)
00418       && (lnxreq_wlansniff.msgcode != P80211ENUM_resultcode_refused)) {
00419     warning("Warning : Exit from monitor mode failed\n");
00420   }
00421   // Put no IP, so better hide from hell ;)
00422   // put interface up with addresse 0
00423   result += IfconfigSetFlags(devname, IFF_UP);
00424 
00425   return result;
00426 }

int getPacketWLAN ( p80211_caphdr_t wlan_header,
UINT8 buf,
int  maxlen 
)

Definition at line 430 of file wlan-ng.c.

References CaptureArg_t::DataLink, debug, FillRadioData(), MAX_BUFFER_SIZE, MAX_OF, memcpy_buff(), MIN_OF, CaptureArg_t::offset, and CaptureArg_t::pcap.

Referenced by getPacket().

00431 {
00432   struct pcap_pkthdr pktHdr;
00433   u_char *RadioPacket;
00434   fd_set rs;
00435   // p80211msg_lnxind_wlansniffrm_t *Sniff_Frame;
00436 
00437   FD_ZERO(&rs);
00438   FD_SET(0, &rs);
00439 
00440   RadioPacket = (u_char *) pcap_next(ca.pcap, &pktHdr);
00441 
00442   //DEBUG 
00443   if (RadioPacket != NULL) {
00444     debug(3, "RadioPacket= %x  - pktHdr.len = %x\n", RadioPacket,
00445           pktHdr.len);
00446 
00447     // If no problem and packet is enought big (with data)
00448     if (pktHdr.len >= sizeof(p80211msg_lnxind_wlansniffrm_t)) {
00449       if (pktHdr.len > MAX_BUFFER_SIZE) {
00450         debug(1, "ERROR : Packet is TOOO BIG size=%d\n", pktHdr.len);
00451         // Sometimes Wlan-NG return an enormous empty packet ...
00452         //DumpHexPaquets(RealTime_WND, buf, 0x1B0);
00453         return 0;
00454       } else {
00455         FillRadioData(&wlan_header, ca.DataLink, RadioPacket, pktHdr.len);
00456         memcpy_buff(buf, RadioPacket + ca.offset,
00457                     MIN_OF((pktHdr.len - ca.offset), maxlen));
00458         return MAX_OF(0,
00459                       (pktHdr.len -
00460                        sizeof(p80211msg_lnxind_wlansniffrm_t)));
00461       }
00462     }
00463   }
00464   return (0);                   /* Noting to read */
00465 }

int openPacketWLAN ( char *  devname  ) 

Definition at line 469 of file wlan-ng.c.

References CalculateOffset(), CaptureArg_t::DataLink, errbuf, ERROR_CANT_OPEN_PCAP, NO_ERROR, CaptureArg_t::offset, and CaptureArg_t::pcap.

Referenced by openPacket().

00470 {
00471   ca.pcap = pcap_open_live(devname, 3000, 1, 1, errbuf);
00472   if (ca.pcap) {
00473     pcap_setnonblock(ca.pcap, 1, errbuf);
00474     ca.DataLink = pcap_datalink(ca.pcap);
00475     ca.offset = CalculateOffset(ca.DataLink);
00476     return NO_ERROR;
00477   }
00478   return ERROR_CANT_OPEN_PCAP;
00479 }

void closePacketWLAN ( void   ) 

Definition at line 482 of file wlan-ng.c.

References CaptureArg_t::pcap.

Referenced by closePacket().

00483 {
00484   pcap_close(ca.pcap);
00485 }


Generated on Fri Jul 25 17:11:28 2008 for WifiScanner by  doxygen 1.5.5