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


@brief Issue getra neighbors command @param argc number of arguments @param argv A pointer to arguments array
static int
roamGetNborList(int argc, char *argv[])
{
	int ret = MLAN_STATUS_SUCCESS;
	int cmdresplen, i;
	struct ifreq ifr;
	char neighflag[6];
	ExactTime_t t;
	t_u16 tlv;
	t_u8 *buffer = NULL, *pos = NULL, *tlvptr = NULL;
	t_u32 cmd_len = 0, cmd_header_len;
	struct eth_priv_cmd *cmd = NULL;
	HostCmd_DS_GEN *hostcmd;
	HostCmd_DS_CMD_ROAMAGENT_NEIGHBORLIST *pNborList;
	MrvlIEtypes_NeighborEntry_t *pNeighbor;
	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;
	pNborList = (HostCmd_DS_CMD_ROAMAGENT_NEIGHBORLIST *)pos;
	cmd_len = S_DS_GEN + sizeof(pNborList->action);
	pNborList->action = cpu_to_le16(HostCmd_ACT_GEN_GET);
	hostcmd->command = cpu_to_le16(HostCmd_CMD_ROAMAGENT_NEIGHBORLIST);
	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[roamneighborlist]");
		printf("ERR:Command sending failed!\n");
		ret = -EFAULT;
		goto done;
	}
	cmdresplen = le16_to_cpu(hostcmd->size);
	cmdresplen -= cmd_len + sizeof(pNborList->Reserved);
	tlvptr = pNborList->TlvBuffer;
	printf("----------------------------------------------------"
	       "--------------\n");
	printf("       BSSID       | RSSI |  Age  | Qualified |"
	       " Blacklist Duration\n");
	printf("----------------------------------------------------"
	       "--------------\n");
	i = 0;
	while (cmdresplen > 2) {
		i++;
		tlv = le16_to_cpu(*((t_u16 *)(tlvptr)));
		switch (tlv) {
		case TLV_TYPE_NEIGHBOR_ENTRY:
			pNeighbor = (MrvlIEtypes_NeighborEntry_t *)(tlvptr);
			pNeighbor->SignalStrength =
				le16_to_cpu(pNeighbor->SignalStrength);
			pNeighbor->Age = le16_to_cpu(pNeighbor->Age);
			pNeighbor->QualifiedNeighborBitmap =
				le32_to_cpu(pNeighbor->QualifiedNeighborBitmap);
			pNeighbor->BlackListDuration =
				le32_to_cpu(pNeighbor->BlackListDuration);
			ms2exactTime(pNeighbor->BlackListDuration, &t);
			neighflag[0] = '\0';
			if ((pNeighbor->QualifiedNeighborBitmap
			     & (BIT_NEIGHFLAG_RSSI
				| BIT_NEIGHFLAG_AGE
				| BIT_NEIGHFLAG_BLACKLIST
				| BIT_NEIGHFLAG_ADMISSION_CAP
				| BIT_NEIGHFLAG_UPLINK_RSSI))
			    == (BIT_NEIGHFLAG_RSSI
				| BIT_NEIGHFLAG_AGE
				| BIT_NEIGHFLAG_BLACKLIST
				| BIT_NEIGHFLAG_ADMISSION_CAP
				| BIT_NEIGHFLAG_UPLINK_RSSI)) {
				strcat(neighflag, "Yes");
			} else {
				strcat(neighflag, "No: ");
				if (!
				    (pNeighbor->
				     QualifiedNeighborBitmap &
				     BIT_NEIGHFLAG_RSSI)) {
					strcat(neighflag, "R");
				}
				if (!
				    (pNeighbor->
				     QualifiedNeighborBitmap &
				     BIT_NEIGHFLAG_AGE)) {
					strcat(neighflag, "S");
				}
				if (!(pNeighbor->QualifiedNeighborBitmap
				      & BIT_NEIGHFLAG_BLACKLIST)) {
					strcat(neighflag, "B");
				}
				if (!(pNeighbor->QualifiedNeighborBitmap
				      & BIT_NEIGHFLAG_ADMISSION_CAP)) {
					strcat(neighflag, "A");
				}
				if (!(pNeighbor->QualifiedNeighborBitmap
				      & BIT_NEIGHFLAG_UPLINK_RSSI)) {
					strcat(neighflag, "U");
				}
			}
			printf(" %02x:%02x:%02x:%02x:%02x:%02x | %3d  | %5d | %9s | ", pNeighbor->Bssid[0], pNeighbor->Bssid[1], pNeighbor->Bssid[2], pNeighbor->Bssid[3], pNeighbor->Bssid[4], pNeighbor->Bssid[5], pNeighbor->SignalStrength, pNeighbor->Age, neighflag);
			if (pNeighbor->BlackListDuration) {
				printExactTime2stdout(&t);
			} else {
				printf("Not Blacklisted");
			}
			printf("\n");
			tlvptr += (le16_to_cpu(pNeighbor->Header.len) +
				   sizeof(MrvlIEtypesHeader_t));
			cmdresplen -= (le16_to_cpu(pNeighbor->Header.len) +
				       sizeof(MrvlIEtypesHeader_t));
			break;
		default:
			printf("\nIncorrect response.\n\n");
			break;
		}
	}
	if (i == 0) {
		printf("< Empty >\n");
	}
	printf("\n");
