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


@brief Issue setra scanperiod command @param argc number of arguments @param argv A pointer to arguments array
static int
roamSetScanPeriod(int argc, char *argv[])
{
	int ret = MLAN_STATUS_SUCCESS;
	int scanmode = 0, period = 0, state = 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_NEIGHBOR_SCANPERIOD *scanPeriodInfo;
	if (argv[0] == NULL) {
		puts("\nInsufficient arguments.. \n");
		ret = MLAN_STATUS_FAILURE;
		goto done;
	}
	if (argc != 3) {
		puts("\nIncorrect number of arguments.\n");
		ret = MLAN_STATUS_FAILURE;
		goto done;
	}
	if (argv[0] && strncmp(argv[0], "stable", strlen("stable")) == 0) {
		state = STATE_STABLE;
	} else if (argv[0] && strncmp(argv[0], "degrad", strlen("degrad")) == 0) {
		state = STATE_DEGRADING;
	} else if (argv[0]
		   && strncmp(argv[0], "unaccep", strlen("unaccep")) == 0) {
		state = STATE_UNACCEPTABLE;
	} else {
		puts("\nUnknown state. Use stable/degrading/unacceptable\n");
		ret = MLAN_STATUS_FAILURE;
		goto done;
	}
	if (argv[1] && strncmp(argv[1], "disc", strlen("disc")) == 0) {
		scanmode = DISCOVERY_MODE;
	} else if (argv[1] && strncmp(argv[1], "track", strlen("track")) == 0) {
		scanmode = TRACKING_MODE;
	} else {
		puts("\nUnknown scamode. Use discovery/ tracking\n");
		ret = MLAN_STATUS_FAILURE;
		goto done;
	}
	period = atoi(argv[2]);
	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;
	scanPeriodInfo = (HostCmd_DS_CMD_ROAMAGENT_NEIGHBOR_SCANPERIOD *)pos;
	cmd_len =
		S_DS_GEN + sizeof(HostCmd_DS_CMD_ROAMAGENT_NEIGHBOR_SCANPERIOD);
	hostcmd->command =
		cpu_to_le16(HostCmd_CMD_ROAMAGENT_NEIGHBOR_SCAN_PERIOD);
	hostcmd->size = cpu_to_le16(cmd_len);
	hostcmd->seq_num = 0;
	hostcmd->result = 0;
	scanPeriodInfo->action = HostCmd_ACT_GEN_SET;
	scanPeriodInfo->scanPeriod.Header.type = TLV_TYPE_NEIGHBOR_SCANPERIOD;
	scanPeriodInfo->scanPeriod.Header.len =
		sizeof(MrvlIEtypes_NeighborScanPeriod_t) -
		sizeof(MrvlIEtypesHeader_t);
	scanPeriodInfo->scanPeriod.SearchMode = scanmode;
	scanPeriodInfo->scanPeriod.State = state;
	scanPeriodInfo->scanPeriod.ScanPeriod = period;
	scanPeriodInfo->action = cpu_to_le16(scanPeriodInfo->action);
	scanPeriodInfo->scanPeriod.Header.type = cpu_to_le16
		(scanPeriodInfo->scanPeriod.Header.type);
	scanPeriodInfo->scanPeriod.Header.len = cpu_to_le16
		(scanPeriodInfo->scanPeriod.Header.len);
	scanPeriodInfo->scanPeriod.SearchMode = cpu_to_le16
		(scanPeriodInfo->scanPeriod.SearchMode);
	scanPeriodInfo->scanPeriod.State = cpu_to_le16
		(scanPeriodInfo->scanPeriod.State);
	scanPeriodInfo->scanPeriod.ScanPeriod = cpu_to_le32
		(scanPeriodInfo->scanPeriod.ScanPeriod);
	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[neighborlist maintain]");
		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 roamSetScanPeriod ( int argc , char * argv [ ] ) { int ret = MLAN_STATUS_SUCCESS ; int scanmode = 0 , period = 0 , state = 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_NEIGHBOR_SCANPERIOD * scanPeriodInfo ; if ( argv [ 0 ] == NULL ) { puts ( " \n \n " ) ; ret = MLAN_STATUS_FAILURE ; goto done ; } if ( argc != 3 ) { puts ( " \n \n " ) ; ret = MLAN_STATUS_FAILURE ; goto done ; } if ( argv [ 0 ] && strncmp ( argv [ 0 ] , " " , strlen ( " " ) ) == 0 ) { state = STATE_STABLE ; } else if ( argv [ 0 ] && strncmp ( argv [ 0 ] , " " , strlen ( " " ) ) == 0 ) { state = STATE_DEGRADING ; } else if ( argv [ 0 ] && strncmp ( argv [ 0 ] , " " , strlen ( " " ) ) == 0 ) { state = STATE_UNACCEPTABLE ; } else { puts ( " \n \n " ) ; ret = MLAN_STATUS_FAILURE ; goto done ; } if ( argv [ 1 ] && strncmp ( argv [ 1 ] , " " , strlen ( " " ) ) == 0 ) { scanmode = DISCOVERY_MODE ; } else if ( argv [ 1 ] && strncmp ( argv [ 1 ] , " " , strlen ( " " ) ) == 0 ) { scanmode = TRACKING_MODE ; } else { puts ( " \n \n " ) ; ret = MLAN_STATUS_FAILURE ; goto done ; } period = atoi ( argv [ 2 ] ) ; 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 ; scanPeriodInfo = ( HostCmd_DS_CMD_ROAMAGENT_NEIGHBOR_SCANPERIOD * ) pos ; cmd_len = S_DS_GEN + sizeof ( HostCmd_DS_CMD_ROAMAGENT_NEIGHBOR_SCANPERIOD ) ; hostcmd -> command = cpu_to_le16 ( HostCmd_CMD_ROAMAGENT_NEIGHBOR_SCAN_PERIOD ) ; hostcmd -> size = cpu_to_le16 ( cmd_len ) ; hostcmd -> seq_num = 0 ; hostcmd -> result = 0 ; scanPeriodInfo -> action = HostCmd_ACT_GEN_SET ; scanPeriodInfo -> scanPeriod . Header . type = TLV_TYPE_NEIGHBOR_SCANPERIOD ; scanPeriodInfo -> scanPeriod . Header . len = sizeof ( MrvlIEtypes_NeighborScanPeriod_t ) - sizeof ( MrvlIEtypesHeader_t ) ; scanPeriodInfo -> scanPeriod . SearchMode = scanmode ; scanPeriodInfo -> scanPeriod . State = state ; scanPeriodInfo -> scanPeriod . ScanPeriod = period ; scanPeriodInfo -> action = cpu_to_le16 ( scanPeriodInfo -> action ) ; scanPeriodInfo -> scanPeriod . Header . type = cpu_to_le16 ( scanPeriodInfo -> scanPeriod . Header . type ) ; scanPeriodInfo -> scanPeriod . Header . len = cpu_to_le16 ( scanPeriodInfo -> scanPeriod . Header . len ) ; scanPeriodInfo -> scanPeriod . SearchMode = cpu_to_le16 ( scanPeriodInfo -> scanPeriod . SearchMode ) ; scanPeriodInfo -> scanPeriod . State = cpu_to_le16 ( scanPeriodInfo -> scanPeriod . State ) ; scanPeriodInfo -> scanPeriod . ScanPeriod = cpu_to_le32 ( scanPeriodInfo -> scanPeriod . ScanPeriod ) ; 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 scanperiod command
  @param argc     number of arguments
  @param argv     A pointer to arguments array
@brief Issue setra scanperiod command @param argc number of arguments @param argv A pointer to arguments array
/* scanperiod */ /* degrad[ing] */ /* unaccep[table] */ /* track[ing] */ /* TODO validation check on period */ /* Fill up buffer */ /* buffer = MRVL_CMD<cmd> */ /* buffer = MRVL_CMD<cmd><hostcmd_size><HostCmd_DS_GEN><CMD_DS> */ /* Point after host command header */ /*
	 * ENDIANNESS
	 */ /* Put buffer length */ /* Initialize the ifr structure */ /* Perform ioctl */