Content-type: text/html Manpage of LORCON

LORCON

Section: C Library Functions (3)
Updated: 01 November 2006
Index Return to Main Contents
 

NAME

LORCON - 802.11 Wireless Packet Injection Library  

SYNOPSIS

#include <tx80211.h>
#include <tx80211_packet.h>

struct tx80211_cardlist *tx80211_getcardlist()
void tx80211_freecardlist(struct tx80211_cardlist *in_list)

int tx80211_getversion()

int tx80211_resolvecard(const char *in_str)

int tx80211_init(struct tx80211 *in_tx, const char *in_ifname, 

        int in_injector)
char * tx80211_geterrstr(struct tx80211 *in_tx) int tx80211_getcapabilities(struct tx80211 *in_tx) int tx80211_open(struct tx80211 *in_tx) int tx80211_setmode(struct tx80211 *in_tx, int in_mode) /* superceded */ int tx80211_getmode(struct tx80211 *in_tx) int tx80211_setfunctionalmode(struct tx80211 *in_tx, int in_fmode) int tx80211_setchannel(struct tx80211 *in_tx, int in_chan) int tx80211_getchannel(struct tx80211 *in_tx) int tx80211_txpacket(struct tx80211 *in_tx,
        struct tx80211_packet *in_packet)
int tx80211_close(struct tx80211 *in_tx)

 

DESCRIPTION

LORCON - Loss Of Radio CONnectivity

The LORCON packet injection library provides a high level interface to transmit IEEE 802.11 packets onto a wireless medium. Written for Linux systems, this architecture simplifies the development of 802.11 packet injection through an abstraction layer, making the development of auditing and assessment tools driver- independent. Using LORCON, developers can write tools that inject packets onto the wireless network without writing driver-specific code, simply by asking the user to identify the driver name they are currently using for a specified interface.

 

ROUTINES

tx80211_getversion() is used to return the LORCON internal version, of the format YYYYMMRR (year-month-release#)

tx80211_getcardlist() is used to obtain a list of supported wireless drivers by the LORCON architecture, with a driver description and capability information. This function allocates memory to populate a pointer of type tx80211_cardlist , returning NULL on error.

tx80211_freecardlist() is used to free the tx80211_cardlist pointer populated by tx80211_getcardlist(). in_list is the populated tx80211_cardlist pointer.

tx80211_resolvecard() is used to resolve the driver type being used from a specified string. in_str is a case-insensitive string (usually specified by the user on the command-line) describing the driver that they wish to use for packet injection. Supported driver names include:

INJ_WLANNG
Indicates the wlan-ng driver available at ftp://ftp.linux-wlan.org/pub/linux-wlan-ng. The string "wlanng" or "wlan-ng" may be used to indicate the use of this driver.
INJ_HOSTAP
Indicated the HostAP driver available at http://hostap.epitest.fi. The string "host-ap" or "hostap" may be used to indicate the use of this driver.
INJ_AIRJACK
Indicates the Airjack driver, available at http://www.sourceforge.net/projects/airjack/. The string "airjack" may be used to indicate the use of this driver. NOTE: The use of this driver is limited to Linux 2.4 kernel systems, and is not otherwise recommended. An alternative driver supporting Prism2 cards such as HostAP or wlan-ng is preferred for robustness, reliability and 2.6 kernel support.
INJ_PRISM54
Indicates the Prism54 driver, available at http://prism54.org. The string "prismgt" or "prism54" may be used to indicate the use of this driver.
INJ_MADWIFING
Indicates the MADWIFI-ng drivers, available at http://www.madwifi.org. The string "madwifi-ng" may be used to indicate the use of this driver.
INJ_MADWIFIOLD
Indicates the MADWIFI-old drivers, available at http://www.madwifi.org. The string "madwifi-old" may be used to indicate the use of this driver.
INJ_RTL8180
Indicates the Realtek RTL8180 driver, available at http://sourceforge.net/projects/rtl8180-sa2400. The string "rtl8180" or "rt8180" may be used to indicate the use of this driver.
INJ_RT2500
Indicates the Ralink RT2500 driver, available at http://sourceforge.net/projects/rt2400. The string "rt2500" or "rtl2500" or "rt25k" or "rtl25k" may be used to indicate the use of this driver.
INJ_RT2750
Indicates the Ralink RT2570 USB driver, available at http://sourceforge.net/projects/rt2400. The string "rt2750" or "rtl2570" may be used to indicate the use of this driver.
INJ_NODRIVER
This value is returned when the driver name specified with in_str is not recognized. This can be due to a typo, or due to lack of support for the specified driver in the installed version of LORCON.

tx80211_resolvecard() returns an integer value that uniquely identifies the driver based on the input string. Upon error, tx80211_resolvecard() will return INJ_NODRIVER.

NOTE: It is not recommended for developers to write code that relies on any given driver. Instead, developers should enumerate what capabilities are needed for their program, and examine the capabilities for the user's selected card and driver combination to determine if the required capabilities are present.

tx80211_init() is used to populate the in_tx structure with the driver-specific code needed for packet injection using the interface name (e.g. "wlan0") specified in the string in_ifname , and the driver type returned from tx80211_resolvecard() with in_injector. This function also establishes the function pointers contained in the in_tx structure and other components needed for packet injection.

tx80211_geterrstr() fetches the error string of the last failed operation, contained in the in_tx structure. tx80211_geterrstr() should only be called when an error is returned. Calling it extraneously may return older error data which is not relevant.

tx80211_getcapabilities() is used to resolve the capability information for the driver in use. Different wireless card and driver combinations present different capability information. LORCON provides the capability bitmask for each card so the driver can deduce what the current capabilities are of the given card to prevent writing driver-specific code. in_tx is the structure populated by the tx80211_init function. This function returns a bitmask value indicating the specific capabilities for this driver:

TX80211_CAP_NONE
Indicates no capability information. This capability is used as a placeholder for drivers that are currently being tested where capability information is not known.
TX80211_CAP_SNIFF
Indicates the capability to sniff packets in monitor mode.
TX80211_CAP_TRANSMIT
Indicates the basic capability to transmit raw 802.11 packets while in monitor mode.
TX80211_CAP_SEQ
Indicates the capability to transmit frames retaining the specified 802.11 sequence number value. Cards with the TX80211_CAP_SEQ capability will not overwrite the specified sequence number before transmitting the packet.
TX80211_CAP_BSSTIME
Indicates the capability to transmit frames retaining the specified BSS Timestamp value in 802.11 beacon frames. Cards with the TX80211_CAP_BSSTIME capability will not overwrite the specified BSS Timestamp value before transmitting the packet.
TX80211_CAP_FRAG
Indicates the capability to transmit a fragmented 802.11 frame by setting the morefrag bit in the frame control header and a non-null value in the fragment number field.
TX80211_CAP_CTRL
Indicates the capability to transmit 802.11 control frames, including but not limited to ACK, PS-Poll, RTS and CTS frames.
TX80211_CAP_DURID
Indicates the capability to transmit frames retaining the specified duration value in the frame control header. Cards with the TX80211_CAP_DURID capability will not overwrite the specified duration value before transmitting the packet.
TX80211_CAP_SNIFFACK
Indicates the capability to observe the presence of ACK frames in monitor mode. NOTE: This is not a TX-related capability, and may be replaced with a separate capability bitmask for RX-related capabilities in a future release.
TX80211_CAP_SELFACK
Indicates the capability to comply with the requirements for positive acknowledgement while in monitor mode. NOTE: While some drivers have the capability to transmit ACK frames, the transmission of positive acknowledgement messages is time-sensitive and not appropriate for non-realtime applications. The TX80211_CAP_SELFACK capability indicates that the card is able to self-transmit ACK messages to properly acknowledge the delivery of frames.
TX80211_CAP_TXNOWAIT
Indicates the capability to transmit frames without waiting for the mandatory DIFS or SIFS intervals.
TX80211_CAP_DSSSTX
Indicates the capability to transmit frames using DSSS modulation. This is appropriate for cards that support 802.11b networking.
TX80211_CAP_OFDMTX
Indicates the capability to transmit frames using OFDM modulation. This is appropriate for cards that support 802.11g or 802.11a networking. NOTE: It is possible to differentiate between 802.11g and 802.11a networking by specifying the appropriate channel in the 2.4 GHz or 5 GHz spectrums with the tx80211_setchannel() function.
TX80211_CAP_MIMOTX
Indicates the capability to transmit frame using MIMO modulation. This capability is reserved for future use as no MIMO-capable drivers are currently supported.
TX80211_CAP_SETRATE
Indicates the capability to set the data transmission rate using the tx80211_setrate() function.

NOTE: The tx80211_getcardlist() call will also populate capability information in the tx80211_cardlist->capabilities[INDEX] field, where INDEX is the resolved card returned by tx80211_resolvecard().

tx80211_open() is used to open and bind a socket for packet transmission. in_tx is the structure populated by the tx80211_init function. It is necessary to call tx80211_open() function before transmitting packets.

tx80211_setmode() is used to explicitly set the operating mode of the wireless card. in_tx is the structure populated by the tx80211_init function.

This function has been superceded with the tx80211_setfunctionalmode() function. Only use this function for explicitly setting the card mode, not to prepare the card for packet injection.

in_mode is the desired operating mode for the wireless card, as defined below:

TX80211_MODE_AUTO
Allows the driver to decide the best operating mode.
TX80211_MODE_ADHOC
Configures the card to operate as an IBSS or ad-hoc network.
TX80211_MODE_INFRA
Configures the card as a wireless client in an BSS or ESS network.
TX80211_MODE_MASTER
Configures the card as an access point or master device.
TX80211_MODE_REPEAT
Configures the card as a wireless repeater or forwarder.
TX80211_MODE_SECOND
Configures the card as a backup or secondary access point or master device.
TX80211_MODE_MONITOR
Configures the card to forward all frames to userspace regardless of destination or BSSID address.

Note that these values match the Linux wireless IW_MODE_ values for backward-compatibility.

tx80211_setmode() returns 0 on success, -1 on error.

tx80211_setfunctionalmode() is used to set the functional operating mode of the wireless card. in_tx is the structure populated by the tx80211_init function. in_fmode is the desired functional operating mode for the wireless card:

TX80211_FUNCMODE_RFMON
Configures the card to forward all frames to userspace regardless of destination or BSSID address.
TX80211_FUNCMODE_INJECT
Configures the card for injection mode. While this may imply other modes, the only guaranteed functionality is injection.
TX80211_FUNCMODE_INJMON
Configures the card for dual functionality, injection and rfmon. If the device supports it, this allows sniffing and injection simultaneously.

tx80211_setfunctionalmode() returns 0 on success, < 0 on error.

NOTE: For most packet injection uses, the TX80211_FUNCMODE_INJMON operating mode is the preferred operating mechanism.

NOTE 2: It's possible that on some cards one mode can perform multiple tasks (IE injection still works while in monitor mode) however this is not recommended as it will not operate on all cards. The caller should always set the desired functional mode.

tx80211_getmode() is used to identify the current operating mode, returning the operating mode or -1 on error. in_tx is the structure populated by the tx80211_init function.

tx80211_setchannel() is used to set card channel, returning 0 on success and -1 on error. in_tx is the structure populated by the tx80211_init function. in_chan is the desired channel number.

tx80211_getchannel() is used to identify the current channel number, returning the channel number or -1 on error. in_tx is the structure populated by the tx80211_init function.

tx80211_txpacket() is used to transmit a packet, returning the number of bytes transmitted on success. On error, TX80211_ENOTX is returned if no bytes were transmitted; TX80211_EPARTTX is returned if only a partial number of bytes were transmitted. in_tx is the structure populated by the tx80211_init function. in_packet is a structure consisting of two members:

packet
An 8-bit pointer to an array of bytes that represents the packet to be transmitted.
plen
An integer value indicating the length of the packet to be transmitted.

tx80211_close() is used to close the socket opened for packet injection with the tx80211_open() function. in_tx is the structure populated by the tx80211_init function. The return value is zero on success, or -1 if an error occurred.

 

EXAMPLE

A sample application designed to inject a specified byte-string is shown below.

#include <stdio.h>
#include <sys/socket.h>

#include <tx80211.h>
#include <tx80211_packet.h>
#include <linux/wireless.h>

#define CHANNEL 11
#define IFACE   "wlan0"

void usage()
{

        struct tx80211_cardlist *cardlist = NULL;
        int i;

        printf("Usage : txack [drivername]\n");

        cardlist = tx80211_getcardlist();

        if (cardlist == NULL) {
                fprintf(stderr, "Error accessing supported cardlist.\n");
        } else {
                printf("\nSupported drivers are: ");
                for (i = 1; i < cardlist->num_cards; i++) {
                        printf("%s ", cardlist->cardnames[i]);
                }
                printf("\n");
        }
        tx80211_freecardlist(cardlist);
}

int main(int argc, char *argv[])
{

        /* ACK frame */
        unsigned char packet[10] = {
                0xd4, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x66, 0xe3, 0x76, 0x3b
        };

        struct tx80211 in_tx;
        struct tx80211_packet in_packet;
        int drivertype;

        if (argc < 2) {
                usage();
                return 0;
        }

        /* Use the command-line argument as the desired driver type */
        drivertype = tx80211_resolvecard(argv[1]);

        /* Validate the driver name specified */
        if (drivertype == INJ_NODRIVER) {
                fprintf(stderr, "Driver name not recognized.\n");
                return -1;
        }

        /* Initialize the in_tx structure using the resolved drivertype and
           interface name */
        if (tx80211_init(&in_tx, IFACE, drivertype) < 0) {
                fprintf(stderr, "Error initializing driver "
                                "\"%s\".\n", argv[1]);
                return -1;
        }

        /* Check the capability of the card to ensure it supports 
           transmitting control frames. */
        if ((tx80211_getcapabilities(&in_tx) & TX80211_CAP_CTRL) == 0) {
                fprintf(stderr, "Driver does not support transmitting "
                                "control frames.\n");
                return -1;
        }

        /* Place the card in monitor mode */
        if (tx80211_setfunctionalmode(&in_tx, TX80211_FUNCMODE_INJMON) != 0) {
                fprintf(stderr, "Error setting monitor/inject mode: %s.\n",
                        tx80211_geterrstr(in_tx));
                return 1;
        }

        /* Switch to the specified channel */
        if (tx80211_setchannel(&in_tx, CHANNEL) < 0) {
                fprintf(stderr, "Error setting channel: %s.\n",
                        tx80211_geterrstr(in_tx));
                return 1;
        }

        /* Open the interface */
        if (tx80211_open(&in_tx) < 0) {
                fprintf(stderr, "Unable to open interface %s: %s.\n", 
                        in_tx.ifname, tx80211_geterrstr(in_tx));
                return 1;
        }

        /* Initialized in_packet with packet contents and length of 
           the packet */
        in_packet.packet = packet;
        in_packet.plen = sizeof(packet);

        /* Transmit the packet */
        if (tx80211_txpacket(&in_tx, &in_packet) < 0) {
                fprintf(stderr, "Unable to transmit packet: %s.\n",
                        tx80211_geterrstr(in_tx));
                return 1;
        }

        /* Close the socket after transmitting the packet */
        tx80211_close(&in_tx);

        return 0;
}


 

AUTHORS

Joshua Wright <jwright@hasborg.com>

Mike Kershaw <dragorn@kismetwireless.net>

 

BUGS

Please send problems, bugs, questions, desirable enhancements, patches and source code contributions to:

lorcon-devel@802.11ninja.net


 

Index

NAME
SYNOPSIS
DESCRIPTION
ROUTINES
EXAMPLE
AUTHORS
BUGS

This document was created by man2html, using the manual pages.
Time: 18:52:06 GMT, April 10, 2007