software/drivers/sd8887/src/wlan/mapp/mlanutl/mlanroamagent.c
/**
 *  @brief          Issue getra metrics command
 *
 *  @param argc     number of arguments
 *  @param argv     A pointer to arguments array
 *
 *  @return         MLAN_STATUS_SUCCESS--success, otherwise--fail
 */
@brief          Issue getra metrics command
@param argc     number of arguments
@param argv     A pointer to arguments array


@brief Issue getra metrics command @param argc number of arguments @param argv A pointer to arguments array
static int
roamGetMetrics(int argc, char *argv[])
{
	int ret = MLAN_STATUS_SUCCESS;
	int i;
	t_u16 Metrics = 0;
	struct ifreq ifr;
	t_u8 *buffer = NULL, *pos = NULL;
	t_u32 cmd_len = 0, cmd_header_len;
	struct eth_priv_cmd *cmd = NULL;
	HostCmd_DS_GEN *hostcmd;
	HostCmd_DS_CMD_ROAMAGENT_ADV_METRIC_THRESHOLD *metricscmd;
	const char *metricslist[] = { "beacon", "data", "per", "fer" };
	if (argc != 0) {
		puts("\nIncorrect number of arguments.\n");
		ret = MLAN_STATUS_FAILURE;
		goto done;
	}
	cmd_header_len = strlen(CMD_NXP) + strlen(HOSTCMD);
	buffer = (t_u8 *)malloc(BUFFER_LENGTH);
	if (buffer == NULL) {
		fprintf(stderr, "Cannot alloc memory\n");
		ret = ENOMEM;
		goto done;
	}
	memset(buffer, 0, BUFFER_LENGTH);
	cmd = (struct eth_priv_cmd *)malloc(sizeof(struct eth_priv_cmd));
	if (!cmd) {
		printf("ERR:Cannot allocate buffer for command!\n");
		free(buffer);
		ret = ENOMEM;
		goto done;
	}
#ifdef USERSPACE_32BIT_OVER_KERNEL_64BIT
	memset(cmd, 0, sizeof(struct eth_priv_cmd));
	memcpy(&cmd->buf, &buffer, sizeof(buffer));
#else
	cmd->buf = buffer;
#endif
	cmd->used_len = 0;
	cmd->total_len = BUFFER_LENGTH;
	strncpy((char *)buffer, CMD_NXP, strlen(CMD_NXP));
	strncpy((char *)buffer + strlen(CMD_NXP), HOSTCMD, strlen(HOSTCMD));
	hostcmd = (HostCmd_DS_GEN *)(buffer + cmd_header_len + sizeof(t_u32));
	pos = (t_u8 *)hostcmd + S_DS_GEN;
	metricscmd = (HostCmd_DS_CMD_ROAMAGENT_ADV_METRIC_THRESHOLD *)pos;
	cmd_len = S_DS_GEN + sizeof(metricscmd->action);
	metricscmd->action = cpu_to_le16(HostCmd_ACT_GEN_GET);
	hostcmd->command =
		cpu_to_le16(HostCmd_CMD_ROAMAGENT_ADV_METRIC_THRESHOLD);
	hostcmd->size = cpu_to_le16(cmd_len);
	hostcmd->seq_num = 0;
	hostcmd->result = 0;
	memcpy(buffer + cmd_header_len, &cmd_len, sizeof(t_u32));
	memset(&ifr, 0, sizeof(ifr));
	strncpy(ifr.ifr_ifrn.ifrn_name, dev_name, strlen(dev_name));
	ifr.ifr_ifru.ifru_data = (void *)cmd;
	if (ioctl(sockfd, MLAN_ETH_PRIV, &ifr)) {
		perror("ioctl[roam set matrics]");
		printf("ERR:Command sending failed!\n");
		ret = -EFAULT;
		goto done;
	}
	Metrics = le16_to_cpu(metricscmd->Metrics);
	if (le16_to_cpu(hostcmd->result) == MLAN_STATUS_SUCCESS) {
		printf("\n Metrics Activated: ");
		for (i = 0; (unsigned int)i < NELEMENTS(metricslist); i++) {
			if (Metrics & BIT(i)) {
				printf(" %s ", metricslist[i]);
			}
		}
		printf("\n");
		if (Metrics & BIT(3)) {
			printf("FER Threshold : %u %% \n",
			       metricscmd->UcFerThresholdValue);
			printf("FER Packet Threshold: %d \n",
			       le32_to_cpu(metricscmd->UiFerPktThreshold));
			printf("FER period. Stable : %d ms, Degrading : %d ms, "
			       "Unacceptable : %d ms\n",
			       le32_to_cpu(metricscmd->StableFERPeriod_ms),
			       le32_to_cpu(metricscmd->DegradingFERPeriod_ms),
			       le32_to_cpu(metricscmd->
					   UnacceptableFERPeriod_ms));
		}
		if (Metrics & BIT(2)) {
			printf("PER Threshold : %u %% \n",
			       metricscmd->UcPerThresholdValue);
			printf("PER Packet Threshold: %d \n",
			       le32_to_cpu(metricscmd->UiPerPktThreshold));
			printf("PER period. Stable : %d ms, Degrading : %d ms, "
			       "Unacceptable : %d ms\n",
			       le32_to_cpu(metricscmd->StablePERPeriod_ms),
			       le32_to_cpu(metricscmd->DegradingPERPeriod_ms),
			       le32_to_cpu(metricscmd->
					   UnacceptablePERPeriod_ms));
		}
		if (Metrics & BIT(1)) {
			printf("Data Packet Threshold: %d \n",
			       le32_to_cpu(metricscmd->UiRxPktThreshold));
		}
		if ((Metrics & BIT(1)) || (Metrics & BIT(2)) ||
		    (Metrics & BIT(3))) {
			printf("Inactivity Period: %d ms \n",
			       le32_to_cpu(metricscmd->
					   InactivityPeriodThreshold_ms));
		}
	} else {
		printf("command response failure %d.\n",
		       le16_to_cpu(hostcmd->result));
	}
done:
	if (buffer)
		free(buffer);
	if (cmd)
		free(cmd);
	return ret;
}
static int roamGetMetrics ( int argc , char * argv [ ] ) { int ret = MLAN_STATUS_SUCCESS ; int i ; t_u16 Metrics = 0 ; struct ifreq ifr ; t_u8 * buffer = NULL , * pos = NULL ; t_u32 cmd_len = 0 , cmd_header_len ; struct eth_priv_cmd * cmd = NULL ; HostCmd_DS_GEN * hostcmd ; HostCmd_DS_CMD_ROAMAGENT_ADV_METRIC_THRESHOLD * metricscmd ; const char * metricslist [ ] = { " " , " " , " " , " " } ; if ( argc != 0 ) { puts ( " \n \n " ) ; ret = MLAN_STATUS_FAILURE ; goto done ; } cmd_header_len = strlen ( CMD_NXP ) + strlen ( HOSTCMD ) ; buffer = ( t_u8 * ) malloc ( BUFFER_LENGTH ) ; if ( buffer == NULL ) { fprintf ( stderr , " \n " ) ; ret = ENOMEM ; goto done ; } memset ( buffer , 0 , BUFFER_LENGTH ) ; cmd = ( struct eth_priv_cmd * ) malloc ( sizeof ( struct eth_priv_cmd ) ) ; if ( ! cmd ) { printf ( " \n " ) ; free ( buffer ) ; ret = ENOMEM ; goto done ; } #ifdef USERSPACE_32BIT_OVER_KERNEL_64BIT memset ( cmd , 0 , sizeof ( struct eth_priv_cmd ) ) ; memcpy ( & cmd -> buf , & buffer , sizeof ( buffer ) ) ; #else cmd -> buf = buffer ; #endif cmd -> used_len = 0 ; cmd -> total_len = BUFFER_LENGTH ; strncpy ( ( char * ) buffer , CMD_NXP , strlen ( CMD_NXP ) ) ; strncpy ( ( char * ) buffer + strlen ( CMD_NXP ) , HOSTCMD , strlen ( HOSTCMD ) ) ; hostcmd = ( HostCmd_DS_GEN * ) ( buffer + cmd_header_len + sizeof ( t_u32 ) ) ; pos = ( t_u8 * ) hostcmd + S_DS_GEN ; metricscmd = ( HostCmd_DS_CMD_ROAMAGENT_ADV_METRIC_THRESHOLD * ) pos ; cmd_len = S_DS_GEN + sizeof ( metricscmd -> action ) ; metricscmd -> action = cpu_to_le16 ( HostCmd_ACT_GEN_GET ) ; hostcmd -> command = cpu_to_le16 ( HostCmd_CMD_ROAMAGENT_ADV_METRIC_THRESHOLD ) ; hostcmd -> size = cpu_to_le16 ( cmd_len ) ; hostcmd -> seq_num = 0 ; hostcmd -> result = 0 ; memcpy ( buffer + cmd_header_len , & cmd_len , sizeof ( t_u32 ) ) ; memset ( & ifr , 0 , sizeof ( ifr ) ) ; strncpy ( ifr . ifr_ifrn . ifrn_name , dev_name , strlen ( dev_name ) ) ; ifr . ifr_ifru . ifru_data = ( void * ) cmd ; if ( ioctl ( sockfd , MLAN_ETH_PRIV , & ifr ) ) { perror ( " " ) ; printf ( " \n " ) ; ret = - EFAULT ; goto done ; } Metrics = le16_to_cpu ( metricscmd -> Metrics ) ; if ( le16_to_cpu ( hostcmd -> result ) == MLAN_STATUS_SUCCESS ) { printf ( " \n " ) ; for ( i = 0 ; ( unsigned int ) i < NELEMENTS ( metricslist ) ; i ++ ) { if ( Metrics & BIT ( i ) ) { printf ( " " , metricslist [ i ] ) ; } } printf ( " \n " ) ; if ( Metrics & BIT ( 3 ) ) { printf ( " \n " , metricscmd -> UcFerThresholdValue ) ; printf ( " \n " , le32_to_cpu ( metricscmd -> UiFerPktThreshold ) ) ; printf ( " " " \n " , le32_to_cpu ( metricscmd -> StableFERPeriod_ms ) , le32_to_cpu ( metricscmd -> DegradingFERPeriod_ms ) , le32_to_cpu ( metricscmd -> UnacceptableFERPeriod_ms ) ) ; } if ( Metrics & BIT ( 2 ) ) { printf ( " \n " , metricscmd -> UcPerThresholdValue ) ; printf ( " \n " , le32_to_cpu ( metricscmd -> UiPerPktThreshold ) ) ; printf ( " " " \n " , le32_to_cpu ( metricscmd -> StablePERPeriod_ms ) , le32_to_cpu ( metricscmd -> DegradingPERPeriod_ms ) , le32_to_cpu ( metricscmd -> UnacceptablePERPeriod_ms ) ) ; } if ( Metrics & BIT ( 1 ) ) { printf ( " \n " , le32_to_cpu ( metricscmd -> UiRxPktThreshold ) ) ; } if ( ( Metrics & BIT ( 1 ) ) || ( Metrics & BIT ( 2 ) ) || ( Metrics & BIT ( 3 ) ) ) { printf ( " \n " , le32_to_cpu ( metricscmd -> InactivityPeriodThreshold_ms ) ) ; } } else { printf ( " \n " , le16_to_cpu ( hostcmd -> result ) ) ; } done : if ( buffer ) free ( buffer ) ; if ( cmd ) free ( cmd ) ; return ret ; }
@brief          Issue getra metrics command
  @param argc     number of arguments
  @param argv     A pointer to arguments array
@brief Issue getra metrics command @param argc number of arguments @param argv A pointer to arguments array
/* Fill up buffer */ /* buffer = MRVL_CMD<cmd> */ /* buffer = MRVL_CMD<cmd><hostcmd_size><HostCmd_DS_GEN><CMD_DS> */ /* Point after host command header */ /* Put buffer length */ /* Initialize the ifr structure */ /* Perform ioctl */