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


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Fri Jan 3 2014 12:07:56