done:
	if (buffer)
		free(buffer);
	if (cmd)
		free(cmd);
	return ret;
}
static int roamGetNborList ( int argc , char * argv [ ] ) { int ret = MLAN_STATUS_SUCCESS ; int cmdresplen , i ; struct ifreq ifr ; char neighflag [ 6 ] ; ExactTime_t t ; t_u16 tlv ; t_u8 * buffer = NULL , * pos = NULL , * tlvptr = NULL ; t_u32 cmd_len = 0 , cmd_header_len ; struct eth_priv_cmd * cmd = NULL ; HostCmd_DS_GEN * hostcmd ; HostCmd_DS_CMD_ROAMAGENT_NEIGHBORLIST * pNborList ; MrvlIEtypes_NeighborEntry_t * pNeighbor ; 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 ; pNborList = ( HostCmd_DS_CMD_ROAMAGENT_NEIGHBORLIST * ) pos ; cmd_len = S_DS_GEN + sizeof ( pNborList -> action ) ; pNborList -> action = cpu_to_le16 ( HostCmd_ACT_GEN_GET ) ; hostcmd -> command = cpu_to_le16 ( HostCmd_CMD_ROAMAGENT_NEIGHBORLIST ) ; 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 ; } cmdresplen = le16_to_cpu ( hostcmd -> size ) ; cmdresplen -= cmd_len + sizeof ( pNborList -> Reserved ) ; tlvptr = pNborList -> TlvBuffer ; printf ( " " " \n " ) ; printf ( " " " \n " ) ; printf ( " " " \n " ) ; i = 0 ; while ( cmdresplen > 2 ) { i ++ ; tlv = le16_to_cpu ( * ( ( t_u16 * ) ( tlvptr ) ) ) ; switch ( tlv ) { case TLV_TYPE_NEIGHBOR_ENTRY : pNeighbor = ( MrvlIEtypes_NeighborEntry_t * ) ( tlvptr ) ; pNeighbor -> SignalStrength = le16_to_cpu ( pNeighbor -> SignalStrength ) ; pNeighbor -> Age = le16_to_cpu ( pNeighbor -> Age ) ; pNeighbor -> QualifiedNeighborBitmap = le32_to_cpu ( pNeighbor -> QualifiedNeighborBitmap ) ; pNeighbor -> BlackListDuration = le32_to_cpu ( pNeighbor -> BlackListDuration ) ; ms2exactTime ( pNeighbor -> BlackListDuration , & t ) ; neighflag [ 0 ] = ' \0 ' ; if ( ( pNeighbor -> QualifiedNeighborBitmap & ( BIT_NEIGHFLAG_RSSI | BIT_NEIGHFLAG_AGE | BIT_NEIGHFLAG_BLACKLIST | BIT_NEIGHFLAG_ADMISSION_CAP | BIT_NEIGHFLAG_UPLINK_RSSI ) ) == ( BIT_NEIGHFLAG_RSSI | BIT_NEIGHFLAG_AGE | BIT_NEIGHFLAG_BLACKLIST | BIT_NEIGHFLAG_ADMISSION_CAP | BIT_NEIGHFLAG_UPLINK_RSSI ) ) { strcat ( neighflag , " " ) ; } else { strcat ( neighflag , " " ) ; if ( ! ( pNeighbor -> QualifiedNeighborBitmap & BIT_NEIGHFLAG_RSSI ) ) { strcat ( neighflag , " " ) ; } if ( ! ( pNeighbor -> QualifiedNeighborBitmap & BIT_NEIGHFLAG_AGE ) ) { strcat ( neighflag , " " ) ; } if ( ! ( pNeighbor -> QualifiedNeighborBitmap & BIT_NEIGHFLAG_BLACKLIST ) ) { strcat ( neighflag , " " ) ; } if ( ! ( pNeighbor -> QualifiedNeighborBitmap & BIT_NEIGHFLAG_ADMISSION_CAP ) ) { strcat ( neighflag , " " ) ; } if ( ! ( pNeighbor -> QualifiedNeighborBitmap & BIT_NEIGHFLAG_UPLINK_RSSI ) ) { strcat ( neighflag , " " ) ; } } printf ( " " , pNeighbor -> Bssid [ 0 ] , pNeighbor -> Bssid [ 1 ] , pNeighbor -> Bssid [ 2 ] , pNeighbor -> Bssid [ 3 ] , pNeighbor -> Bssid [ 4 ] , pNeighbor -> Bssid [ 5 ] , pNeighbor -> SignalStrength , pNeighbor -> Age , neighflag ) ; if ( pNeighbor -> BlackListDuration ) { printExactTime2stdout ( & t ) ; } else { printf ( " " ) ; } printf ( " \n " ) ; tlvptr += ( le16_to_cpu ( pNeighbor -> Header . len ) + sizeof ( MrvlIEtypesHeader_t ) ) ; cmdresplen -= ( le16_to_cpu ( pNeighbor -> Header . len ) + sizeof ( MrvlIEtypesHeader_t ) ) ; break ; default : printf ( " \n \n \n " ) ; break ; } } if ( i == 0 ) { printf ( " \n " ) ; } printf ( " \n " ) ; done : if ( buffer ) free ( buffer ) ; if ( cmd ) free ( cmd ) ; return ret ; }
@brief          Issue getra neighbors command
  @param argc     number of arguments
  @param argv     A pointer to arguments array
@brief Issue getra neighbors command @param argc number of arguments @param argv A pointer to arguments array
/*
	 * NEIGHBOR_LIST
	 */ /* 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 */ /*
		 * ENDIANNESS for Response
		 */