WiFi card configuration
parent
f7ac3b31b6
commit
739b234cc5
2
Makefile
2
Makefile
|
|
@ -1,5 +1,5 @@
|
|||
test:
|
||||
gcc main.c -o bin/wipacket -liw
|
||||
gcc main.c if_helper.c -o bin/wipacket -liw
|
||||
|
||||
clean:
|
||||
rm wipacket
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
#include "if_helper.h"
|
||||
|
||||
// Either I'm blind, or libiw API documentation is very hard to find,
|
||||
// so for now system() calls will have to do for configuring the
|
||||
// wireless interface.
|
||||
|
||||
int if_up(char *name) {
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf), "ifconfig %s up", name);
|
||||
int ret = system(buf);
|
||||
if (ret != 0) {
|
||||
printf("Could not bring up interface %s\n", name);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int if_down(char *name) {
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf), "ifconfig %s down", name);
|
||||
int ret = system(buf);
|
||||
if (ret != 0) {
|
||||
printf("Could not bring down interface %s\n", name);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int if_enable_ibss(char *name) {
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf), "iw %s set type ibss", name);
|
||||
int ret = system(buf);
|
||||
if (ret != 0) {
|
||||
printf("Could not enable IBSS on %s\n", name);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int if_join_ibss(char *name, char *essid, int frequency) {
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf), "iw %s ibss join %s %d", name, essid, frequency);
|
||||
int ret = system(buf);
|
||||
if (ret != 0) {
|
||||
printf("Interface %s failed enabling ESSID \"%s\" on frequency %d \n", name, essid, frequency);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int if_up(char *name);
|
||||
int if_down(char *name);
|
||||
int if_enable_ibss(char *name);
|
||||
int if_join_ibss(char *name, char *essid, int frequency);
|
||||
11
main.c
11
main.c
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
#include <net/ethernet.h>
|
||||
#include <linux/if_packet.h>
|
||||
|
||||
#include "if_helper.h"
|
||||
//#include <linux/if_ether.h>
|
||||
//#include <linux/if_arp.h>
|
||||
|
||||
|
|
@ -23,6 +25,10 @@ void cleanup();
|
|||
// Ethernet protocol ID
|
||||
#define PROTOCOL_IDENTIFIER 0x9f77
|
||||
|
||||
// ESSID and frequency for network
|
||||
#define ESSID "wipacket"
|
||||
#define FREQUENCY 2412
|
||||
|
||||
// The ethernet broadcast address
|
||||
const unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
||||
|
||||
|
|
@ -120,7 +126,12 @@ void prepeareBroadcastHeader() {
|
|||
}
|
||||
|
||||
void configureInterface() {
|
||||
int status;
|
||||
printf("Configuring interface %s...\n", if_name);
|
||||
if_down(if_name);
|
||||
if_enable_ibss(if_name);
|
||||
if_up(if_name);
|
||||
if_join_ibss(if_name, ESSID, FREQUENCY);
|
||||
}
|
||||
|
||||
void cleanup() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue