最近在通过无线扫描周边的手机mac的事情,拿到AP周边的mac后需要送到应用层,之前接触的都是RTOS的系统,数据交互比较简单,Linux下应用层无法直接和驱动交换数据,需要通过kernel提供的一些通道,因为只是向应用层送数据,和应用层的交互比较简单,所以尝试采用proc文件系统的方式。
开始找到一些列子,编写好程序以后编译移植提示creat_proc_entry接口找不到,感觉很奇怪,直接去翻看对应的头文件linux/proc_fs.h,发现果然没有,原来3.10内核的改动非常之大,很多接口被替换或者去掉了,其中就有creat_proc_entry这个接口。3.10之后推荐使用的是proc_create接口。下面是一个小例子:
#define PROCREG_DIR "myownproc"
struct proc_dir_entry *procRegDir;
static const struct file_operations maclist_proc_fops = {
.owner = THIS_MODULE,
.open = maclist_proc_open,
.write = maclist_proc_write,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
#define MAX_MACLIST_LENGTH 1024
static struct proc_dir_entry *entry_wl_beacon_mac;
static char *maclistbuffer;
static int mac_index;
static int mac_next = 0;
static char fifo_from_user = 0;
UCHAR GLOBAL_AddrLocalNum = 0;
UCHAR GLOBAL_AddrLocal[MAX_MCAST_LIST_SIZE][6];
UCHAR GLOBAL_AddrLocalNum1 = 0;
UCHAR GLOBAL_AddrLocal1[MAX_MCAST_LIST_SIZE][6];
static int maclist_proc_show(struct seq_file *m, void *v)
{
if(maclistbuffer[0] == 's')
{
maclistbuffer[0] = '0';
int index=0;
for(index=0;index
seq_printf(m,"%02x:%02x:%02x:%02x:%02x:%02x\n", GLOBAL_AddrLocal[index][0],GLOBAL_AddrLocal[index][1],GLOBAL_AddrLocal[index][2],GLOBAL_AddrLocal[index][3],GLOBAL_AddrLocal[index][4],GLOBAL_AddrLocal[index][5]);
}
GLOBAL_AddrLocalNum = 0;
}
else if(maclistbuffer[0] == 'a')
{
maclistbuffer[0] = '0';
int index=0;
for(index=0;index
seq_printf(m,"%02x:%02x:%02x:%02x:%02x:%02x\n", GLOBAL_AddrLocal1[index][0],GLOBAL_AddrLocal1[index][1],GLOBAL_AddrLocal1[index][2],GLOBAL_AddrLocal1[index][3],GLOBAL_AddrLocal1[index][4],GLOBAL_AddrLocal1[index][5]);
}
GLOBAL_AddrLocalNum1 = 0;
}
else
{
seq_printf(m,"sta number is %d, proc!\n", GLOBAL_AddrLocalNum);
seq_printf(m,"ap number is %d, proc!\n", GLOBAL_AddrLocalNum1);
}
return 0;
}
static int maclist_proc_open(struct inode *inode, struct file *file)
{
return single_open(file,maclist_proc_show,inode->i_private);
}
static ssize_t maclist_proc_write(struct file *file, const char *buffer, size_t len, loff_t *off)
{
int user_len = 0;
if (len > MAX_MACLIST_LENGTH)
{
user_len = MAX_MACLIST_LENGTH;
}
else
{
user_len = len;
}
if(copy_from_user(maclistbuffer, buffer, user_len))
{
return -EFAULT;
}
return user_len;
}
int wl_proc_init(void)
{
if (procRegDir == NULL)
procRegDir = proc_mkdir(PROCREG_DIR, NULL);
#if 1
maclistbuffer = (char *)vmalloc(MAX_MACLIST_LENGTH);
if(!maclistbuffer)
{
return -ENOMEM;
}
else
{
memset(maclistbuffer,0,MAX_MACLIST_LENGTH);
entry_wl_beacon_mac = proc_create("beaconmaclist", 0x0644, procRegDir, &maclist_proc_fops);
if(entry_wl_beacon_mac)
{
mac_index = 0;
mac_next = 0;
}
else
{
vfree(maclistbuffer);
}
}
#endif
return 0;
}
int wl_proc_exit(void)
{
remove_proc_entry("beaconmaclist", entry_wl_beacon_mac);
vfree(maclistbuffer);
return 0;
}