Logo Search packages:      
Sourcecode: uaputl version File versions  Download package

void apcmd_sys_cfg_rates_ext ( int  argc,
char *  argv[] 
)

Creates a sys_cfg request for setting data_rates, MCBC and TX data rates.

Usage: "sys_cfg_rates_ext [RATES]"

Parameters:
argcNumber of arguments
argvPointer to the arguments
Returns:
N/A

Definition at line 1488 of file uapcmd.c.

References A2HEXDECIMAL, ACTION_GET, ACTION_SET, APCMD_RESP_CHECK, APCMD_SYS_CONFIGURE, BASIC_RATE_SET_BIT, BUF_HEADER_SIZE, cmd_options, CMD_SUCCESS, endian_convert_tlv_header_out, is_input_valid(), is_mcbc_rate_valid(), is_tx_rate_valid(), MAX_RATES, MRVL_MCBC_DATA_RATE_TLV_ID, MRVL_RATES_TLV_ID, MRVL_TX_DATA_RATE_TLV_ID, parse_input(), print_sys_cfg_rates_ext_usage(), print_tlv(), uap_cpu_to_le16, UAP_FAILURE, uap_ioctl(), and UAP_SUCCESS.

{
    int i, j = 0;
    int opt;
    int rflag = 0, mflag = 0, uflag = 0;
    char *argv_rate[14];
    int argc_rate = 0;
    char *argv_mrate[1];
    char *argv_urate[1];
    int mrate_found = UAP_FAILURE;
    int urate_found = UAP_FAILURE;
    u8 *tlv_buf = NULL;
    TLVBUF_TX_DATA_RATE *tlv_urate = NULL;
    TLVBUF_MCBC_DATA_RATE *tlv_mrate = NULL;
    TLVBUF_RATES *tlv_rate = NULL;
    u8 *buffer = NULL;
    APCMDBUF_SYS_CONFIGURE *cmd_buf = NULL;
    int ret = UAP_FAILURE;
    u16 cmd_len;
    int output[3][2];

    while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
        switch (opt) {
        default:
            print_sys_cfg_rates_ext_usage();
            return;
        }
    }
    argc -= optind;
    argv += optind;

    if (argc) {
        /* 
         * SET
         */
        parse_input(argc, argv, output);

        /* 
         * Rate
         */
        if ((output[0][0] != -1) && (output[0][1] > output[0][0])) {
            rflag = 1;
            i = 0;
            for (j = (output[0][0] + 1); j < output[0][1]; j++) {
                argv_rate[i] =
                    (char *) malloc(sizeof(char) * (strlen(argv[j]) + 1));
                strcpy(argv_rate[i], argv[j]);
                argc_rate = ++i;
            }
        }

        /* 
         * mrate
         */

        if ((output[1][0] != -1) && (output[1][1] > output[1][0])) {
            if ((output[1][1] - output[1][0]) != 2) {
                printf("\nERR: Invalid mrate input");
                print_sys_cfg_rates_ext_usage();
                goto done;
            }
            mflag = 1;
            argv_mrate[0] =
                (char *) malloc(sizeof(char) * (strlen(argv[j]) + 1));
            strcpy(argv_mrate[0], argv[output[1][0] + 1]);
        }

        /* 
         * urate
         */
        if ((output[2][0] != -1) && (output[2][1] > output[2][0])) {
            if ((output[2][1] - output[2][0]) != 2) {
                printf("\nERR: Invalid urate input");
                print_sys_cfg_rates_ext_usage();
                goto done;
            }
            uflag = 1;
            argv_urate[0] =
                (char *) malloc(sizeof(char) * (strlen(argv[j]) + 1));
            strcpy(argv_urate[0], argv[output[2][0] + 1]);
        }

        if (!rflag && !mflag & !uflag) {
            printf("ERR: Invalid input\n");
            print_sys_cfg_rates_ext_usage();
            goto done;
        }

        if (rflag && is_input_valid(RATE, argc_rate, argv_rate) != UAP_SUCCESS) {
            printf("ERR: Invalid RATE\n");
            print_sys_cfg_rates_ext_usage();
            goto done;
        }

        if (mflag && is_input_valid(MCBCDATARATE, 1, argv_mrate) != UAP_SUCCESS) {
            printf("ERR: Invalid MCBC RATE\n");
            print_sys_cfg_rates_ext_usage();
            goto done;
        }

        if (uflag && is_input_valid(TXDATARATE, 1, argv_urate) != UAP_SUCCESS) {
            printf("ERR: Invalid TX RATE\n");
            print_sys_cfg_rates_ext_usage();
            goto done;
        }

        if (!rflag && (mflag || uflag)) {
            /* 
             * Check mrate and urate wrt old Rates
             */
            if (mflag && A2HEXDECIMAL(argv_mrate[0]) &&
                is_mcbc_rate_valid(A2HEXDECIMAL(argv_mrate[0])) !=
                UAP_SUCCESS) {
                printf("ERR: invalid MCBC data rate.");
                print_sys_cfg_rates_ext_usage();
                goto done;
            }
            if (uflag && A2HEXDECIMAL(argv_urate[0]) &&
                is_tx_rate_valid(A2HEXDECIMAL(argv_urate[0])) != UAP_SUCCESS) {
                printf("ERR: invalid tx data rate.");
                print_sys_cfg_rates_ext_usage();
                goto done;
            }
        } else if (rflag && (mflag || uflag)) {
            /* 
             * Check mrate and urate wrt new Rates
             */
            for (i = 0; i < argc_rate; i++) {
                /* 
                 * MCBC rate must be from Basic rates
                 */
                if (mflag && !mrate_found &&
                    A2HEXDECIMAL(argv_rate[i]) & BASIC_RATE_SET_BIT) {
                    if (A2HEXDECIMAL(argv_mrate[0]) ==
                        (A2HEXDECIMAL(argv_rate[i]) & ~BASIC_RATE_SET_BIT)) {
                        mrate_found = UAP_SUCCESS;
                    }
                }
                if (uflag && !urate_found && (A2HEXDECIMAL(argv_urate[0]) ==
                                              ((A2HEXDECIMAL(argv_rate[i]) &
                                                ~BASIC_RATE_SET_BIT)))) {
                    urate_found = UAP_SUCCESS;
                }
            }

            if (mflag && A2HEXDECIMAL(argv_mrate[0]) &&
                !(mrate_found == UAP_SUCCESS)) {
                printf("ERR: mrate not valid\n");
                goto done;
            }

            if (uflag && A2HEXDECIMAL(argv_urate[0]) &&
                !(urate_found == UAP_SUCCESS)) {
                printf("ERR: urate not valid\n");
                goto done;
            }
        }
        /* post-parsing */
        cmd_len = sizeof(APCMDBUF_SYS_CONFIGURE);
        if (rflag) {
            cmd_len += sizeof(TLVBUF_RATES) + argc_rate;
            cmd_len += sizeof(TLVBUF_MCBC_DATA_RATE);
            cmd_len += sizeof(TLVBUF_TX_DATA_RATE);
        } else {
            if (mflag)
                cmd_len += sizeof(TLVBUF_MCBC_DATA_RATE);
            if (uflag)
                cmd_len += sizeof(TLVBUF_TX_DATA_RATE);
        }
    } else {
        /* GET */
        cmd_len = sizeof(APCMDBUF_SYS_CONFIGURE)
            + sizeof(TLVBUF_RATES) + MAX_RATES + sizeof(TLVBUF_MCBC_DATA_RATE)
            + sizeof(TLVBUF_TX_DATA_RATE);
    }

    buffer = (u8 *) malloc(cmd_len);
    if (!buffer) {
        printf("ERR:Cannot allocate buffer for command!\n");
        goto done;
    }
    bzero((char *) buffer, cmd_len);

    /* Fill the command buffer */
    cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
    cmd_buf->CmdCode = APCMD_SYS_CONFIGURE;
    cmd_buf->Size = cmd_len;
    cmd_buf->SeqNum = 0;
    cmd_buf->Result = 0;
    cmd_buf->Action = argc ? ACTION_SET : ACTION_GET;
    tlv_buf = buffer + sizeof(APCMDBUF_SYS_CONFIGURE);
    /* Locate headers */
    if (rflag || (!argc)) {
        tlv_rate = (TLVBUF_RATES *) (buffer + sizeof(APCMDBUF_SYS_CONFIGURE));
        tlv_rate->Tag = MRVL_RATES_TLV_ID;
        tlv_rate->Length = argc ? argc_rate : MAX_RATES;
        for (i = 0; i < argc_rate; i++) {
            tlv_rate->OperationalRates[i] = (u8) A2HEXDECIMAL(argv_rate[i]);
        }
        tlv_buf += tlv_rate->Length + sizeof(TLVBUF_RATES);
        endian_convert_tlv_header_out(tlv_rate);
    }
    if (rflag || mflag || (!argc)) {
        tlv_mrate = (TLVBUF_MCBC_DATA_RATE *) tlv_buf;
        tlv_mrate->Tag = MRVL_MCBC_DATA_RATE_TLV_ID;
        tlv_mrate->Length = 2;
        tlv_mrate->MCBCdatarate = 0;
        if (mflag) {
            tlv_mrate->MCBCdatarate = (u16) A2HEXDECIMAL(argv_mrate[0])
                & ~BASIC_RATE_SET_BIT;
            tlv_mrate->MCBCdatarate = uap_cpu_to_le16(tlv_mrate->MCBCdatarate);
        }
        tlv_buf += sizeof(TLVBUF_MCBC_DATA_RATE);
        endian_convert_tlv_header_out(tlv_mrate);
    }
    if (rflag || uflag || (!argc)) {
        tlv_urate = (TLVBUF_TX_DATA_RATE *) tlv_buf;
        tlv_urate->Tag = MRVL_TX_DATA_RATE_TLV_ID;
        tlv_urate->Length = 2;
        tlv_urate->TxDataRate = 0;
        if (uflag) {
            tlv_urate->TxDataRate = (u16) A2HEXDECIMAL(argv_urate[0])
                & ~BASIC_RATE_SET_BIT;
            tlv_urate->TxDataRate = uap_cpu_to_le16(tlv_urate->TxDataRate);
        }
        endian_convert_tlv_header_out(tlv_urate);
    }

    /* Send the command */
    ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);

    tlv_buf = buffer + sizeof(APCMDBUF_SYS_CONFIGURE);

    if (ret == UAP_SUCCESS) {
        /* Verify response */
        if (cmd_buf->CmdCode != (APCMD_SYS_CONFIGURE | APCMD_RESP_CHECK)) {
            printf("ERR:Corrupted response! CmdCode=%x\n", cmd_buf->CmdCode);
            goto done;
        }
        /* Print response */
        if (cmd_buf->Result == CMD_SUCCESS) {
            if (argc) {
                printf("Rates setting successful\n");
            } else {
                print_tlv((u8 *) tlv_buf,
                          cmd_buf->Size - sizeof(APCMDBUF_SYS_CONFIGURE) +
                          BUF_HEADER_SIZE);
            }
        } else {
            printf("ERR:Could not %s operational rates!\n",
                   argc ? "set" : "get");
            if (argc)
                printf
                    ("operational rates only allow to set before bss start.\n");
        }
    } else {
        printf("ERR:Command sending failed!\n");
    }
  done:
    if (rflag) {
        for (i = 0; i < argc_rate; i++) {
            free(argv_rate[i]);
        }
    }
    if (mflag)
        free(argv_mrate[0]);
    if (uflag)
        free(argv_urate[0]);
    if (buffer)
        free(buffer);
    return;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index