int wlan_regrdwr_getset(int argc, char *argv[]) { uint8_t action; uint32_t value; wifi_reg_t reg_type; int ret; if (argc != 4 && argc != 5) return -WM_FAIL; reg_type = atoi(argv[2]); if (argc == 4) { action = ACTION_GET; value = 0; } else { action = ACTION_SET; value = a2hex_or_atoi(argv[4]); } ret = wifi_reg_access(reg_type, action, a2hex_or_atoi(argv[3]), &value); if (ret == WM_SUCCESS) { if (action == ACTION_GET) { switch (reg_type) { case REG_MAC: wmprintf("MAC Reg 0x%x\r\n", value); break; case REG_BBP: wmprintf("BBP Reg 0x%x", value); break; case REG_RF: wmprintf("RF Reg 0x%x", value); break; default: wlcm_e("Read/write register failed"); } } else wmprintf("Set the register successfully\r\n"); } else { wlcm_e("Read/write register failed"); return -WM_FAIL; } return WM_SUCCESS; }
/** * @brief get hostcmd data * * @param ln A pointer to line number * @param buf A pointer to hostcmd data * @param size A pointer to the return size of hostcmd buffer * @return UAP_SUCCESS */ static int mlan_get_hostcmd_data(FILE * fp, int *ln, t_u8 * buf, t_u16 * size) { t_s32 errors = 0, i; t_s8 line[256], *pos, *pos1, *pos2, *pos3; t_u16 len; while ((pos = mlan_config_get_line(fp, line, sizeof(line), ln))) { (*ln)++; if (strcmp(pos, "}") == 0) { break; } pos1 = strchr(pos, ':'); if (pos1 == NULL) { printf("Line %d: Invalid hostcmd line '%s'\n", *ln, pos); errors++; continue; } *pos1++ = '\0'; pos2 = strchr(pos1, '='); if (pos2 == NULL) { printf("Line %d: Invalid hostcmd line '%s'\n", *ln, pos); errors++; continue; } *pos2++ = '\0'; len = a2hex_or_atoi(pos1); if (len < 1 || len > MRVDRV_SIZE_OF_CMD_BUFFER) { printf("Line %d: Invalid hostcmd line '%s'\n", *ln, pos); errors++; continue; } *size += len; if (*pos2 == '"') { pos2++; if ((pos3 = strchr(pos2, '"')) == NULL) { printf("Line %d: invalid quotation '%s'\n", *ln, pos); errors++; continue; } *pos3 = '\0'; memset(buf, 0, len); memmove(buf, pos2, MIN(strlen(pos2), len)); buf += len; } else if (*pos2 == '\'') { pos2++; if ((pos3 = strchr(pos2, '\'')) == NULL) { printf("Line %d: invalid quotation '%s'\n", *ln, pos); errors++; continue; } *pos3 = ','; for (i = 0; i < len; i++) { if ((pos3 = strchr(pos2, ',')) != NULL) { *pos3 = '\0'; *buf++ = (t_u8) a2hex_or_atoi(pos2); pos2 = pos3 + 1; } else *buf++ = 0; } } else if (*pos2 == '{') { t_u16 tlvlen = 0, tmp_tlvlen; mlan_get_hostcmd_data(fp, ln, buf + len, &tlvlen); tmp_tlvlen = tlvlen; while (len--) { *buf++ = (t_u8) (tmp_tlvlen & 0xff); tmp_tlvlen >>= 8; } *size += tlvlen; buf += tlvlen; } else {
pos2 = pos3 + 1; } else *buf++ = 0; } } else if (*pos2 == '{') { t_u16 tlvlen = 0, tmp_tlvlen; mlan_get_hostcmd_data(fp, ln, buf + len, &tlvlen); tmp_tlvlen = tlvlen; while (len--) { *buf++ = (t_u8) (tmp_tlvlen & 0xff); tmp_tlvlen >>= 8; } *size += tlvlen; buf += tlvlen; } else { t_u32 value = a2hex_or_atoi(pos2); while (len--) { *buf++ = (t_u8) (value & 0xff); value >>= 8; } } } return UAP_SUCCESS; } /******************************************************** Global Functions ********************************************************/ /** * @brief Prepare host-command buffer