software/drivers/sd8887/src/wlan/mapp/mlanutl/mlanroamagent.c
static int
roamSetBackOff(int argc, char *argv[])
{
	int ret = MLAN_STATUS_SUCCESS;
	struct ifreq ifr;
	t_u8 *buffer = NULL, *pos = NULL;
	t_u32 cmd_len = 0, cmd_header_len;
	struct eth_priv_cmd *cmd = NULL;
	int spflag[2] = { 0, 0 };	/*scan,priod */
	t_u16 minscan;
	t_u32 bperiod;
	HostCmd_DS_GEN *hostcmd;
	HostCmd_DS_CMD_ROAMAGENT_BACKOFF *roambackoffcmd;
	int i;

	if (argv[0] == NULL) {
		puts("\nInsufficient arguments.. \n");
		ret = MLAN_STATUS_FAILURE;
		goto done;
	}
	/* BackOff */
	if ((argc != 2) && (argc != 4)) {
		puts("\nIncorrect number of arguments.\n");
		ret = MLAN_STATUS_FAILURE;
		goto done;
	}

	for (i = 0; i < 4; i++) {
		if (argv[i + 0] &&
		    strncmp(argv[i + 0], "scans", strlen("scans")) == 0) {
			minscan = atoi(argv[i + 1]);
			i++;
			spflag[0] = 1;
			/* TODO validation check on minscan */
		}
		if (argv[i + 0] &&
		    strncmp(argv[i + 0], "period", strlen("period")) == 0) {
			bperiod = atoi(argv[i + 1]);
			i++;
			spflag[1] = 1;
			/* TODO validation check on bperiod */
		}
	}

	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");
		ret = ENOMEM;
		goto done;
	}

	/* Fill up buffer */
#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;

	/* buffer = MRVL_CMD<cmd> */
	strncpy((char *)buffer, CMD_NXP, strlen(CMD_NXP));
	strncpy((char *)buffer + strlen(CMD_NXP), HOSTCMD, strlen(HOSTCMD));

	/* buffer = MRVL_CMD<cmd><hostcmd_size><HostCmd_DS_GEN><CMD_DS> */
	hostcmd = (HostCmd_DS_GEN *)(buffer + cmd_header_len + sizeof(t_u32));

	/* Point after host command header */
	pos = (t_u8 *)hostcmd + S_DS_GEN;

	roambackoffcmd = (HostCmd_DS_CMD_ROAMAGENT_BACKOFF *)pos;
	cmd_len = S_DS_GEN + sizeof(HostCmd_DS_CMD_ROAMAGENT_BACKOFF);
	hostcmd->command = cpu_to_le16(HostCmd_CMD_ROAMAGENT_BACKOFF);
	hostcmd->size = cpu_to_le16(cmd_len);
	hostcmd->seq_num = 0;
	hostcmd->result = 0;

	switch (spflag[0] + spflag[1]) {
	case 0:
		/* error */
		puts("\nIncorrect arguments for setra backoff command.\n");
		ret = MLAN_STATUS_FAILURE;
		goto done;

	case 1:
		/* get missing parameter */
		if (getBackOff(roambackoffcmd) != MLAN_STATUS_SUCCESS) {
			ret = MLAN_STATUS_FAILURE;
			goto done;
		}
		if (spflag[0] == 0) {
			minscan = roambackoffcmd->Scans;
		} else {
			bperiod = roambackoffcmd->Period;
		}
		break;

	case 2:
	default:
		break;
	}

	roambackoffcmd->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
	roambackoffcmd->Scans = cpu_to_le16(minscan);
	roambackoffcmd->Period = cpu_to_le16(bperiod);

	/* Put buffer length */
	memcpy(buffer + cmd_header_len, &cmd_len, sizeof(t_u32));

	/* Initialize the ifr structure */
	memset(&ifr, 0, sizeof(ifr));
	strncpy(ifr.ifr_ifrn.ifrn_name, dev_name, strlen(dev_name));
	ifr.ifr_ifru.ifru_data = (void *)cmd;
	/* Perform ioctl */
	if (ioctl(sockfd, MLAN_ETH_PRIV, &ifr)) {
		perror("ioctl[roambackoff]");
		printf("ERR:Command sending failed!\n");
		ret = -EFAULT;
		goto done;
	}

	if (le16_to_cpu(hostcmd->result)) {
		printf("\nHostCmd Error: ReturnCode=%#04x, Result=%#04x\n\n",
		       le16_to_cpu(hostcmd->command),
		       le16_to_cpu(hostcmd->result));
	} else {
		printf("\nHostCmd Success: ReturnCode=%#04x, Result=%#04x\n\n",
		       le16_to_cpu(hostcmd->command),
		       le16_to_cpu(hostcmd->result));
	}

