//////////////////////////////////////////////////////////////////////// // getTxFrequenciesByName //////////////////////////////////////////////////////////////////////// // Gets the list of supported Tx channels. // // Params: name - The formal name of the device. // frequencyList - The array of supported channels // numFrequencies - The number of elements in the frequencyList // array. Also the number of Tx channels the // device supports. // // Returns - True on success, False otherwise. //////////////////////////////////////////////////////////////////////// boolean getTxFrequenciesByName(PCHAR name, PUINT *frequencyList, PUINT numFrequencies) { PAirpcapHandle Ad; CHAR Ebuf[AIRPCAP_ERRBUF_SIZE]; boolean response; // // Open the device // Ad = AirpcapOpen(name, Ebuf); if(!Ad) { printf("Error opening the adapter: %s\n", Ebuf); frequencyList = NULL; *numFrequencies = 0; return FALSE; } // // Toss the request over to the sister function for processing. // response = getTxFrequenciesByHandle(Ad, frequencyList, numFrequencies); // // Make sure to close the adapter we opened. // AirpcapClose(Ad); return response; }
int cygwin_init(char *param) { char * iface; char errbuf[AIRPCAP_ERRBUF_SIZE ]; iface = (char *)calloc(1, strlen(param) + strlen(DEVICE_HEADER) +1); strcpy (iface, DEFAULT_ADAPT_NAME); if (param) { // if it's empty, use the default adapter if (strlen(param) > 0) { // Make sure the adapter name contains the '\\.\' at its begining memset(iface, 0, strlen(param) + strlen(DEVICE_HEADER) +1); if (strstr(param, DEVICE_HEADER) == NULL) { // Not found, add it strcpy(iface, DEVICE_HEADER); strcat(iface, param); } else { // Already contains the adapter header strcpy(iface, param); } } } airpcap_handle = AirpcapOpen(iface, errbuf); if(airpcap_handle == NULL) { fprintf( stderr, "This adapter doesn't have wireless extensions. Quitting\n"); //pcap_close( winpcap_adapter ); return( -1 ); } /* Tell the adapter that the packets we'll send and receive don't include the FCS */ if(!AirpcapSetFcsPresence(airpcap_handle, FALSE)) return printErrorCloseAndReturn("Error setting FCS presence: %s\n", -1); /* Set the link layer to bare 802.11 */ if(!AirpcapSetLinkType(airpcap_handle, AIRPCAP_LT_802_11)) return printErrorCloseAndReturn("Error setting the link type: %s\n", -1); /* Accept correct frames only */ if( !AirpcapSetFcsValidation(airpcap_handle, AIRPCAP_VT_ACCEPT_CORRECT_FRAMES) ) return printErrorCloseAndReturn("Error setting FCS validation: %s\n", -1); /* Set a low mintocopy for better responsiveness */ if(!AirpcapSetMinToCopy(airpcap_handle, 1)) return printErrorCloseAndReturn("Error setting MinToCopy: %s\n", -1); return 0; }
//////////////////////////////////////////////////////////////////////// // isTxAdapter //////////////////////////////////////////////////////////////////////// // Determines whether a given device supports Tx or not. // // Params: Name - The formal name of the device. // // Returns - True if the given device supports Tx, false otherwise. //////////////////////////////////////////////////////////////////////// boolean isTxAdapter(PCHAR Name) { PAirpcapHandle Ad; CHAR Ebuf[AIRPCAP_ERRBUF_SIZE]; PAirpcapChannelInfo frequencyList, tmpFrequency; UINT numFrequencies; UINT i; // // Always return false for the Multi-Channel Aggregator // if (strncmp(Name, "\\\\.\\airpcap_any", 16) == 0) return FALSE; // // Open adapter // Ad = AirpcapOpen(Name, Ebuf); if(!Ad) { printf("Error opening the adapter: %s\n", Ebuf); return FALSE; } // // Get the list of supported channels. This returns an array of structs // that contains a flag for Tx. // if (!AirpcapGetDeviceSupportedChannels(Ad, &frequencyList, &numFrequencies)) { printf("Error retrieving list of supported channels for adapter %s\n", Name); AirpcapClose(Ad); return FALSE; } // // Loop through the array of returned channels and look for one thats // supports Tx. // for(i=0; i<numFrequencies; i++) { tmpFrequency = frequencyList + i; if (tmpFrequency->Flags & AIRPCAP_CIF_TX_ENABLED) { AirpcapClose(Ad); return TRUE; } } // // No channels supported Tx. // AirpcapClose(Ad); return FALSE; }
int airpcap_open(struct tx80211 *in_tx) { struct airpcap_data *apcap = in_tx->extra; apcap->ad = AirpcapOpen(in_tx->ifname, apcap->errstr); if (apcap->ad == NULL) { snprintf(in_tx->errstr, TX80211_STATUS_MAX, "Unable to open airpcap interface: %s", apcap->errstr); return TX80211_ENOOPENINT; } /* Set the link type to standard 802.11 header */ if (!AirpcapSetLinkType(apcap->ad, AIRPCAP_LT_802_11_PLUS_RADIO)) { snprintf(in_tx->errstr, TX80211_STATUS_MAX, "Unable to set airpcap link type: %s", AirpcapGetLastError(apcap->ad)); return TX80211_ENOOPENINT; } return TX80211_ENOERR; }
int tx80211_airpcap_init(struct tx80211 *in_tx) { struct airpcap_data *apcap = in_tx->extra; in_tx->capabilities = tx80211_airpcap_capabilities(); in_tx->open_callthrough = &airpcap_open; in_tx->close_callthrough = &airpcap_close; in_tx->setmode_callthrough = &airpcap_setmode; in_tx->getmode_callthrough = &airpcap_getmode; in_tx->getchan_callthrough = &airpcap_getchannel; in_tx->setchan_callthrough = &airpcap_setchannel; in_tx->txpacket_callthrough = &airpcap_send; in_tx->setfuncmode_callthrough = &airpcap_setfuncmode; in_tx->selfack_callthrough = NULL; /* Allocate memory for the airpcap_data structure */ in_tx->extra = malloc(sizeof(struct airpcap_data)); if (in_tx->extra == NULL) { snprintf(in_tx->errstr, TX80211_STATUS_MAX, "Unable to allocate memory for initialization data."); return TX80211_ENOMEM; } apcap = in_tx->extra; apcap->ad = AirpcapOpen(in_tx->ifname, apcap->errstr); if(!apcap->ad) { snprintf(in_tx->errstr, TX80211_STATUS_MAX, "Error opening the adapter: %s\n", apcap->errstr); return -1; } return TX80211_ENOERR; }
//////////////////////////////////////////////////////////////////////// // getAirPcapAdapter //////////////////////////////////////////////////////////////////////// // Lists the adapters and asks the user to select and adapter and a // frequency. // // Returns - Handle to the selected adapter with the channel already // set and PPI selected. //////////////////////////////////////////////////////////////////////// PAirpcapHandle getAirPcapAdapter() { PAirpcapHandle Ad; CHAR Ebuf[AIRPCAP_ERRBUF_SIZE]; UINT freq_chan = 8; UINT i, Inum, range; AirpcapDeviceDescription *AllDevs, *TmpDev; AirpcapChannelInfo tchaninfo; // // Get the device list // if(!AirpcapGetDeviceList(&AllDevs, Ebuf)) { printf("Unable to retrieve the device list: %s\n", Ebuf); return NULL; } // // Make sure that the device list is valid // if(AllDevs == NULL) { printf("No interfaces found! Make sure the airpcap software is installed and your adapter is properly plugged in.\n"); return NULL; } // // Print the list // for(TmpDev = AllDevs, i = 0; TmpDev; TmpDev = TmpDev->next) { printf("%d. ", ++i); // // If the adapter is a Tx adapter, say so. // if (isTxAdapter(TmpDev->Name)) { printf("Tx - "); } // // Print adapter name and description // printf("%s", TmpDev->Name); if(TmpDev->Description) { printf(" (%s)\n", TmpDev->Description); } else { printf(" (No description available)\n"); } } printf("\n"); // // Store the range of valid adapters for future use. // range = i; // // If there are no valid adapters // if(range == 0) { printf("\nNo interfaces found! Make sure the airpcap software is installed and your adapter is properly plugged in.\n"); AirpcapFreeDeviceList(AllDevs); return NULL; } // // Loop because the user may have selected an invalid adapter. // while (1) { // // Ask for the user to select an adapter. // printf("Enter the adapter number (1-%d): ",range); flushall(); /* kill any characters left in buffer */ scanf("%d", &Inum); // // Check if the user specified a valid adapter // if(Inum < 1 || Inum > range) { printf("Error: Invalid adapter selection.\n\n"); continue; } // // Jump to the selected adapter // for(TmpDev = AllDevs, i = 0; i < Inum-1 ;TmpDev = TmpDev->next, i++); // // Make sure the adapter is a Tx capable one. // if (!isTxAdapter(TmpDev->Name)) { printf("Error: The selected adapter does not support transmission.\n\n"); } else { break; } } // // Loop, as the user may specify an invalid channel. // while (1) { // // Ask for a channel to listen to // printf("Enter the channel or frequency: ",i); scanf("%d", &freq_chan); // // Check if the user specified a valid channel // if(freq_chan < 1 || freq_chan > 8000) { printf("\nChannel or frequency out of range.\n"); AirpcapFreeDeviceList(AllDevs); return NULL; } // // Make sure the user picked a valid Tx channel. // if (!isTxFrequencySupported(TmpDev->Name, freq_chan)) { printf("\nThe selected frequency does not support transmission.\nPlease select from the list of supported channels below:\n\n"); // // Print the list of channels the adapter supports Tx on. // printTxFrequenciesByName(TmpDev->Name); printf("\n\n"); } else { break; } } // // Open the adapter // Ad = AirpcapOpen(TmpDev->Name, Ebuf); if(!Ad) { printf("Error opening the adapter: %s\n", Ebuf); return NULL; } // // We don't need the device list any more, free it // AirpcapFreeDeviceList(AllDevs); // // Set the link layer to 802.11 plus PPI headers // if(!AirpcapSetLinkType(Ad, AIRPCAP_LT_802_11_PLUS_PPI)) { printf("Error setting the link layer: %s\n", AirpcapGetLastError(Ad)); AirpcapClose(Ad); return NULL; } // Set the channel. // If the user provides a value below 500, we assume it's a channel number, otherwise we assume it's a frequency. if(freq_chan < 500) { if(!AirpcapSetDeviceChannel(Ad, freq_chan)) { printf("Error setting the channel: %s\n", AirpcapGetLastError(Ad)); AirpcapClose(Ad); return NULL; } } else { memset(&tchaninfo, sizeof(tchaninfo), 0); tchaninfo.Frequency = freq_chan; if(!AirpcapSetDeviceChannelEx(Ad, tchaninfo)) { printf("Error setting the channel: %s\n", AirpcapGetLastError(Ad)); AirpcapClose(Ad); return NULL; } } return Ad; }