s32 wldev_iovar_setint_bsscfg( struct net_device *dev, s8 *iovar, s32 val, s32 bssidx) { s8 iovar_buf[WLC_IOCTL_SMLEN]; val = htod32(val); memset(iovar_buf, 0, sizeof(iovar_buf)); return wldev_iovar_setbuf_bsscfg(dev, iovar, &val, sizeof(val), iovar_buf, sizeof(iovar_buf), bssidx, NULL); }
static int wl_android_get_assoc_res_ies(struct net_device *dev, char *command) { int error; u8 buf[WL_ASSOC_INFO_MAX]; wl_assoc_info_t assoc_info; u32 resp_ies_len = 0; int bytes_written = 0; WL_TRACE(("%s: wl_iw_get_assoc_res_ies\n", dev->name)); error = wldev_iovar_getbuf(dev, "assoc_info", NULL, 0, buf, WL_ASSOC_INFO_MAX, NULL); if (unlikely(error)) { WL_ERR(("could not get assoc info (%d)\n", error)); return -1; } memcpy(&assoc_info, buf, sizeof(wl_assoc_info_t)); assoc_info.req_len = htod32(assoc_info.req_len); assoc_info.resp_len = htod32(assoc_info.resp_len); assoc_info.flags = htod32(assoc_info.flags); if (assoc_info.resp_len) { resp_ies_len = assoc_info.resp_len - sizeof(struct dot11_assoc_resp); } /* first 4 bytes are ie len */ memcpy(command, &resp_ies_len, sizeof(u32)); bytes_written = sizeof(u32); /* get the association resp IE's if there are any */ if (resp_ies_len) { error = wldev_iovar_getbuf(dev, "assoc_resp_ies", NULL, 0, buf, WL_ASSOC_INFO_MAX, NULL); if (unlikely(error)) { WL_ERR(("could not get assoc resp_ies (%d)\n", error)); return -1; } memcpy(command+sizeof(u32), buf, resp_ies_len); bytes_written += resp_ies_len; } return bytes_written; }
/* * HAPD_MAC_FILTER mac_mode mac_cnt mac_addr1 mac_addr2 * */ static int wl_android_set_mac_address_filter(struct net_device *dev, const char* str) { int i; int ret = 0; int macnum = 0; int macmode = MACLIST_MODE_DISABLED; struct maclist *list; char eabuf[ETHER_ADDR_STR_LEN]; /* string should look like below (macmode/macnum/maclist) */ /* 1 2 00:11:22:33:44:55 00:11:22:33:44:ff */ /* get the MAC filter mode */ macmode = bcm_atoi(strsep((char**)&str, " ")); if (macmode < MACLIST_MODE_DISABLED || macmode > MACLIST_MODE_ALLOW) { DHD_ERROR(("%s : invalid macmode %d\n", __FUNCTION__, macmode)); return -1; } macnum = bcm_atoi(strsep((char**)&str, " ")); if (macnum < 0 || macnum > MAX_NUM_MAC_FILT) { DHD_ERROR(("%s : invalid number of MAC address entries %d\n", __FUNCTION__, macnum)); return -1; } /* allocate memory for the MAC list */ list = (struct maclist*)kmalloc(sizeof(int) + sizeof(struct ether_addr) * macnum, GFP_KERNEL); if (!list) { DHD_ERROR(("%s : failed to allocate memory\n", __FUNCTION__)); return -1; } /* prepare the MAC list */ list->count = htod32(macnum); bzero((char *)eabuf, ETHER_ADDR_STR_LEN); for (i = 0; i < list->count; i++) { strncpy(eabuf, strsep((char**)&str, " "), ETHER_ADDR_STR_LEN - 1); if (!(ret = bcm_ether_atoe(eabuf, &list->ea[i]))) { DHD_ERROR(("%s : mac parsing err index=%d, addr=%s\n", __FUNCTION__, i, eabuf)); list->count--; break; } DHD_INFO(("%s : %d/%d MACADDR=%s", __FUNCTION__, i, list->count, eabuf)); } /* set the list */ if ((ret = wl_android_set_ap_mac_list(dev, macmode, list)) != 0) DHD_ERROR(("%s : Setting MAC list failed error=%d\n", __FUNCTION__, ret)); kfree(list); return 0; }
int wlmPreambleSet(WLM_PREAMBLE preamble) { preamble = htod32(preamble); if (wlu_set(irh, WLC_SET_PLCPHDR, &preamble, sizeof(preamble))) { printf("wlmPreambleSet: %s\n", wlmLastError()); return FALSE; } return TRUE; }
int wl_ie(void *wl, uchar id, uchar len, uchar *data) { int err; uchar *buf; uint32 pktflag; int iecount; ie_setbuf_t *ie_setbuf; uchar count; /* use VNDR_IE_CUSTOM_FLAG flags for none vendor IE */ pktflag = htod32(VNDR_IE_CUSTOM_FLAG); count = sizeof(ie_setbuf_t) + len - 1; buf = malloc(count); if (buf == NULL) { fprintf(stderr, "memory alloc failure\n"); return -1; } ie_setbuf = (ie_setbuf_t *) buf; /* Copy the ie SET command ("add") to the buffer */ strncpy(ie_setbuf->cmd, "add", VNDR_IE_CMD_LEN - 1); ie_setbuf->cmd[VNDR_IE_CMD_LEN - 1] = '\0'; /* Buffer contains only 1 IE */ iecount = htod32(1); memcpy((void *)&ie_setbuf->ie_buffer.iecount, &iecount, sizeof(int)); memcpy((void *)&ie_setbuf->ie_buffer.ie_list[0].pktflag, &pktflag, sizeof(uint32)); /* Now, add the IE to the buffer */ ie_setbuf->ie_buffer.ie_list[0].ie_data.id = id; ie_setbuf->ie_buffer.ie_list[0].ie_data.len = len; memcpy((uchar *)&ie_setbuf->ie_buffer.ie_list[0].ie_data.data[0], data, len); err = wlu_var_setbuf(wl, "ie", buf, count); free(buf); return (err); }
int wlmRxAntSet(int antenna) { /* Set 'antdiv' - select receive antenna */ antenna = htod32(antenna); if (wlu_set(irh, WLC_SET_ANTDIV, &antenna, sizeof(antenna))) { printf("wlmRxAntSet: %s\n", wlmLastError()); return FALSE; } return TRUE; }
int wlmTxAntSet(int antenna) { /* Set 'txant' - select transmit antenna */ antenna = htod32(antenna); if (wlu_set(irh, WLC_SET_TXANT, &antenna, sizeof(antenna))) { printf("wlmTxAntSet: %s\n", wlmLastError()); return FALSE; } return TRUE; }
int wlmGmodeSet(WLM_GMODE gmode) { /* Set 'gmode' - select mode in 2.4G band */ gmode = htod32(gmode); if (wlu_set(irh, WLC_SET_GMODE, (void *)&gmode, sizeof(gmode))) { printf("wlmGmodeSet: %s\n", wlmLastError()); return FALSE; } return TRUE; }
int dhd_iscan_request(void * dhdp, uint16 action) { int rc; wl_iscan_params_t params; dhd_pub_t *dhd = dhd_bus_pub(dhdp); char buf[WLC_IOCTL_SMLEN]; DHD_TRACE(("%s: Entered\n", __FUNCTION__)); memset(¶ms, 0, sizeof(wl_iscan_params_t)); memcpy(¶ms.params.bssid, ðer_bcast, ETHER_ADDR_LEN); params.params.bss_type = DOT11_BSSTYPE_ANY; params.params.scan_type = DOT11_SCANTYPE_ACTIVE; params.params.nprobes = htod32(-1); params.params.active_time = htod32(-1); params.params.passive_time = htod32(-1); params.params.home_time = htod32(-1); params.params.channel_num = htod32(0); params.version = htod32(ISCAN_REQ_VERSION); params.action = htod16(action); params.scan_duration = htod16(0); bcm_mkiovar("iscan", (char *)¶ms, sizeof(wl_iscan_params_t), buf, WLC_IOCTL_SMLEN); rc = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, WLC_IOCTL_SMLEN, TRUE, 0); return rc; }
static int dhd_iscan_get_partial_result(void *dhdp, uint *scan_count) { wl_iscan_results_t *list_buf; wl_iscan_results_t list; wl_scan_results_t *results; iscan_buf_t *iscan_cur; int status = -1; dhd_pub_t *dhd = dhd_bus_pub(dhdp); int rc; DHD_TRACE(("%s: Enter\n", __FUNCTION__)); iscan_cur = dhd_iscan_allocate_buf(dhd, &iscan_chain); if (!iscan_cur) { DHD_ERROR(("%s: Failed to allocate node\n", __FUNCTION__)); dhd_iscan_free_buf(dhdp, 0); dhd_iscan_request(dhdp, WL_SCAN_ACTION_ABORT); dhd_ind_scan_confirm(dhdp, FALSE); goto fail; } dhd_iscan_lock(); memset(iscan_cur->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN); list_buf = (wl_iscan_results_t*)iscan_cur->iscan_buf; results = &list_buf->results; results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE; results->version = 0; results->count = 0; memset(&list, 0, sizeof(list)); list.results.buflen = htod32(WLC_IW_ISCAN_MAXLEN); bcm_mkiovar("iscanresults", (char *)&list, WL_ISCAN_RESULTS_FIXED_SIZE, iscan_cur->iscan_buf, WLC_IW_ISCAN_MAXLEN); rc = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iscan_cur->iscan_buf, WLC_IW_ISCAN_MAXLEN, FALSE, 0); results->buflen = dtoh32(results->buflen); results->version = dtoh32(results->version); *scan_count = results->count = dtoh32(results->count); status = dtoh32(list_buf->status); DHD_TRACE(("%s: Got %d resuls\n", __FUNCTION__, results->count)); dhd_iscan_unlock(); if (!(*scan_count)) { dhd_iscan_free_buf(dhdp, iscan_cur); } fail: return status; }
int wlmBandSet(WLM_BAND band) { band = htod32(band); if (wlu_set(irh, WLC_SET_BAND, (void *)&band, sizeof(band))) { printf("wlmBandSet: %s\n", wlmLastError()); return FALSE; } curBand = band; return TRUE; }
/* produce a sparse image file */ int make_sparse_image(FILE *fp, Bit64u sec) { Bit64u numpages; sparse_header_t header; size_t sizesofar; size_t padtopagesize; memset(&header, 0, sizeof(header)); header.magic = htod32(SPARSE_HEADER_MAGIC); header.version = htod32(SPARSE_HEADER_VERSION); header.pagesize = htod32((1 << 10) * 32); // Use 32 KB Pages - could be configurable numpages = (sec / (dtoh32(header.pagesize) / 512)) + 1; header.numpages = htod32((Bit32u)numpages); if (numpages != dtoh32(header.numpages)) { fclose (fp); fatal ("ERROR: The disk image is too large for a sparse image!"); // Could increase page size here. // But note this only happens at 128 Terabytes! } if (fwrite(&header, sizeof(header), 1, fp) != 1) { fclose (fp); fatal ("ERROR: The disk image is not complete - could not write header!"); } fileset(fp, 0xff, 4 * dtoh32(header.numpages)); sizesofar = SPARSE_HEADER_SIZE + (4 * dtoh32(header.numpages)); padtopagesize = dtoh32(header.pagesize) - (sizesofar & (dtoh32(header.pagesize) - 1)); fileset(fp, 0, padtopagesize); return 0; }
/** Format a bsscfg indexed iovar buffer. The bsscfg index will be * taken care of in dhd_ioctl_entry. Internal use only, not exposed to * wl_iw, wl_cfg80211 and wl_cfgp2p */ s32 wldev_mkiovar_bsscfg( const s8 *iovar_name, s8 *param, s32 paramlen, s8 *iovar_buf, s32 buflen, s32 bssidx) { const s8 *prefix = "bsscfg:"; s8 *p; u32 prefixlen; u32 namelen; u32 iolen; if (bssidx == 0) { return wldev_mkiovar((s8*)iovar_name, (s8 *)param, paramlen, (s8 *) iovar_buf, buflen); } prefixlen = (u32) strlen(prefix); /* lengh of bsscfg prefix */ namelen = (u32) strlen(iovar_name) + 1; /* lengh of iovar name + null */ iolen = prefixlen + namelen + sizeof(u32) + paramlen; if (buflen < 0 || iolen > (u32)buflen) { WLDEV_ERROR(("%s: buffer is too short\n", __FUNCTION__)); return BCME_BUFTOOSHORT; } if (iovar_buf && buflen != 0) memset(iovar_buf, 0, buflen); else return BCME_BADARG; p = (s8 *)iovar_buf; /* copy prefix, no null */ memcpy(p, prefix, prefixlen); p += prefixlen; /* copy iovar name including null */ memcpy(p, iovar_name, namelen); p += namelen; /* bss config index as first param */ bssidx = htod32(bssidx); memcpy(p, &bssidx, sizeof(u32)); p += sizeof(u32); /* parameter buffer follows */ if (paramlen) memcpy(p, param, paramlen); return iolen; }
int vmware3_image_t::write_ints(int fd, Bit32u *buffer, size_t count) { size_t i; Bit32u *p; for (p = buffer, i=0; i<count; p++, i++) *p=htod32(*p); int res=::write(fd, (void*)buffer, count * 4); for (p = buffer, i=0; i<count; p++, i++) *p=dtoh32(*p); return res; }
int wldev_get_mode( struct net_device *dev, uint8 *cap) { int error = 0; int chanspec = 0; uint16 band = 0; uint16 bandwidth = 0; wl_bss_info_t *bss = NULL; char* buf = kmalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); if (!buf) return -1; *(u32*) buf = htod32(WL_EXTRA_BUF_MAX); error = wldev_ioctl(dev, WLC_GET_BSS_INFO, (void*)buf, WL_EXTRA_BUF_MAX, false); if (error) { WLDEV_ERROR(("%s:failed:%d\n", __FUNCTION__, error)); return -1; } bss = (struct wl_bss_info *)(buf + 4); chanspec = wl_chspec_driver_to_host(bss->chanspec); band = chanspec & WL_CHANSPEC_BAND_MASK; bandwidth = chanspec & WL_CHANSPEC_BW_MASK; if (band == WL_CHANSPEC_BAND_2G) { if (bss->n_cap) strcpy(cap, "n"); else strcpy(cap, "bg"); } else if (band == WL_CHANSPEC_BAND_5G) { if (bandwidth == WL_CHANSPEC_BW_80) strcpy(cap, "ac"); else if ((bandwidth == WL_CHANSPEC_BW_40) || (bandwidth == WL_CHANSPEC_BW_20)) { if ((bss->nbss_cap & 0xf00) && (bss->n_cap)) strcpy(cap, "n|ac"); else if (bss->n_cap) strcpy(cap, "n"); else if (bss->vht_cap) strcpy(cap, "ac"); else strcpy(cap, "a"); } else { WLDEV_ERROR(("%s:Mode get failed\n", __FUNCTION__)); return -1; } } return error; }
s32 wldev_mkiovar_bsscfg( const s8 *iovar_name, s8 *param, s32 paramlen, s8 *iovar_buf, s32 buflen, s32 bssidx) { const s8 *prefix = "bsscfg:"; s8 *p; u32 prefixlen; u32 namelen; u32 iolen; if (bssidx == 0) { return wldev_mkiovar((s8*)iovar_name, (s8 *)param, paramlen, (s8 *) iovar_buf, buflen); } prefixlen = (u32) strlen(prefix); namelen = (u32) strlen(iovar_name) + 1; iolen = prefixlen + namelen + sizeof(u32) + paramlen; if (buflen < 0 || iolen > (u32)buflen) { WLDEV_ERROR(("%s: buffer is too short\n", __FUNCTION__)); return BCME_BUFTOOSHORT; } p = (s8 *)iovar_buf; memcpy(p, prefix, prefixlen); p += prefixlen; memcpy(p, iovar_name, namelen); p += namelen; bssidx = htod32(bssidx); memcpy(p, &bssidx, sizeof(u32)); p += sizeof(u32); if (paramlen) memcpy(p, param, paramlen); return iolen; }
/* * softap channel autoselect */ int wldev_get_auto_channel(struct net_device *dev, int *chan) { int chosen = 0; wl_uint32_list_t request; int retry = 0; int updown = 0; int ret = 0; wlc_ssid_t null_ssid; memset(&null_ssid, 0, sizeof(wlc_ssid_t)); ret |= wldev_ioctl(dev, WLC_UP, &updown, sizeof(updown), true); ret |= wldev_ioctl(dev, WLC_SET_SSID, &null_ssid, sizeof(null_ssid), true); request.count = htod32(0); ret = wldev_ioctl(dev, WLC_START_CHANNEL_SEL, &request, sizeof(request), true); if (ret < 0) { WLDEV_ERROR(("can't start auto channel scan:%d\n", ret)); goto fail; } while (retry++ < 15) { bcm_mdelay(350); ret = wldev_ioctl(dev, WLC_GET_CHANNEL_SEL, &chosen, sizeof(chosen), false); if ((ret == 0) && (dtoh32(chosen) != 0)) { *chan = (uint16)chosen & 0x00FF; /* covert chanspec --> chan number */ printf("%s: Got channel = %d, attempt:%d\n", __FUNCTION__, *chan, retry); break; } } if ((ret = wldev_ioctl(dev, WLC_DOWN, &updown, sizeof(updown), true)) < 0) { WLDEV_ERROR(("%s fail to WLC_DOWN ioctl err =%d\n", __FUNCTION__, ret)); goto fail; } fail : if (ret < 0) { WLDEV_ERROR(("%s: return value %d\n", __FUNCTION__, ret)); } return ret; }
static uint16_t ptp_ptpip_init_event_ack (PTPParams* params) { PTPIPHeader hdr; unsigned char *data = NULL; uint16_t ret; ret = ptp_ptpip_evt_read (params, &hdr, &data); if (ret != PTP_RC_OK) return ret; free (data); if (hdr.type != dtoh32(PTPIP_INIT_EVENT_ACK)) { gp_log (GP_LOG_ERROR, "ptpip", "bad type returned %d\n", htod32(hdr.type)); return PTP_RC_GeneralError; } return PTP_RC_OK; }
/* * data parsing from ComboScan tlv list */ int wl_iw_parse_data_tlv(char** list_str, void *dst, int dst_size, const char token, int input_size, int *bytes_left) { char* str = *list_str; uint16 short_temp; uint32 int_temp; if ((list_str == NULL) || (*list_str == NULL) ||(bytes_left == NULL) || (*bytes_left < 0)) { DHD_ERROR(("%s error paramters\n", __FUNCTION__)); return -1; } /* Clean all dest bytes */ memset(dst, 0, dst_size); while (*bytes_left > 0) { if (str[0] != token) { DHD_TRACE(("%s NOT Type=%d get=%d left_parse=%d \n", __FUNCTION__, token, str[0], *bytes_left)); return -1; } *bytes_left -= 1; str += 1; if (input_size == 1) { memcpy(dst, str, input_size); } else if (input_size == 2) { memcpy(dst, (char *)htod16(memcpy(&short_temp, str, input_size)), input_size); } else if (input_size == 4) { memcpy(dst, (char *)htod32(memcpy(&int_temp, str, input_size)), input_size); } *bytes_left -= input_size; str += input_size; *list_str = str; return 1; } return 1; }
int wl_p2p_scan(void *wl, uint16 sync_id, int isActive, int numProbes, int activeDwellTime, int passiveDwellTime, int num_channels, uint16 *channels) { wl_p2p_scan_t *params = NULL; int params_size = 0; int malloc_size = 0; int nssid = 0; int err = 0; wl_escan_params_t *eparams; malloc_size = sizeof(wl_p2p_scan_t); malloc_size += OFFSETOF(wl_escan_params_t, params) + WL_SCAN_PARAMS_FIXED_SIZE + WL_NUMCHANNELS * sizeof(uint16); malloc_size += WL_SCAN_PARAMS_SSID_MAX * sizeof(wlc_ssid_t); params = (wl_p2p_scan_t *)malloc(malloc_size); if (params == NULL) { fprintf(stderr, "Error allocating %d bytes for scan params\n", malloc_size); return -1; } memset(params, 0, malloc_size); eparams = (wl_escan_params_t *)(params+1); params->type = 'E'; eparams->version = htod32(ESCAN_REQ_VERSION); eparams->action = htod16(WL_SCAN_ACTION_START); eparams->sync_id = sync_id; memcpy(&eparams->params.bssid, ðer_bcast, ETHER_ADDR_LEN); eparams->params.bss_type = DOT11_BSSTYPE_ANY; eparams->params.scan_type = isActive ? 0 : WL_SCANFLAGS_PASSIVE; eparams->params.nprobes = htod32(numProbes); eparams->params.active_time = htod32(activeDwellTime); eparams->params.passive_time = htod32(passiveDwellTime); eparams->params.home_time = htod32(-1); eparams->params.channel_num = 0; memcpy(eparams->params.channel_list, channels, num_channels * sizeof(uint16)); eparams->params.channel_num = htod32((nssid << WL_SCAN_PARAMS_NSSID_SHIFT) | (num_channels & WL_SCAN_PARAMS_COUNT_MASK)); params_size = sizeof(wl_p2p_scan_t) + sizeof(wl_escan_params_t) + WL_SCAN_PARAMS_FIXED_SIZE+ (num_channels * sizeof(uint16)) + (nssid * sizeof(wlc_ssid_t)); err = wlu_iovar_setbuf(wl, "p2p_scan", params, params_size, buf, WLC_IOCTL_MAXLEN); free(params); return err; }
int wlmChannelSet(int channel) { /* Check band lock first before set channel */ if ((channel <= 14) && (curBand != WLM_BAND_2G)) { curBand = WLM_BAND_2G; } else if ((channel > 14) && (curBand != WLM_BAND_5G)) { curBand = WLM_BAND_5G; } /* Set 'channel' */ channel = htod32(channel); if (wlu_set(irh, WLC_SET_CHANNEL, &channel, sizeof(channel))) { printf("wlmChannelSet: %s\n", wlmLastError()); return FALSE; } return TRUE; }
int wldev_get_conap_ctrl_channel(struct net_device *dev,uint8 *ctrl_channel) { struct wl_bss_info *bss = NULL; int err; *(u32 *) wlcfg_drv_priv->extra_buf = htod32(WL_EXTRA_BUF_MAX); if ((err = wldev_ioctl(ap_net_dev, WLC_GET_BSS_INFO, wlcfg_drv_priv->extra_buf, WL_EXTRA_BUF_MAX, false))) { printf("Failed to get hostapd bss info, use temp channel \n"); return -1; } else { bss = (struct wl_bss_info *) (wlcfg_drv_priv->extra_buf + 4); *ctrl_channel = bss->ctl_ch; printf(" %s Valid BSS Found. ctrl_channel:%d \n",__func__ ,*ctrl_channel); return 0; } }
static int wl_android_sta_diassoc(struct net_device *dev, const char* straddr) { scb_val_t scbval; DHD_INFO(("%s: deauth STA %s\n", __FUNCTION__, straddr)); /* Unspecified reason */ scbval.val = htod32(1); bcm_ether_atoe(straddr, &scbval.ea); DHD_INFO(("%s: deauth STA: %02X:%02X:%02X:%02X:%02X:%02X\n", __FUNCTION__, scbval.ea.octet[0], scbval.ea.octet[1], scbval.ea.octet[2], scbval.ea.octet[3], scbval.ea.octet[4], scbval.ea.octet[5])); wldev_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON, &scbval, sizeof(scb_val_t), true); return 1; }
int wlmEnableCarrierTone(int enable, WLM_BAND band, int channel) { int val = channel; (void)band; if (!enable) { val = 0; } else { wlmEnableAdapterUp(1); if (wlu_set(irh, WLC_OUT, NULL, 0) < 0) { printf("wlmEnableCarrierTone: %s\n", wlmLastError()); return FALSE; } } val = htod32(val); if (wlu_set(irh, WLC_FREQ_ACCURACY, &val, sizeof(int)) < 0) { printf("wlmEnableCarrierTone: %s\n", wlmLastError()); return FALSE; } return TRUE; }
static uint16_t ptp_ptpip_init_command_ack(PTPParams *params) { PTPIPHeader hdr; unsigned char *data = NULL; uint16_t ret; ret = ptp_ptpip_generic_read(params, params->cmdfd, &hdr, &data); if (ret != PTP_RC_OK) return ret; if (hdr.type != dtoh32(PTPIP_INIT_COMMAND_ACK)) { VitaMTP_Log(VitaMTP_ERROR, "ptpip/init_cmd_ack: bad type returned %d\n", htod32(hdr.type)); return PTP_RC_GeneralError; } params->eventpipeid = dtoh32a(&data[ptpip_cmdack_idx]); free(data); return PTP_RC_OK; }
uint16_t ptp_usb_sendreq (PTPParams* params, PTPContainer* req) { int res, towrite, do_retry = TRUE; PTPUSBBulkContainer usbreq; Camera *camera = ((PTPData *)params->data)->camera; GP_LOG_D ("Sending PTP_OC 0x%0x (%s) request...", req->Code, ptp_get_opcode_name(params, req->Code)); /* build appropriate USB container */ usbreq.length=htod32(PTP_USB_BULK_REQ_LEN- (sizeof(uint32_t)*(5-req->Nparam))); usbreq.type=htod16(PTP_USB_CONTAINER_COMMAND); usbreq.code=htod16(req->Code); usbreq.trans_id=htod32(req->Transaction_ID); usbreq.payload.params.param1=htod32(req->Param1); usbreq.payload.params.param2=htod32(req->Param2); usbreq.payload.params.param3=htod32(req->Param3); usbreq.payload.params.param4=htod32(req->Param4); usbreq.payload.params.param5=htod32(req->Param5); /* send it to responder */ towrite = PTP_USB_BULK_REQ_LEN-(sizeof(uint32_t)*(5-req->Nparam)); retry: res = gp_port_write (camera->port, (char*)&usbreq, towrite); if (res != towrite) { if (res < 0) { GP_LOG_E ("PTP_OC 0x%04x sending req failed: %s (%d)", req->Code, gp_port_result_as_string(res), res); if (res == GP_ERROR_IO_WRITE && do_retry) { GP_LOG_D ("Clearing halt on OUT EP and retrying once."); gp_port_usb_clear_halt (camera->port, GP_PORT_USB_ENDPOINT_OUT); do_retry = FALSE; goto retry; } } else GP_LOG_E ("PTP_OC 0x%04x sending req failed: wrote only %d of %d bytes", req->Code, res, towrite); return PTP_ERROR_IO; } return PTP_RC_OK; }
static int escan(void *wl, uint16 action, uint16 sync_id, int isActive, int numProbes, int activeDwellTime, int passiveDwellTime, int num_channels, uint16 *channels) { int params_size = (WL_SCAN_PARAMS_FIXED_SIZE + OFFSETOF(wl_escan_params_t, params)) + (WL_NUMCHANNELS * sizeof(uint16)); wl_escan_params_t *params; int nssid = 0; int err; params_size += WL_SCAN_PARAMS_SSID_MAX * sizeof(wlc_ssid_t); params = (wl_escan_params_t*)malloc(params_size); if (params == NULL) { return -1; } memset(params, 0, params_size); memcpy(¶ms->params.bssid, ðer_bcast, ETHER_ADDR_LEN); params->params.bss_type = DOT11_BSSTYPE_ANY; params->params.scan_type = isActive ? 0 : WL_SCANFLAGS_PASSIVE; params->params.nprobes = htod32(numProbes); params->params.active_time = htod32(activeDwellTime); params->params.passive_time = htod32(passiveDwellTime); params->params.home_time = htod32(-1); params->params.channel_num = 0; params_size = sizeof(*params); params->version = htod32(ESCAN_REQ_VERSION); params->action = htod16(action); params->sync_id = htod16(sync_id); memcpy(params->params.channel_list, channels, num_channels * sizeof(uint16)); params->params.channel_num = htod32((nssid << WL_SCAN_PARAMS_NSSID_SHIFT) | (num_channels & WL_SCAN_PARAMS_COUNT_MASK)); params_size = (WL_SCAN_PARAMS_FIXED_SIZE + OFFSETOF(wl_escan_params_t, params)) + (num_channels * sizeof(uint16)) + (nssid * sizeof(wlc_ssid_t)); err = wlu_iovar_setbuf(wl, "escan", params, params_size, buf, WLC_IOCTL_MAXLEN); free(params); return err; }
/* Generic interface for downloading required data onto the dongle */ static int wwd_download2dongle(wwd_interface_t interface, const char *iovar, uint16_t flag, uint16_t dload_type, unsigned char *dload_buf, uint32_t len) { wl_dload_data_t *dload_ptr = (wl_dload_data_t *)dload_buf; unsigned int dload_data_offset; wiced_buffer_t buffer; uint32_t* iov_data; dload_data_offset = offsetof(wl_dload_data_t, data); dload_ptr->flag = (DLOAD_HANDLER_VER << DLOAD_FLAG_VER_SHIFT) | flag; dload_ptr->dload_type = dload_type; dload_ptr->len = htod32(len - dload_data_offset); dload_ptr->crc = 0; wiced_assert("dload buffer too large", len < 0xffffffff - 8 ); len = len + 8 - (len%8); iov_data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t)len, iovar ); CHECK_IOCTL_BUFFER( iov_data ); memcpy( iov_data, dload_ptr, len); CHECK_RETURN( wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, interface ) ); return WWD_SUCCESS; }
static int lua_set_acl(lua_State *L, void *wl, lua_cmd_t *cmd, char *argv) { int ret; int val; if (!stricmp(argv, "deny")) { val = 1; } else if (!stricmp(argv, "allow")) { val = 2; } else { val = 0; } val = htod32(val); ret = wlu_set(wl, WLC_SET_MACMODE, &val, sizeof(int)); return ret; }
int wl_status(void *wl, int *isAssociated, int biBufferSize, wl_bss_info_t *biBuffer) { int ret; struct ether_addr bssid; wl_bss_info_t *bi; *isAssociated = FALSE; if ((ret = wlu_get(wl, WLC_GET_BSSID, &bssid, ETHER_ADDR_LEN)) == 0) { /* The adapter is associated. */ *(uint32*)buf = htod32(WLC_IOCTL_MAXLEN); if ((ret = wlu_get(wl, WLC_GET_BSS_INFO, buf, WLC_IOCTL_MAXLEN)) < 0) return ret; bi = (wl_bss_info_t*)(buf + 4); if (dtoh32(bi->version) == WL_BSS_INFO_VERSION || dtoh32(bi->version) == LEGACY2_WL_BSS_INFO_VERSION || dtoh32(bi->version) == LEGACY_WL_BSS_INFO_VERSION) { *isAssociated = TRUE; if (bi->length <= (uint32)biBufferSize) { memcpy(biBuffer, bi, bi->length); } else { fprintf(stderr, "buffer too small %d > %d\n", bi->length, biBufferSize); } } else fprintf(stderr, "Sorry, your driver has bss_info_version %d " "but this program supports only version %d.\n", bi->version, WL_BSS_INFO_VERSION); } return 0; }