done:
	if (buffer)
		free(buffer);
	if (cmd)
		free(cmd);
	return ret;
}
/**
 *  @brief          Issue setra backoff command
 *
 *  @param argc     number of arguments
 *  @param argv     A pointer to arguments array
 *
 *  @return         MLAN_STATUS_SUCCESS--success, otherwise--fail
 */
@brief          Issue setra backoff command
@param argc     number of arguments
@param argv     A pointer to arguments array


@brief Issue setra backoff command @param argc number of arguments @param argv A pointer to arguments array
static int
roamSetBackOff(int argc, char *argv[])
{
	int ret = MLAN_STATUS_SUCCESS;
	struct ifreq ifr;
	t_u8 *buffer = NULL, *pos = NULL;
	t_u32 cmd_len = 0, cmd_header_len;
	struct eth_priv_cmd *cmd = NULL;
	int spflag[2] = { 0, 0 };	
	t_u16 minscan;
	t_u32 bperiod;
	HostCmd_DS_GEN *hostcmd;
	HostCmd_DS_CMD_ROAMAGENT_BACKOFF *roambackoffcmd;
	int i;
	if (argv[0] == NULL) {
		puts("\nInsufficient arguments.. \n");
		ret = MLAN_STATUS_FAILURE;
		goto done;
	}
	if ((argc != 2) && (argc != 4)) {
		puts("\nIncorrect number of arguments.\n");
		ret = MLAN_STATUS_FAILURE;
		goto done;
	}
	for (i = 0; i < 4; i++) {
		if (argv[i + 0] &&
		    strncmp(argv[i + 0], "scans", strlen("scans")) == 0) {
			minscan = atoi(argv[i + 1]);
			i++;
			spflag[0] = 1;
		}
		if (argv[i + 0] &&
		    strncmp(argv[i + 0], "period", strlen("period")) == 0) {
			bperiod = atoi(argv[i + 1]);
			i++;
			spflag[1] = 1;
		}
	}
	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");
		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;
	roambackoffcmd = (HostCmd_DS_CMD_ROAMAGENT_BACKOFF *)pos;
	cmd_len = S_DS_GEN + sizeof(HostCmd_DS_CMD_ROAMAGENT_BACKOFF);
	hostcmd->command = cpu_to_le16(HostCmd_CMD_ROAMAGENT_BACKOFF);
	hostcmd->size = cpu_to_le16(cmd_len);
	hostcmd->seq_num = 0;
	hostcmd->result = 0;
	switch (spflag[0] + spflag[1]) {
	case 0:
		puts("\nIncorrect arguments for setra backoff command.\n");
		ret = MLAN_STATUS_FAILURE;
		goto done;
	case 1:
		if (getBackOff(roambackoffcmd) != MLAN_STATUS_SUCCESS) {
			ret = MLAN_STATUS_FAILURE;
			goto done;
		}
		if (spflag[0] == 0) {
			minscan = roambackoffcmd->Scans;
		} else {
			bperiod = roambackoffcmd->Period;
		}
		break;
	case 2:
	default:
		break;
	}
	roambackoffcmd->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
	roambackoffcmd->Scans = cpu_to_le16(minscan);
	roambackoffcmd->Period = cpu_to_le16(bperiod);
	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[roambackoff]");
		printf("ERR:Command sending failed!\n");
		ret = -EFAULT;
		goto done;
	}
	if (le16_to_cpu(hostcmd->result)) {
		printf("\nHostCmd Error: ReturnCode=%#04x, Result=%#04x\n\n",
		       le16_to_cpu(hostcmd->command),
		       le16_to_cpu(hostcmd->result));
	} else {
		printf("\nHostCmd Success: ReturnCode=%#04x, Result=%#04x\n\n",
		       le16_to_cpu(hostcmd->command),
		       le16_to_cpu(hostcmd->result));
	}
