1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162 |
- #include <linux/module.h>
- #include <linux/dcache.h>
- #include <linux/debugfs.h>
- #include <linux/delay.h>
- #include <linux/mm.h>
- #include <linux/string.h>
- #include <net/iw_handler.h>
- #include "dev.h"
- #include "decl.h"
- #include "host.h"
- #include "debugfs.h"
- static struct dentry *lbs_dir;
- static char *szStates[] = {
- "Connected",
- "Disconnected"
- };
- #ifdef PROC_DEBUG
- static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev);
- #endif
- static int open_file_generic(struct inode *inode, struct file *file)
- {
- file->private_data = inode->i_private;
- return 0;
- }
- static ssize_t write_file_dummy(struct file *file, const char __user *buf,
- size_t count, loff_t *ppos)
- {
- return -EINVAL;
- }
- static const size_t len = PAGE_SIZE;
- static ssize_t lbs_dev_info(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- size_t pos = 0;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- ssize_t res;
- pos += snprintf(buf+pos, len-pos, "state = %s\n",
- szStates[priv->connect_status]);
- pos += snprintf(buf+pos, len-pos, "region_code = %02x\n",
- (u32) priv->regioncode);
- res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
- free_page(addr);
- return res;
- }
- static ssize_t lbs_getscantable(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- size_t pos = 0;
- int numscansdone = 0, res;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- DECLARE_MAC_BUF(mac);
- struct bss_descriptor * iter_bss;
- pos += snprintf(buf+pos, len-pos,
- "# | ch | rssi | bssid | cap | Qual | SSID \n");
- mutex_lock(&priv->lock);
- list_for_each_entry (iter_bss, &priv->network_list, list) {
- u16 ibss = (iter_bss->capability & WLAN_CAPABILITY_IBSS);
- u16 privacy = (iter_bss->capability & WLAN_CAPABILITY_PRIVACY);
- u16 spectrum_mgmt = (iter_bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT);
- pos += snprintf(buf+pos, len-pos,
- "%02u| %03d | %04ld | %s |",
- numscansdone, iter_bss->channel, iter_bss->rssi,
- print_mac(mac, iter_bss->bssid));
- pos += snprintf(buf+pos, len-pos, " %04x-", iter_bss->capability);
- pos += snprintf(buf+pos, len-pos, "%c%c%c |",
- ibss ? 'A' : 'I', privacy ? 'P' : ' ',
- spectrum_mgmt ? 'S' : ' ');
- pos += snprintf(buf+pos, len-pos, " %04d |", SCAN_RSSI(iter_bss->rssi));
- pos += snprintf(buf+pos, len-pos, " %s\n",
- escape_essid(iter_bss->ssid, iter_bss->ssid_len));
- numscansdone++;
- }
- mutex_unlock(&priv->lock);
- res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
- free_page(addr);
- return res;
- }
- static ssize_t lbs_sleepparams_write(struct file *file,
- const char __user *user_buf, size_t count,
- loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- ssize_t buf_size, res;
- int p1, p2, p3, p4, p5, p6;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- buf_size = min(count, len - 1);
- if (copy_from_user(buf, user_buf, buf_size)) {
- res = -EFAULT;
- goto out_unlock;
- }
- res = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
- if (res != 6) {
- res = -EFAULT;
- goto out_unlock;
- }
- priv->sp.sp_error = p1;
- priv->sp.sp_offset = p2;
- priv->sp.sp_stabletime = p3;
- priv->sp.sp_calcontrol = p4;
- priv->sp.sp_extsleepclk = p5;
- priv->sp.sp_reserved = p6;
- res = lbs_prepare_and_send_command(priv,
- CMD_802_11_SLEEP_PARAMS,
- CMD_ACT_SET,
- CMD_OPTION_WAITFORRSP, 0, NULL);
- if (!res)
- res = count;
- else
- res = -EINVAL;
- out_unlock:
- free_page(addr);
- return res;
- }
- static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- ssize_t res;
- size_t pos = 0;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- res = lbs_prepare_and_send_command(priv,
- CMD_802_11_SLEEP_PARAMS,
- CMD_ACT_GET,
- CMD_OPTION_WAITFORRSP, 0, NULL);
- if (res) {
- res = -EFAULT;
- goto out_unlock;
- }
- pos += snprintf(buf, len, "%d %d %d %d %d %d\n", priv->sp.sp_error,
- priv->sp.sp_offset, priv->sp.sp_stabletime,
- priv->sp.sp_calcontrol, priv->sp.sp_extsleepclk,
- priv->sp.sp_reserved);
- res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
- out_unlock:
- free_page(addr);
- return res;
- }
- static ssize_t lbs_extscan(struct file *file, const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- ssize_t res, buf_size;
- union iwreq_data wrqu;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- buf_size = min(count, len - 1);
- if (copy_from_user(buf, userbuf, buf_size)) {
- res = -EFAULT;
- goto out_unlock;
- }
- lbs_send_specific_ssid_scan(priv, buf, strlen(buf)-1, 0);
- memset(&wrqu, 0, sizeof(union iwreq_data));
- wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
- out_unlock:
- free_page(addr);
- return count;
- }
- static void lbs_parse_bssid(char *buf, size_t count,
- struct lbs_ioctl_user_scan_cfg *scan_cfg)
- {
- char *hold;
- unsigned int mac[ETH_ALEN];
- hold = strstr(buf, "bssid=");
- if (!hold)
- return;
- hold += 6;
- sscanf(hold, "%02x:%02x:%02x:%02x:%02x:%02x",
- mac, mac+1, mac+2, mac+3, mac+4, mac+5);
- memcpy(scan_cfg->bssid, mac, ETH_ALEN);
- }
- static void lbs_parse_ssid(char *buf, size_t count,
- struct lbs_ioctl_user_scan_cfg *scan_cfg)
- {
- char *hold, *end;
- ssize_t size;
- hold = strstr(buf, "ssid=");
- if (!hold)
- return;
- hold += 5;
- end = strchr(hold, ' ');
- if (!end)
- end = buf + count - 1;
- size = min((size_t)IW_ESSID_MAX_SIZE, (size_t) (end - hold));
- strncpy(scan_cfg->ssid, hold, size);
- return;
- }
- static int lbs_parse_clear(char *buf, size_t count, const char *tag)
- {
- char *hold;
- int val;
- hold = strstr(buf, tag);
- if (!hold)
- return 0;
- hold += strlen(tag);
- sscanf(hold, "%d", &val);
- if (val != 0)
- val = 1;
- return val;
- }
- static int lbs_parse_dur(char *buf, size_t count,
- struct lbs_ioctl_user_scan_cfg *scan_cfg)
- {
- char *hold;
- int val;
- hold = strstr(buf, "dur=");
- if (!hold)
- return 0;
- hold += 4;
- sscanf(hold, "%d", &val);
- return val;
- }
- static void lbs_parse_type(char *buf, size_t count,
- struct lbs_ioctl_user_scan_cfg *scan_cfg)
- {
- char *hold;
- int val;
- hold = strstr(buf, "type=");
- if (!hold)
- return;
- hold += 5;
- sscanf(hold, "%d", &val);
- /* type=1,2 or 3 */
- if (val < 1 || val > 3)
- return;
- scan_cfg->bsstype = val;
- return;
- }
- static ssize_t lbs_setuserscan(struct file *file,
- const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- ssize_t res, buf_size;
- struct lbs_ioctl_user_scan_cfg *scan_cfg;
- union iwreq_data wrqu;
- int dur;
- char *buf = (char *)get_zeroed_page(GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
-
- buf_size = min(count, len - 1);
- if (copy_from_user(buf, userbuf, buf_size)) {
- res = -EFAULT;
- goto out_buf;
- }
- scan_cfg = kzalloc(sizeof(struct lbs_ioctl_user_scan_cfg), GFP_KERNEL);
- if (!scan_cfg) {
- res = -ENOMEM;
- goto out_buf;
- }
- res = count;
- scan_cfg->bsstype = LBS_SCAN_BSS_TYPE_ANY;
- dur = lbs_parse_dur(buf, count, scan_cfg);
- lbs_parse_bssid(buf, count, scan_cfg);
- scan_cfg->clear_bssid = lbs_parse_clear(buf, count, "clear_bssid=");
- lbs_parse_ssid(buf, count, scan_cfg);
- scan_cfg->clear_ssid = lbs_parse_clear(buf, count, "clear_ssid=");
- lbs_parse_type(buf, count, scan_cfg);
- lbs_scan_networks(priv, scan_cfg, 1);
- wait_event_interruptible(priv->cmd_pending,
- priv->surpriseremoved || !priv->last_scanned_channel);
- if (priv->surpriseremoved)
- goto out_scan_cfg;
- memset(&wrqu, 0x00, sizeof(union iwreq_data));
- wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
- out_scan_cfg:
- kfree(scan_cfg);
- out_buf:
- free_page((unsigned long)buf);
- return res;
- }
- /*
- * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
- * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
- * firmware. Here's an example:
- * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
- * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
- * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
- *
- * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
- * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
- * defined in mrvlietypes_thresholds
- *
- * This function searches in this TLV data chunk for a given TLV type
- * and returns a pointer to the first data byte of the TLV, or to NULL
- * if the TLV hasn't been found.
- */
- static void *lbs_tlv_find(u16 tlv_type, const u8 *tlv, u16 size)
- {
- __le16 le_type = cpu_to_le16(tlv_type);
- ssize_t pos = 0;
- struct mrvlietypesheader *tlv_h;
- while (pos < size) {
- u16 length;
- tlv_h = (struct mrvlietypesheader *) tlv;
- if (tlv_h->type == le_type)
- return tlv_h;
- if (tlv_h->len == 0)
- return NULL;
- length = le16_to_cpu(tlv_h->len) +
- sizeof(struct mrvlietypesheader);
- pos += length;
- tlv += length;
- }
- return NULL;
- }
- /*
- * This just gets the bitmap of currently subscribed events. Used when
- * adding an additonal event subscription.
- */
- static u16 lbs_get_events_bitmap(struct lbs_private *priv)
- {
- ssize_t res;
- struct cmd_ds_802_11_subscribe_event *events = kzalloc(
- sizeof(struct cmd_ds_802_11_subscribe_event),
- GFP_KERNEL);
- res = lbs_prepare_and_send_command(priv,
- CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
- CMD_OPTION_WAITFORRSP, 0, events);
- if (res) {
- kfree(events);
- return 0;
- }
- return le16_to_cpu(events->events);
- }
- static ssize_t lbs_threshold_read(
- u16 tlv_type, u16 event_mask,
- struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- ssize_t res = 0;
- size_t pos = 0;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- u8 value;
- u8 freq;
- struct cmd_ds_802_11_subscribe_event *events = kzalloc(
- sizeof(struct cmd_ds_802_11_subscribe_event),
- GFP_KERNEL);
- struct mrvlietypes_thresholds *got;
- res = lbs_prepare_and_send_command(priv,
- CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
- CMD_OPTION_WAITFORRSP, 0, events);
- if (res) {
- kfree(events);
- return res;
- }
- got = lbs_tlv_find(tlv_type, events->tlv, sizeof(events->tlv));
- if (got) {
- value = got->value;
- freq = got->freq;
- }
- kfree(events);
- if (got)
- pos += snprintf(buf, len, "%d %d %d\n", value, freq,
- !!(le16_to_cpu(events->events) & event_mask));
- res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
- free_page(addr);
- return res;
- }
- static ssize_t lbs_threshold_write(
- u16 tlv_type, u16 event_mask,
- struct file *file,
- const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- ssize_t res, buf_size;
- int value, freq, curr_mask, new_mask;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- struct cmd_ds_802_11_subscribe_event *events;
- buf_size = min(count, len - 1);
- if (copy_from_user(buf, userbuf, buf_size)) {
- res = -EFAULT;
- goto out_unlock;
- }
- res = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
- if (res != 3) {
- res = -EFAULT;
- goto out_unlock;
- }
- curr_mask = lbs_get_events_bitmap(priv);
- if (new_mask)
- new_mask = curr_mask | event_mask;
- else
- new_mask = curr_mask & ~event_mask;
- /* Now everything is set and we can send stuff down to the firmware */
- events = kzalloc(
- sizeof(struct cmd_ds_802_11_subscribe_event),
- GFP_KERNEL);
- if (events) {
- struct mrvlietypes_thresholds *tlv =
- (struct mrvlietypes_thresholds *) events->tlv;
- events->action = cpu_to_le16(CMD_ACT_SET);
- events->events = cpu_to_le16(new_mask);
- tlv->header.type = cpu_to_le16(tlv_type);
- tlv->header.len = cpu_to_le16(
- sizeof(struct mrvlietypes_thresholds) -
- sizeof(struct mrvlietypesheader));
- tlv->value = value;
- if (tlv_type != TLV_TYPE_BCNMISS)
- tlv->freq = freq;
- lbs_prepare_and_send_command(priv,
- CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_SET,
- CMD_OPTION_WAITFORRSP, 0, events);
- kfree(events);
- }
- res = count;
- out_unlock:
- free_page(addr);
- return res;
- }
- static ssize_t lbs_lowrssi_read(
- struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
- file, userbuf, count, ppos);
- }
- static ssize_t lbs_lowrssi_write(
- struct file *file, const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
- file, userbuf, count, ppos);
- }
- static ssize_t lbs_lowsnr_read(
- struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
- file, userbuf, count, ppos);
- }
- static ssize_t lbs_lowsnr_write(
- struct file *file, const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
- file, userbuf, count, ppos);
- }
- static ssize_t lbs_failcount_read(
- struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
- file, userbuf, count, ppos);
- }
- static ssize_t lbs_failcount_write(
- struct file *file, const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
- file, userbuf, count, ppos);
- }
- static ssize_t lbs_highrssi_read(
- struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
- file, userbuf, count, ppos);
- }
- static ssize_t lbs_highrssi_write(
- struct file *file, const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
- file, userbuf, count, ppos);
- }
- static ssize_t lbs_highsnr_read(
- struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
- file, userbuf, count, ppos);
- }
- static ssize_t lbs_highsnr_write(
- struct file *file, const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
- file, userbuf, count, ppos);
- }
- static ssize_t lbs_bcnmiss_read(
- struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
- file, userbuf, count, ppos);
- }
- static ssize_t lbs_bcnmiss_write(
- struct file *file, const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
- file, userbuf, count, ppos);
- }
- static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- struct lbs_offset_value offval;
- ssize_t pos = 0;
- int ret;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- offval.offset = priv->mac_offset;
- offval.value = 0;
- ret = lbs_prepare_and_send_command(priv,
- CMD_MAC_REG_ACCESS, 0,
- CMD_OPTION_WAITFORRSP, 0, &offval);
- mdelay(10);
- pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
- priv->mac_offset, priv->offsetvalue.value);
- ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
- free_page(addr);
- return ret;
- }
- static ssize_t lbs_rdmac_write(struct file *file,
- const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- ssize_t res, buf_size;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- buf_size = min(count, len - 1);
- if (copy_from_user(buf, userbuf, buf_size)) {
- res = -EFAULT;
- goto out_unlock;
- }
- priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
- res = count;
- out_unlock:
- free_page(addr);
- return res;
- }
- static ssize_t lbs_wrmac_write(struct file *file,
- const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- ssize_t res, buf_size;
- u32 offset, value;
- struct lbs_offset_value offval;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- buf_size = min(count, len - 1);
- if (copy_from_user(buf, userbuf, buf_size)) {
- res = -EFAULT;
- goto out_unlock;
- }
- res = sscanf(buf, "%x %x", &offset, &value);
- if (res != 2) {
- res = -EFAULT;
- goto out_unlock;
- }
- offval.offset = offset;
- offval.value = value;
- res = lbs_prepare_and_send_command(priv,
- CMD_MAC_REG_ACCESS, 1,
- CMD_OPTION_WAITFORRSP, 0, &offval);
- mdelay(10);
- res = count;
- out_unlock:
- free_page(addr);
- return res;
- }
- static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- struct lbs_offset_value offval;
- ssize_t pos = 0;
- int ret;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- offval.offset = priv->bbp_offset;
- offval.value = 0;
- ret = lbs_prepare_and_send_command(priv,
- CMD_BBP_REG_ACCESS, 0,
- CMD_OPTION_WAITFORRSP, 0, &offval);
- mdelay(10);
- pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
- priv->bbp_offset, priv->offsetvalue.value);
- ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
- free_page(addr);
- return ret;
- }
- static ssize_t lbs_rdbbp_write(struct file *file,
- const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- ssize_t res, buf_size;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- buf_size = min(count, len - 1);
- if (copy_from_user(buf, userbuf, buf_size)) {
- res = -EFAULT;
- goto out_unlock;
- }
- priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
- res = count;
- out_unlock:
- free_page(addr);
- return res;
- }
- static ssize_t lbs_wrbbp_write(struct file *file,
- const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- ssize_t res, buf_size;
- u32 offset, value;
- struct lbs_offset_value offval;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- buf_size = min(count, len - 1);
- if (copy_from_user(buf, userbuf, buf_size)) {
- res = -EFAULT;
- goto out_unlock;
- }
- res = sscanf(buf, "%x %x", &offset, &value);
- if (res != 2) {
- res = -EFAULT;
- goto out_unlock;
- }
- offval.offset = offset;
- offval.value = value;
- res = lbs_prepare_and_send_command(priv,
- CMD_BBP_REG_ACCESS, 1,
- CMD_OPTION_WAITFORRSP, 0, &offval);
- mdelay(10);
- res = count;
- out_unlock:
- free_page(addr);
- return res;
- }
- static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- struct lbs_offset_value offval;
- ssize_t pos = 0;
- int ret;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- offval.offset = priv->rf_offset;
- offval.value = 0;
- ret = lbs_prepare_and_send_command(priv,
- CMD_RF_REG_ACCESS, 0,
- CMD_OPTION_WAITFORRSP, 0, &offval);
- mdelay(10);
- pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
- priv->rf_offset, priv->offsetvalue.value);
- ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
- free_page(addr);
- return ret;
- }
- static ssize_t lbs_rdrf_write(struct file *file,
- const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- ssize_t res, buf_size;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- buf_size = min(count, len - 1);
- if (copy_from_user(buf, userbuf, buf_size)) {
- res = -EFAULT;
- goto out_unlock;
- }
- priv->rf_offset = simple_strtoul((char *)buf, NULL, 16);
- res = count;
- out_unlock:
- free_page(addr);
- return res;
- }
- static ssize_t lbs_wrrf_write(struct file *file,
- const char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- struct lbs_private *priv = file->private_data;
- ssize_t res, buf_size;
- u32 offset, value;
- struct lbs_offset_value offval;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- buf_size = min(count, len - 1);
- if (copy_from_user(buf, userbuf, buf_size)) {
- res = -EFAULT;
- goto out_unlock;
- }
- res = sscanf(buf, "%x %x", &offset, &value);
- if (res != 2) {
- res = -EFAULT;
- goto out_unlock;
- }
- offval.offset = offset;
- offval.value = value;
- res = lbs_prepare_and_send_command(priv,
- CMD_RF_REG_ACCESS, 1,
- CMD_OPTION_WAITFORRSP, 0, &offval);
- mdelay(10);
- res = count;
- out_unlock:
- free_page(addr);
- return res;
- }
- #define FOPS(fread, fwrite) { \
- .owner = THIS_MODULE, \
- .open = open_file_generic, \
- .read = (fread), \
- .write = (fwrite), \
- }
- struct lbs_debugfs_files {
- char *name;
- int perm;
- struct file_operations fops;
- };
- static struct lbs_debugfs_files debugfs_files[] = {
- { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
- { "getscantable", 0444, FOPS(lbs_getscantable,
- write_file_dummy), },
- { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
- lbs_sleepparams_write), },
- { "extscan", 0600, FOPS(NULL, lbs_extscan), },
- { "setuserscan", 0600, FOPS(NULL, lbs_setuserscan), },
- };
- static struct lbs_debugfs_files debugfs_events_files[] = {
- {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
- lbs_lowrssi_write), },
- {"low_snr", 0644, FOPS(lbs_lowsnr_read,
- lbs_lowsnr_write), },
- {"failure_count", 0644, FOPS(lbs_failcount_read,
- lbs_failcount_write), },
- {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
- lbs_bcnmiss_write), },
- {"high_rssi", 0644, FOPS(lbs_highrssi_read,
- lbs_highrssi_write), },
- {"high_snr", 0644, FOPS(lbs_highsnr_read,
- lbs_highsnr_write), },
- };
- static struct lbs_debugfs_files debugfs_regs_files[] = {
- {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
- {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
- {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
- {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
- {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
- {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
- };
- void lbs_debugfs_init(void)
- {
- if (!lbs_dir)
- lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
- return;
- }
- void lbs_debugfs_remove(void)
- {
- if (lbs_dir)
- debugfs_remove(lbs_dir);
- return;
- }
- void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
- {
- int i;
- struct lbs_debugfs_files *files;
- if (!lbs_dir)
- goto exit;
- priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
- if (!priv->debugfs_dir)
- goto exit;
- for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
- files = &debugfs_files[i];
- priv->debugfs_files[i] = debugfs_create_file(files->name,
- files->perm,
- priv->debugfs_dir,
- priv,
- &files->fops);
- }
- priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
- if (!priv->events_dir)
- goto exit;
- for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
- files = &debugfs_events_files[i];
- priv->debugfs_events_files[i] = debugfs_create_file(files->name,
- files->perm,
- priv->events_dir,
- priv,
- &files->fops);
- }
- priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
- if (!priv->regs_dir)
- goto exit;
- for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
- files = &debugfs_regs_files[i];
- priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
- files->perm,
- priv->regs_dir,
- priv,
- &files->fops);
- }
- #ifdef PROC_DEBUG
- lbs_debug_init(priv, dev);
- #endif
- exit:
- return;
- }
- void lbs_debugfs_remove_one(struct lbs_private *priv)
- {
- int i;
- for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
- debugfs_remove(priv->debugfs_regs_files[i]);
- debugfs_remove(priv->regs_dir);
- for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
- debugfs_remove(priv->debugfs_events_files[i]);
- debugfs_remove(priv->events_dir);
- #ifdef PROC_DEBUG
- debugfs_remove(priv->debugfs_debug);
- #endif
- for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
- debugfs_remove(priv->debugfs_files[i]);
- debugfs_remove(priv->debugfs_dir);
- }
- /* debug entry */
- #ifdef PROC_DEBUG
- #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
- #define item_addr(n) (offsetof(struct lbs_private, n))
- struct debug_data {
- char name[32];
- u32 size;
- size_t addr;
- };
- /* To debug any member of struct lbs_private, simply add one line here.
- */
- static struct debug_data items[] = {
- {"intcounter", item_size(intcounter), item_addr(intcounter)},
- {"psmode", item_size(psmode), item_addr(psmode)},
- {"psstate", item_size(psstate), item_addr(psstate)},
- };
- static int num_of_items = ARRAY_SIZE(items);
- /**
- * @brief proc read function
- *
- * @param page pointer to buffer
- * @param s read data starting position
- * @param off offset
- * @param cnt counter
- * @param eof end of file flag
- * @param data data to output
- * @return number of output data
- */
- static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
- {
- int val = 0;
- size_t pos = 0;
- ssize_t res;
- char *p;
- int i;
- struct debug_data *d;
- unsigned long addr = get_zeroed_page(GFP_KERNEL);
- char *buf = (char *)addr;
- p = buf;
- d = (struct debug_data *)file->private_data;
- for (i = 0; i < num_of_items; i++) {
- if (d[i].size == 1)
- val = *((u8 *) d[i].addr);
- else if (d[i].size == 2)
- val = *((u16 *) d[i].addr);
- else if (d[i].size == 4)
- val = *((u32 *) d[i].addr);
- else if (d[i].size == 8)
- val = *((u64 *) d[i].addr);
- pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
- }
- res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
- free_page(addr);
- return res;
- }
- /**
- * @brief proc write function
- *
- * @param f file pointer
- * @param buf pointer to data buffer
- * @param cnt data number to write
- * @param data data to write
- * @return number of data
- */
- static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
- size_t cnt, loff_t *ppos)
- {
- int r, i;
- char *pdata;
- char *p;
- char *p0;
- char *p1;
- char *p2;
- struct debug_data *d = (struct debug_data *)f->private_data;
- pdata = kmalloc(cnt, GFP_KERNEL);
- if (pdata == NULL)
- return 0;
- if (copy_from_user(pdata, buf, cnt)) {
- lbs_deb_debugfs("Copy from user failed\n");
- kfree(pdata);
- return 0;
- }
- p0 = pdata;
- for (i = 0; i < num_of_items; i++) {
- do {
- p = strstr(p0, d[i].name);
- if (p == NULL)
- break;
- p1 = strchr(p, '\n');
- if (p1 == NULL)
- break;
- p0 = p1++;
- p2 = strchr(p, '=');
- if (!p2)
- break;
- p2++;
- r = simple_strtoul(p2, NULL, 0);
- if (d[i].size == 1)
- *((u8 *) d[i].addr) = (u8) r;
- else if (d[i].size == 2)
- *((u16 *) d[i].addr) = (u16) r;
- else if (d[i].size == 4)
- *((u32 *) d[i].addr) = (u32) r;
- else if (d[i].size == 8)
- *((u64 *) d[i].addr) = (u64) r;
- break;
- } while (1);
- }
- kfree(pdata);
- return (ssize_t)cnt;
- }
- static struct file_operations lbs_debug_fops = {
- .owner = THIS_MODULE,
- .open = open_file_generic,
- .write = lbs_debugfs_write,
- .read = lbs_debugfs_read,
- };
- /**
- * @brief create debug proc file
- *
- * @param priv pointer struct lbs_private
- * @param dev pointer net_device
- * @return N/A
- */
- static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev)
- {
- int i;
- if (!priv->debugfs_dir)
- return;
- for (i = 0; i < num_of_items; i++)
- items[i].addr += (size_t) priv;
- priv->debugfs_debug = debugfs_create_file("debug", 0644,
- priv->debugfs_dir, &items[0],
- &lbs_debug_fops);
- }
- #endif
|