test_ioctl.c
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <string.h>
00004 #include <sys/ioctl.h>
00005 #include <sys/socket.h>
00006 #include <linux/if.h>
00007 #include "ath5k_interface.h"
00008 
00009 int config(int sock, struct ifreq *ifr, unsigned int freq, int rate, unsigned char txpowerdbm, int antmode)
00010 {
00011         struct ath5k_config_info config_info;
00012 
00013         config_info.frequency = freq;
00014         config_info.rate = rate;
00015         config_info.tx_power_dbm = txpowerdbm;
00016         config_info.antenna_mode = antmode;
00017 
00018         ifr->ifr_data = (void *)&config_info;
00019 
00020         if((ioctl(sock, SIO_SET_CONFIG, ifr)) < 0)
00021         {
00022                 perror("Error setting config");
00023                 exit(1);
00024         }
00025                 
00026         return 0;
00027 }
00028 
00029 int set_debug(int sock, struct ifreq *ifr, unsigned int debug)
00030 {
00031         ifr->ifr_data = (void *)&debug;
00032 
00033         if((ioctl(sock, SIO_SET_DEBUG, ifr)) < 0)
00034         {
00035                 perror("Error setting debug level");
00036                 exit(1);
00037         }
00038 
00039         return 0;
00040 }
00041 
00042 int config_disable_ack(int sock, struct ifreq *ifr, int disable)
00043 {
00044         ifr->ifr_data = (void *)&disable;
00045 
00046         if((ioctl(sock, SIO_SET_DISABLEACK, ifr)) < 0)
00047         {
00048                 perror("Error setting disable ack");
00049                 exit(1);
00050         }
00051 
00052         return 0;
00053 }
00054 
00055 int config_tx_control(int sock, struct ifreq *ifr, unsigned int count, bool wait_for_ack, bool use_short_preamble)
00056 {
00057         struct ath5k_txcontrol_info info;
00058 
00059         info.count = count;
00060         info.wait_for_ack = wait_for_ack;
00061         info.use_short_preamble = use_short_preamble;
00062 
00063         ifr->ifr_data = (void *)&info;
00064 
00065         if((ioctl(sock, SIO_SET_TXCONTROL, ifr)) < 0)
00066         {
00067                 perror("Error setting tx control");
00068                 exit(1);
00069         }
00070 
00071         return 0;
00072 }
00073 
00074 int set_rxfilter(int sock, struct ifreq *ifr, int broad, int con, int prom)
00075 {
00076         struct ath5k_rxfilter_info info;
00077 
00078         info.broadcast = broad;
00079         info.control = con;
00080         info.promisc = prom;
00081 
00082         ifr->ifr_data = (void *)&info;
00083 
00084         if((ioctl(sock, SIO_SET_RXFILTER, ifr)) < 0)
00085         {
00086                 perror("Error setting tx control");
00087                 exit(1);
00088         }
00089 
00090         return 0;
00091 
00092 
00093 }
00094 
00095 void usage()
00096 {
00097         printf("Usage: ./athraw_config <interface>\n\n");
00098         exit(0);
00099 }
00100 
00101 int main(int argc, char *argv[])
00102 {       
00103         int sock;
00104         struct ifreq ifr;
00105 
00106         if (argc < 4)
00107                 usage();
00108 
00109         /* Create socket */
00110         if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
00111         {
00112                 perror("Error creating socket");
00113                 exit(1);
00114         }       
00115         strcpy(ifr.ifr_name,  argv[1]);
00116 
00117         if (strcmp(argv[2], "debug") == 0)
00118         {
00119                 char *final;
00120                 int base = 16;
00121                 unsigned int debug = strtoul(argv[3], &final, base);
00122 
00123                 printf("Setting debug mask %08x\n", debug);
00124                 set_debug(sock, &ifr, debug);
00125         }
00126         else if (strcmp(argv[2], "rxfilter") == 0)
00127         {
00128                 int broad = atoi(argv[3]);
00129                 int control = atoi(argv[4]);
00130                 int promisc = atoi(argv[5]);
00131 
00132                 printf("Setting rx filter. broadcast %d, control %d, promisc %d\n", broad, control, promisc);
00133                 set_rxfilter(sock, &ifr, broad, control, promisc);
00134         }
00135         else if (strcmp(argv[2], "disableack") == 0)
00136         {
00137                 int disable = atoi(argv[3]);
00138 
00139                 printf("Disable ack %d\n", disable);
00140                 config_disable_ack(sock, &ifr, disable);
00141         }
00142         else if (strcmp(argv[2], "config") == 0)
00143         {
00144                 int freq = atoi(argv[3]);
00145                 int rate = atoi(argv[4]);
00146                 int txpower = atoi(argv[5]);
00147                 int antmode = atoi(argv[6]);
00148 
00149                 printf("Setting freq %d, rate %d, power %d, ant. mode %d\n", freq, rate, txpower, antmode);
00150                 config(sock, &ifr, freq, rate, txpower, antmode);
00151         }
00152         else if (strcmp(argv[2], "txcontrol") == 0)
00153         {
00154                 int count = atoi(argv[3]);
00155                 int wait_ack = atoi(argv[4]);
00156                 int short_pre = atoi(argv[5]);
00157 
00158                 printf("Setting tx control. Count %d, wait ack %d, short preamble %d\n", count,wait_ack,short_pre);
00159                 config_tx_control(sock, &ifr, count,wait_ack,short_pre);
00160         }
00161 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:11