atheros设置beacon和probe response中的IE信息
来源:互联网 发布:推荐淘宝上的韩国泡菜 编辑:程序博客网 时间:2024/06/05 03:53
查看设置IE信息
#include <stdio.h>#include <sys/types.h>#include <sys/socket.h>#include <string.h>#include <errno.h>#include <sys/ioctl.h>#include <unistd.h>#define BUF_SIZE 1024#define TRACE printf("%s %d\n", __func__, __LINE__)/******************************************************************************/#define IFNAMSIZ 16typedef __uint32_t __u32;typedef __int32_t __s32;typedef __uint16_t __u16;typedef __int16_t __s16;typedef __uint8_t __u8;#ifndef __user#define __user#endif /* __user */#define ifr_name ifr_ifrn.ifrn_name /* interface name *//******************************************************************************//* from ieee80211_ioctl.h */#define SIOCIWFIRSTPRIV0x8BE0#define SIOCIWLASTPRIV0x8BFF#defineIEEE80211_IOCTL_GET_APPIEBUF(SIOCIWFIRSTPRIV+19)#defineIEEE80211_IOCTL_SET_APPIEBUF(SIOCIWFIRSTPRIV+20)#defineIEEE80211_IOCTL_FILTERFRAME(SIOCIWFIRSTPRIV+12)enum {IEEE80211_APPIE_FRAME_BEACON= 0,IEEE80211_APPIE_FRAME_PROBE_REQ= 1,IEEE80211_APPIE_FRAME_PROBE_RESP= 2,IEEE80211_APPIE_FRAME_ASSOC_REQ= 3,IEEE80211_APPIE_FRAME_ASSOC_RESP= 4,IEEE80211_APPIE_NUM_OF_FRAME= 5};struct ieee80211req_getset_appiebuf {u_int32_tapp_frmtype;/* management frame type for which buffer is added */u_int32_tapp_buflen;/* application-supplied buffer length */u_int8_tapp_buf[0];/* application-supplied IE(s) */};/******************************************************************************//* from wireless.h */#define SIOCSIWESSID0x8B1A/* set ESSID (network name) */#define SIOCGIWESSID0x8B1B/* get ESSID */structiw_param{ __s32value;/* The value of the parameter itself */ __u8fixed;/* Hardware should not use auto select */ __u8disabled;/* Disable the feature */ __u16flags;/* Various specifc flags (if any) */};structiw_point{ void __user*pointer;/* Pointer to the data (in user space) */ __u16length;/* number of fields or size in bytes */ __u16flags;/* Optional params */};structiw_freq{__s32m;/* Mantissa */__s16e;/* Exponent */__u8i;/* List index (when in range struct) */__u8flags;/* Flags (fixed/auto) */};structiw_quality{__u8qual;/* link quality (%retries, SNR, %missed beacons or better...) */__u8level;/* signal level (dBm) */__u8noise;/* noise level (dBm) */__u8updated;/* Flags to know if updated */};unioniwreq_data{/* Config - generic */charname[IFNAMSIZ];/* Name : used to verify the presence of wireless extensions. * Name of the protocol/provider... */struct iw_pointessid;/* Extended network name */struct iw_paramnwid;/* network id (or domain - the cell) */struct iw_freqfreq;/* frequency or channel : * 0-1000 = channel * > 1000 = frequency in Hz */struct iw_paramsens;/* signal level threshold */struct iw_parambitrate;/* default bit rate */struct iw_paramtxpower;/* default transmit power */struct iw_paramrts;/* RTS threshold threshold */struct iw_paramfrag;/* Fragmentation threshold */__u32mode;/* Operation mode */struct iw_paramretry;/* Retry limits & lifetime */struct iw_pointencoding;/* Encoding stuff : tokens */struct iw_parampower;/* PM duration/timeout */struct iw_quality qual;/* Quality part of statistics */struct sockaddrap_addr;/* Access point address */struct sockaddraddr;/* Destination address (hw/mac) */struct iw_paramparam;/* Other small parameters */struct iw_pointdata;/* Other large parameters */};structiwreq {union{charifrn_name[IFNAMSIZ];/* if name, e.g. "eth0" */} ifr_ifrn;/* Data part (defined just above) */unioniwreq_datau;};/******************************************************************************/voidhexdump(char *msg, const void *buf, int len){unsigned char *__buf = (unsigned char *)buf;#define PER_LINE 16printf("%s\n", msg);printf("buf len: %d\n", len); printf("-------------------------------- 1\n"); int i; for (i = 0; i < len; i++) { printf("%02x ", __buf[i]); if (((i + 1) % PER_LINE) == 0) { printf("\n"); } else if (((i + 1) % 8) == 0) {printf(" "); } } printf("\n-------------------------------- 2\n");#undef PER_LINE}/******************************************************************************//* adapted from hostapd */static intset80211priv(char *ifname, int op, void *data, int len){struct iwreq iwr;int do_inline = len < IFNAMSIZ;int sock_fd = socket(PF_INET, SOCK_DGRAM, 0);if (sock_fd < 0) {perror("socket()");return -1;}/* Certain ioctls must use the non-inlined method */if (op == IEEE80211_IOCTL_SET_APPIEBUF || op == IEEE80211_IOCTL_FILTERFRAME)do_inline = 0;memset(&iwr, 0, sizeof(iwr));strncpy(iwr.ifr_name, ifname, IFNAMSIZ - 1);if (do_inline) {/* * Argument data fits inline; put it there. */memcpy(iwr.u.name, data, len);} else {/* * Argument data too big for inline transfer; setup a * parameter block instead; the kernel will transfer * the data for the driver. */iwr.u.data.pointer = data;iwr.u.data.length = len;}if (ioctl(sock_fd, op, &iwr) < 0) {printf("atheros: %s: %s: ioctl op=0x%x " "len=%d failed: %d (%s)", __func__, ifname, op, len, errno, strerror(errno));close(sock_fd);return -1;}close(sock_fd);return 0;}/******************************************************************************/static intatheros_set_appiebuf(char *ifname, const unsigned char *ie, size_t ie_len){TRACE;printf("%s buflen = %lu", __func__, (unsigned long) ie_len);hexdump("atheros: set_generic_elem", ie, ie_len);unsigned char buf[BUF_SIZE] = {[0 ... (BUF_SIZE - 1)] = 0,};struct ieee80211req_getset_appiebuf *app_ie;app_ie = (struct ieee80211req_getset_appiebuf *)buf;memcpy(&(app_ie->app_buf[0]), ie, ie_len);app_ie->app_buflen = ie_len;app_ie->app_frmtype = IEEE80211_APPIE_FRAME_BEACON;hexdump("atheros: SET_APPIEBUF(Beacon)", app_ie->app_buf, app_ie->app_buflen);set80211priv(ifname, IEEE80211_IOCTL_SET_APPIEBUF, app_ie, sizeof(struct ieee80211req_getset_appiebuf) + app_ie->app_buflen);app_ie->app_frmtype = IEEE80211_APPIE_FRAME_PROBE_RESP;hexdump("atheros: SET_APPIEBUF(ProbeResp)", app_ie->app_buf, app_ie->app_buflen);set80211priv(ifname, IEEE80211_IOCTL_SET_APPIEBUF, app_ie, sizeof(struct ieee80211req_getset_appiebuf) + app_ie->app_buflen);TRACE;return 0;}static intatheros_get_appiebuf2(char *ifname){TRACE;int ret = 0;unsigned char buf[BUF_SIZE] = {[0 ... (BUF_SIZE - 1)] = 0,};int len = BUF_SIZE;struct ieee80211req_getset_appiebuf *app_ie;app_ie = (struct ieee80211req_getset_appiebuf *)buf;memset(buf, 0, sizeof(buf));app_ie->app_frmtype = IEEE80211_APPIE_FRAME_BEACON;app_ie->app_buflen = BUF_SIZE - sizeof(struct ieee80211req_getset_appiebuf);ret = set80211priv(ifname, IEEE80211_IOCTL_GET_APPIEBUF, app_ie, len);hexdump("atheros: GET_APPIEBUF BEACON", app_ie->app_buf, app_ie->app_buflen);memset(buf, 0, sizeof(buf));app_ie->app_frmtype = IEEE80211_APPIE_FRAME_PROBE_RESP;app_ie->app_buflen = BUF_SIZE - sizeof(struct ieee80211req_getset_appiebuf);ret = set80211priv(ifname, IEEE80211_IOCTL_GET_APPIEBUF, app_ie, len);hexdump("atheros: GET_APPIEBUF PROBE_RESP", app_ie->app_buf, app_ie->app_buflen);TRACE;return ret;}static intatheros_clear_appiebuf(char *ifname){TRACE;unsigned char buf[BUF_SIZE] = {[0 ... (BUF_SIZE - 1)] = 0,};int len = 0;atheros_set_appiebuf(ifname, buf, len);TRACE;return 0;}static intatheros_set_appiebuf_vendor(char *ifname){TRACE;unsigned char buf[BUF_SIZE] = {0xdd, 0x04, 0x01, 0x02, 0x03, 0x04};int len = 6;atheros_set_appiebuf(ifname, buf, len);TRACE;return 0;}static intatheros_get_ssid(char *ifname){char buf[BUF_SIZE] = {[0 ... (BUF_SIZE - 1)] = 0,};int len = BUF_SIZE;int ret = set80211priv(ifname, SIOCGIWESSID, buf, len);printf("buf: %s\n", buf);return ret;}intmain(int argc, char *argv[]){char *ifname = NULL;if (argc > 1) {ifname = argv[1];}if (ifname != NULL) {atheros_get_ssid(ifname);atheros_get_appiebuf2(ifname);atheros_clear_appiebuf(ifname);atheros_set_appiebuf_vendor(ifname);atheros_get_appiebuf2(ifname);}return 0;}
Makefile示例
export PATH := /work/atheros/sdk/build/gcc-4.3.3/build_mips/staging_dir/usr/bin:${PATH}#$(warning ========PATH: ${PATH})export CROSS := mips-linux-uclibc-CC = $(CROSS)gccCFLAGS += -g -WallSOURCE += test.call: $(CC) -o test $(SOURCE) $(CFLAGS)
- atheros设置beacon和probe response中的IE信息
- hostapd修改Beacon和Probe Response帧
- request response中的attribute,parameter和header信息
- 人脸识别中的Gallery和Probe
- 如何设置Response中的ContentType
- response(设置头信息、跳转、Cookie)
- 设置response对象当中的头部信息简单应用和个人理解
- (2.3)QCA atheros 无线配置命令——Beacon配置参数
- Linux Device和Driver注册过程中的Probe时机
- servlet中的request和response
- Django中的request和response
- Servlet中的Response和Request
- Servlet中的Request和Response
- response.setHeader设置返回页面的头meta 信息
- iwpriv命令设置Atheros无线网卡
- platform match 和probe
- match()和probe()函数
- Eclipse中的警告信息和拼写错误信息的设置
- 1019 Number Sequence 数论
- Curl模仿http浏览器常见命令
- Assignment 3: Data Structures
- 2013 多校第二场 hdu 4618 Palindrome Sub-Array
- 1020 Anniversary Cake DFS
- atheros设置beacon和probe response中的IE信息
- 系统集成项目管理之项目整体管理
- Spring3.0任务调度
- jsp转发和重定向的区别
- 归档与非归档模式下更改数据文件位置
- struts文件上传
- 1035 Spell checker 暴力模拟
- java代码获取系统时间和执行定时任务
- hdu1241Oil Deposits