Changeset 86 for trunk

Show
Ignore:
Timestamp:
11/01/06 19:00:10 (2 years ago)
Author:
dragorn
Message:

Moved ifcontrol to ifcontrol_linux
Added setfunctionalmode API
Deprecated setmode API
Fixed missing getchannel symbol (getchan vs getchannel)
Added geterrstr() api to fetch string errors
Added string errors to most iw* ioctl wrappers

Location:
trunk
Files:
15 modified
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/Makefile.in

    r83 r86  
    2525DEPEND = .depend 
    2626 
    27 LIBOBJ = ifcontrol.lo iwcontrol.lo \ 
     27LIBOBJ = ifcontrol_linux.lo iwcontrol.lo \ 
    2828                 wtinject.lo mwoldinject.lo mwnginject.lo \ 
    2929                 ajinject.lo p54inject.lo wginject.lo \ 
  • trunk/ajinject.c

    r73 r86  
    5050        in_tx->setchan_callthrough = &ajinj_setchannel; 
    5151        in_tx->txpacket_callthrough = &ajinj_send; 
     52        in_tx->setfuncmode_callthrough = NULL; 
    5253 
    5354        return 0; 
  • trunk/hapinject.c

    r69 r86  
    3333        in_tx->setchan_callthrough = &wtinj_setchannel; 
    3434        in_tx->txpacket_callthrough = &wtinj_send; 
     35        in_tx->setfuncmode_callthrough = &wtinj_setfuncmode; 
    3536 
    3637        return 0; 
  • trunk/ifcontrol_linux.c

    r68 r86  
    2020 
    2121#include "config.h" 
    22 #include "ifcontrol.h" 
     22#include "ifcontrol_linux.h" 
    2323#include "tx80211.h" 
    2424 
  • trunk/lorcon.3

    r85 r86  
    11.\" $Id: $ 
    2 .TH LORCON 3 "22 November 2005" 
     2.TH LORCON 3 "01 November 2006" 
    33.SH NAME 
    44LORCON \- 802.11 Wireless Packet Injection Library 
     
    2121.LP 
    2222.ft B 
    23 int tx80211_getcapabilities(struct tx80211 *in_tx) 
    24 .ft 
    25 .LP 
    26 .ft B 
    2723int tx80211_init(struct tx80211 *in_tx, const char *in_ifname,  
    2824.ti +8  
     
    3127.LP 
    3228.ft B 
     29int tx80211_geterrstr(struct tx80211 *in_tx) 
     30.ft 
     31.LP 
     32.ft B 
     33int tx80211_getcapabilities(struct tx80211 *in_tx) 
     34.ft 
     35.LP 
     36.ft B 
    3337int tx80211_open(struct tx80211 *in_tx) 
    3438.ft 
     
    3640.ft B 
    3741int tx80211_setmode(struct tx80211 *in_tx, int in_mode) 
    38 int tx80211_getmode(struct tx80211 *in_tx) 
     42int tx80211_getmode(struct tx80211 *in_tx) /* deprecated */ 
     43int tx80211_setfunctionalmode(struct tx80211 *in_tx, int in_fmode) 
    3944.ft 
    4045.LP 
     
    184189 
    185190.PP 
     191.BR tx80211_geterrstr() 
     192fetches the error string of the last failed operation, contained in the 
     193.I in_tx 
     194structure. 
     195.B tx80211_geterrstr() 
     196should only be called when an error is returned.  Calling it extraneously may return 
     197older error data which is not relevant. 
     198 
     199.PP 
    186200.BR tx80211_getcapabilities() 
    187201is used to resolve the capability information for the driver in use.  Different 
     
    322336.B tx80211_init 
    323337function. 
     338 
     339.I This function is deprecated.  It has been superseded by the 
     340.B tx80211_setfunctionalmode 
     341.I function. 
     342 
    324343.I in_mode 
    325344is the desired operating mode for the wireless card, as defined in the 
     
    367386operating mode is the preferred operating mechanism. 
    368387 
     388.PP 
     389.BR tx80211_setfunctionalmode() 
     390is used to set the operating mode of the wireless card. 
     391.I in_tx 
     392is the structure populated by the 
     393.B tx80211_init 
     394function. 
     395.I in_fmode 
     396is the desired functional operating mode for the wireless card: 
     397 
     398.RS 
     399.TP 
     400.B 
     401TX80211_FUNCMODE_RFMON 
     402Configures the card to forward all frames to userspace regardless of destination 
     403or BSSID address. 
     404.TP 
     405.B 
     406TX80211_FUNCMODE_INJECT 
     407Configures the card for injection mode.  While this may imply other modes, the only 
     408guaranteed functionality is injection. 
     409.TP 
     410.B 
     411TX80211_FUNCMODE_INJMON 
     412Configures the card for dual functionality, injection and rfmon.  If the device 
     413supports it, this allows sniffing and injection simultaneously. 
     414 
     415.RE 
     416.B tx80211_setfunctionalmode() 
     417returns 0 on success, < 0 on error. 
     418 
     419.B NOTE: 
     420For most packet injection uses, the  
     421.B TX80211_FUNCMODE_INJMON 
     422operating mode is the preferred operating mechanism. 
     423 
     424.B NOTE 2: It's possible that on some cards one mode can perform multiple tasks (IE 
     425injection still works while in monitor mode) however this is not recommended as it 
     426will not operate on all cards.  The caller should always set the desired functional 
     427mode. 
    369428 
    370429.PP 
     
    506565 
    507566        /* Place the card in monitor mode */ 
    508         if (tx80211_setmode(&in_tx, IW_MODE_MONITOR) != 0) { 
    509                 fprintf(stderr, "Error setting monitor mode.\\n"); 
     567        if (tx80211_setfunctionalmode(&in_tx, TX80211_FUNCMODE_INJMON) != 0) { 
     568                fprintf(stderr, "Error setting monitor/inject mode: %s.\\n", 
     569                        tx80211_geterrstr(in_tx)); 
    510570                return 1; 
    511571        } 
     
    513573        /* Switch to the specified channel */ 
    514574        if (tx80211_setchannel(&in_tx, CHANNEL) < 0) { 
    515                 fprintf(stderr, "Error setting channel.\\n"); 
     575                fprintf(stderr, "Error setting channel: %s.\\n", 
     576                        tx80211_geterrstr(in_tx)); 
    516577                return 1; 
    517578        } 
     
    519580        /* Open the interface */ 
    520581        if (tx80211_open(&in_tx) < 0) { 
    521                 fprintf(stderr, "Unable to open interface %s.\\n",  
    522                         in_tx.ifname); 
     582                fprintf(stderr, "Unable to open interface %s: %s.\\n",  
     583                        in_tx.ifname, tx80211_geterrstr(in_tx)); 
    523584                return 1; 
    524585        } 
     
    531592        /* Transmit the packet */ 
    532593        if (tx80211_txpacket(&in_tx, &in_packet) < 0) { 
    533                 fprintf(stderr, "Unable to transmit packet.\\n"); 
     594                fprintf(stderr, "Unable to transmit packet: %s.\\n", 
     595                        tx80211_geterrstr(in_tx)); 
    534596                return 1; 
    535597        } 
  • trunk/mwnginject.c

    r83 r86  
    3333        in_tx->setchan_callthrough = &wtinj_setchannel; 
    3434        in_tx->txpacket_callthrough = &madwifing_send; 
     35        in_tx->setfuncmode_callthrough = NULL; 
    3536 
    3637        return 0; 
  • trunk/mwoldinject.c

    r73 r86  
    3636        in_tx->setchan_callthrough = &wtinj_setchannel; 
    3737        in_tx->txpacket_callthrough = &wtinj_send; 
     38        in_tx->setfuncmode_callthrough = &wtinj_setfuncmode; 
    3839 
    3940        return 0; 
  • trunk/p54inject.c

    r69 r86  
    3333        in_tx->setchan_callthrough = &wtinj_setchannel; 
    3434        in_tx->txpacket_callthrough = &wtinj_send; 
     35        in_tx->setfuncmode_callthrough = &wtinj_setfuncmode; 
    3536 
    3637        return 0; 
  • trunk/rt2500inject.c

    r70 r86  
    3333        in_tx->setchan_callthrough = &wtinj_setchannel; 
    3434        in_tx->txpacket_callthrough = &wtinj_send; 
     35        in_tx->setfuncmode_callthrough = &wtinj_setfuncmode; 
    3536 
    3637        return 0; 
  • trunk/rt2570inject.c

    r85 r86  
    3333        in_tx->setchan_callthrough = &wtinj_setchannel; 
    3434        in_tx->txpacket_callthrough = &rt2570_send; 
     35        in_tx->setfuncmode_callthrough = &wtinj_setfuncmode; 
    3536 
    3637        return 0; 
  • trunk/rtlinject.c

    r68 r86  
    3333        in_tx->setchan_callthrough = &wtinj_setchannel; 
    3434        in_tx->txpacket_callthrough = &wtinj_send; 
     35        in_tx->setfuncmode_callthrough = &wtinj_setfuncmode; 
    3536 
    3637        return 0; 
  • trunk/tx80211.c

    r73 r86  
    180180} 
    181181 
     182char *tx80211_geterrstr(struct tx80211 *in_tx) 
     183{ 
     184        return in_tx->errstr; 
     185} 
     186 
    182187int tx80211_init(struct tx80211 *in_tx, const char *in_ifname, int in_injector) 
    183188{ 
     
    248253int tx80211_close(struct tx80211 *in_tx) 
    249254{ 
    250         if (in_tx->close_callthrough == NULL) 
    251                 return TX80211_ENOHANDLER; 
     255        if (in_tx->close_callthrough == NULL)  
     256        { 
     257                snprintf(in_tx->errstr, TX80211_STATUS_MAX,  
     258                                 "Close callthrough handler not implemented"); 
     259                return TX80211_ENOHANDLER; 
     260        } 
    252261 
    253262        return (in_tx->close_callthrough) (in_tx); 
     
    256265int tx80211_setmode(struct tx80211 *in_tx, int in_mode) 
    257266{ 
    258         if (in_tx->setmode_callthrough == NULL) 
    259                 return TX80211_ENOHANDLER; 
     267        fprintf(stderr, "LORCON - tx80211_setmode(...) is deprecated, please use " 
     268                        "tx80211_setfunctionalmode(...) instead\n"); 
     269 
     270        if (in_tx->setmode_callthrough == NULL)  
     271        { 
     272                snprintf(in_tx->errstr, TX80211_STATUS_MAX,  
     273                                 "Setmode callthrough handler not implemented"); 
     274                return TX80211_ENOHANDLER; 
     275        } 
    260276 
    261277        return (in_tx->setmode_callthrough) (in_tx, in_mode); 
     
    265281{ 
    266282        if (in_tx->getmode_callthrough == NULL) 
    267                 return TX80211_ENOHANDLER; 
     283        { 
     284                snprintf(in_tx->errstr, TX80211_STATUS_MAX,  
     285                                 "Getmode callthrough handler not implemented"); 
     286                return TX80211_ENOHANDLER; 
     287        } 
    268288 
    269289        return (in_tx->getmode_callthrough) (in_tx); 
     
    272292int tx80211_setfunctionalmode(struct tx80211 *in_tx, int in_fmode) 
    273293{ 
    274         if (in_tx->setfuncmode_callthrough == NULL) 
    275                 return TX80211_ENOHANDLER; 
     294        if (in_tx->setfuncmode_callthrough == NULL)  
     295        { 
     296                snprintf(in_tx->errstr, TX80211_STATUS_MAX,  
     297                                 "Setfunctionalmode callthrough handler not implemented"); 
     298                return TX80211_ENOHANDLER; 
     299        } 
    276300 
    277301        return (in_tx->setfuncmode_callthrough) (in_tx, in_fmode); 
     
    281305{ 
    282306        if (in_tx->setchan_callthrough == NULL) 
    283                 return TX80211_ENOHANDLER; 
     307        { 
     308                snprintf(in_tx->errstr, TX80211_STATUS_MAX,  
     309                                 "Setchannel callthrough handler not implemented"); 
     310                return TX80211_ENOHANDLER; 
     311        } 
    284312 
    285313        return (in_tx->setchan_callthrough) (in_tx, in_chan); 
    286314} 
    287315 
    288 int tx80211_getchan(struct tx80211 *in_tx) 
     316int tx80211_getchannel(struct tx80211 *in_tx) 
    289317{ 
    290318        if (in_tx->getchan_callthrough == NULL) 
    291                 return TX80211_ENOHANDLER; 
     319        { 
     320                snprintf(in_tx->errstr, TX80211_STATUS_MAX,  
     321                                 "Getchannel callthrough handler not implemented"); 
     322                return TX80211_ENOHANDLER; 
     323        } 
    292324 
    293325        return (in_tx->getchan_callthrough) (in_tx); 
     
    296328int tx80211_txpacket(struct tx80211 *in_tx, struct tx80211_packet *in_packet) 
    297329{ 
    298         if (in_tx->txpacket_callthrough == NULL) 
    299                 return TX80211_ENOHANDLER; 
     330        if (in_tx->txpacket_callthrough == NULL)  
     331        { 
     332                snprintf(in_tx->errstr, TX80211_STATUS_MAX,  
     333                                 "txpacket callthrough handler not implemented"); 
     334                return TX80211_ENOHANDLER; 
     335        } 
    300336 
    301337        return (in_tx->txpacket_callthrough) (in_tx, in_packet); 
    302338} 
     339 
  • trunk/tx80211.h

    r85 r86  
    5555        int rate; 
    5656 
     57        /* Error buffer */ 
     58        char errstr[TX80211_STATUS_MAX]; 
     59 
    5760        /* Extra space for use by the driver code */ 
    5861        void *extra; 
     
    8487/* Functional modes (you should probably be using these to set the mode 
    8588 * instead of calling SetMode() directly.  These modes can be combined 
    86  * if the card supports them, and the actual modes set will be */ 
    87 #define TX80211_FUNCMODE_ 
     89 * if the card supports them, and the actual modes set will be.  It's 
     90 * possible that one mode will be able to perform other tasks (ie, some cards 
     91 * may support inject in monitor mode w/ no special tricks) but it's a wise 
     92 * idea to use the proper mode, INJMON, for that) */ 
     93#define TX80211_FUNCMODE_RFMON          0 
     94#define TX80211_FUNCMODE_INJECT         1 
     95#define TX80211_FUNCMODE_INJMON         2 
    8896 
    8997/* tx80211 device capabilities */ 
     
    253261int tx80211_resolvecard(const char *in_str); 
    254262 
     263/* Get the error string */ 
     264char *tx80211_geterrstr(struct tx80211 *in_tx); 
     265 
    255266/* Create and assign a tx80211 system */ 
    256267int tx80211_init(struct tx80211 *in_tx, const char *in_ifname, int in_injector); 
  • trunk/wginject.c

    r69 r86  
    4949        in_tx->setchan_callthrough = &wginj_setchannel; 
    5050        in_tx->txpacket_callthrough = &wginj_send; 
     51        in_tx->setfuncmode_callthrough = NULL; 
    5152 
    5253        return 0; 
  • trunk/wtinject.c

    r68 r86  
    2323 
    2424#include "wtinject.h" 
     25#include "tx80211.h" 
     26#include "tx80211_errno.h" 
    2527 
    2628int wtinj_send(struct tx80211 *wtinj, struct tx80211_packet *in_pkt) 
     
    5254        wtinj->raw_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); 
    5355 
    54         if (wtinj->raw_fd < 0) 
     56        if (wtinj->raw_fd < 0) { 
     57                snprintf(wtinj->errstr, TX80211_STATUS_MAX, "no socket fd in tx descriptor"); 
    5558                return -1; 
     59        } 
    5660 
    5761        memset(&if_req, 0, sizeof if_req); 
     
    6064        err = ioctl(wtinj->raw_fd, SIOCGIFINDEX, &if_req); 
    6165        if (err < 0) { 
     66                snprintf(wtinj->errstr, TX80211_STATUS_MAX, "SIOCGIFINDEX ioctl failed, %s", 
     67                                 strerror(errno)); 
    6268                close(wtinj->raw_fd); 
    6369                return -2; 
     
    7076        err = bind(wtinj->raw_fd, (struct sockaddr *)&sa_ll, sizeof sa_ll); 
    7177        if (err != 0) { 
     78                snprintf(wtinj->errstr, TX80211_STATUS_MAX, "bind() failed, %s", 
     79                                 strerror(errno)); 
    7280                close(wtinj->raw_fd); 
    7381                return -3; 
     
    8593{ 
    8694        /* wrapper for iwconfig_set_channel */ 
    87         char errstr[TX80211_STATUS_MAX];        /* Not used for now */ 
    88         return (iwconfig_set_channel(wtinj->ifname, errstr, channel)); 
     95        return (iwconfig_set_channel(wtinj->ifname, wtinj->errstr, channel)); 
    8996 
    9097} 
     
    93100{ 
    94101        /* wrapper for iwconfig_get_channel */ 
    95         char errstr[TX80211_STATUS_MAX];        /* Not used for now */ 
    96         return (iwconfig_get_channel(wtinj->ifname, errstr)); 
     102        return (iwconfig_get_channel(wtinj->ifname, wtinj->errstr)); 
    97103 
    98104} 
     
    101107{ 
    102108        /* wrapper for iwconfig_set_mode */ 
    103         char errstr[TX80211_STATUS_MAX];        /* Not used for now */ 
    104         return (iwconfig_set_mode(wtinj->ifname, errstr, mode)); 
    105  
     109        return (iwconfig_set_mode(wtinj->ifname, wtinj->errstr, mode)); 
    106110} 
    107111 
     
    109113{ 
    110114        /* wrapper for iwconfig_get_mode */ 
    111         char errstr[TX80211_STATUS_MAX];        /* Not used for now */ 
    112         return (iwconfig_get_mode(wtinj->ifname, errstr)); 
     115        return (iwconfig_get_mode(wtinj->ifname, wtinj->errstr)); 
    113116 
    114117} 
     118 
     119int wtinj_setfuncmode(struct tx80211 *wtinj, int funcmode) 
     120{ 
     121        /* All the iw* drivers use rfmon mode for injection so we just set it 
     122         * here the same */ 
     123        if (funcmode == TX80211_FUNCMODE_RFMON || 
     124                funcmode == TX80211_FUNCMODE_INJECT || 
     125                funcmode == TX80211_FUNCMODE_INJMON) { 
     126                return (iwconfig_set_mode(wtinj->ifname, wtinj->errstr, IW_MODE_MONITOR)); 
     127        } 
     128 
     129        /* Otherwise we don't have a handler */ 
     130        return TX80211_ENOHANDLER; 
     131} 
     132 
  • trunk/wtinject.h

    r48 r86  
    6262int wtinj_setmode(struct tx80211 *wtinj, int mode); 
    6363int wtinj_getmode(struct tx80211 *wtinj); 
     64int wtinj_setfuncmode(struct tx80211 *wtinj, int funcmode); 
    6465 
    6566#endif