done:
	if (buffer)
		free(buffer);
	if (cmd)
		free(cmd);
	return ret;
}
static int roamSetBackOff ( int argc , char * argv [ ] ) { int ret = MLAN_STATUS_SUCCESS ; struct ifreq ifr ; t_u8 * buffer = NULL , * pos = NULL ; t_u32 cmd_len = 0 , cmd_header_len ; struct eth_priv_cmd * cmd = NULL ; int spflag [ 2 ] = { 0 , 0 } ; t_u16 minscan ; t_u32 bperiod ; HostCmd_DS_GEN * hostcmd ; HostCmd_DS_CMD_ROAMAGENT_BACKOFF * roambackoffcmd ; int i ; if ( argv [ 0 ] == NULL ) { puts ( " \n \n " ) ; ret = MLAN_STATUS_FAILURE ; goto done ; } if ( ( argc != 2 ) && ( argc != 4 ) ) { puts ( " \n \n " ) ; ret = MLAN_STATUS_FAILURE ; goto done ; } for ( i = 0 ; i < 4 ; i ++ ) { if ( argv [ i + 0 ] && strncmp ( argv [ i + 0 ] , " " , strlen ( " " ) ) == 0 ) { minscan = atoi ( argv [ i + 1 ] ) ; i ++ ; spflag [ 0 ] = 1 ; } if ( argv [ i + 0 ] && strncmp ( argv [ i + 0 ] , " " , strlen ( " " ) ) == 0 ) { bperiod = atoi ( argv [ i + 1 ] ) ; i ++ ; spflag [ 1 ] = 1 ; } } 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 " ) ; 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 ; roambackoffcmd = ( HostCmd_DS_CMD_ROAMAGENT_BACKOFF * ) pos ; cmd_len = S_DS_GEN + sizeof ( HostCmd_DS_CMD_ROAMAGENT_BACKOFF ) ; hostcmd -> command = cpu_to_le16 ( HostCmd_CMD_ROAMAGENT_BACKOFF ) ; hostcmd -> size = cpu_to_le16 ( cmd_len ) ; hostcmd -> seq_num = 0 ; hostcmd -> result = 0 ; switch ( spflag [ 0 ] + spflag [ 1 ] ) { case 0 : puts ( " \n \n " ) ; ret = MLAN_STATUS_FAILURE ; goto done ; case 1 : if ( getBackOff ( roambackoffcmd ) != MLAN_STATUS_SUCCESS ) { ret = MLAN_STATUS_FAILURE ; goto done ; } if ( spflag [ 0 ] == 0 ) { minscan = roambackoffcmd -> Scans ; } else { bperiod = roambackoffcmd -> Period ; } break ; case 2 : default : break ; } roambackoffcmd -> action = cpu_to_le16 ( HostCmd_ACT_GEN_SET ) ; roambackoffcmd -> Scans = cpu_to_le16 ( minscan ) ; roambackoffcmd -> Period = cpu_to_le16 ( bperiod ) ; 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 ; } if ( le16_to_cpu ( hostcmd -> result ) ) { printf ( " \n \n \n " , le16_to_cpu ( hostcmd -> command ) , le16_to_cpu ( hostcmd -> result ) ) ; } else { printf ( " \n \n \n " , le16_to_cpu ( hostcmd -> command ) , le16_to_cpu ( hostcmd -> result ) ) ; } done : if ( buffer ) free ( buffer ) ; if ( cmd ) free ( cmd ) ; return ret ; }
@brief          Issue setra backoff command
  @param argc     number of arguments
  @param argv     A pointer to arguments array
@brief Issue setra backoff command @param argc number of arguments @param argv A pointer to arguments array
/*scan,priod */ /* BackOff */ /* TODO validation check on minscan */ /* TODO validation check on bperiod */ /* Fill up buffer */ /* buffer = MRVL_CMD<cmd> */ /* buffer = MRVL_CMD<cmd><hostcmd_size><HostCmd_DS_GEN><CMD_DS> */ /* Point after host command header */ /* error */ /* get missing parameter */ /* Put buffer length */ /* Initialize the ifr structure */ /* Perform ioctl */