software/drivers/sd8887/src/wlan/mapp/uaputl/uaputl.c
/**
 *  @brief Get uAP stats
 *
 *  @param argc     Number of arguments
 *  @param argv     Pointer to the arguments
 *
 *  @return         UAP_SUCCESS/UAP_FAILURE
 */
@brief Get uAP stats
@param argc     Number of arguments
@param argv     Pointer to the arguments


@brief Get uAP stats @param argc Number of arguments @param argv Pointer to the arguments
int
apcmd_uap_stats(int argc, char *argv[])
{
	t_u8 no_of_oids = sizeof(snmp_oids) / sizeof(snmp_oids[0]);
	t_u16 i, j;
	int size;
	apcmdbuf_snmp_mib *cmd_buf = NULL;
	t_u8 *buf = NULL;
	tlvbuf_header *tlv = NULL;
	t_u16 cmd_len = 0;
	t_u16 buf_len = MRVDRV_SIZE_OF_CMD_BUFFER;
	int opt;
	t_u16 oid_size, byte2 = 0;
	t_u32 byte4 = 0;
	int ret = UAP_SUCCESS;
	while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
		switch (opt) {
		default:
			print_apcmd_uap_stats();
			return UAP_SUCCESS;
		}
	}
	argc -= optind;
	argv += optind;
	if (argc) {
		printf("Error: Invalid Input\n");
		print_apcmd_uap_stats();
		return UAP_FAILURE;
	}
	cmd_len += sizeof(apcmdbuf_snmp_mib);
	for (i = 0; i < no_of_oids; i++) {
		cmd_len += snmp_oids[i].len + sizeof(tlvbuf_header);
	}
	buf = (t_u8 *)malloc(buf_len);
	if (!buf) {
		printf("ERR:Cannot allocate buffer from command!\n");
		return UAP_FAILURE;
	}
	memset(buf, 0, buf_len);
	cmd_buf = (apcmdbuf_snmp_mib *)buf;
	cmd_buf->size = cmd_len - BUF_HEADER_SIZE;
	cmd_buf->result = 0;
	cmd_buf->seq_num = 0;
	cmd_buf->cmd_code = HostCmd_SNMP_MIB;
	cmd_buf->action = uap_cpu_to_le16(ACTION_GET);
	tlv = (tlvbuf_header *)((t_u8 *)cmd_buf + sizeof(apcmdbuf_snmp_mib));
	for (i = 0; i < no_of_oids; i++) {
		tlv->type = uap_cpu_to_le16(snmp_oids[i].type);
		tlv->len = uap_cpu_to_le16(snmp_oids[i].len);
		tlv = (tlvbuf_header *)&(tlv->data[snmp_oids[i].len]);
	}
	ret = uap_ioctl((t_u8 *)cmd_buf, &cmd_len, buf_len);
	if (ret == UAP_SUCCESS) {
		if (cmd_buf->result == CMD_SUCCESS) {
			tlv = (tlvbuf_header *)((t_u8 *)cmd_buf +
						sizeof(apcmdbuf_snmp_mib));
			size = cmd_buf->size - (sizeof(apcmdbuf_snmp_mib) -
						BUF_HEADER_SIZE);
			while ((unsigned int)size >= sizeof(tlvbuf_header)) {
				tlv->type = uap_le16_to_cpu(tlv->type);
				for (i = 0; i < no_of_oids; i++) {
					if (snmp_oids[i].type == tlv->type) {
						printf("%s: ",
						       snmp_oids[i].name);
						break;
					}
				}
				oid_size = uap_le16_to_cpu(tlv->len);
				switch (oid_size) {
				case 1:
					printf("%d",
					       (unsigned int)tlv->data[0]);
					break;
				case 2:
					memcpy(&byte2, &tlv->data[0],
					       sizeof(oid_size));
					printf("%d",
					       (unsigned int)
					       uap_le16_to_cpu(byte2));
					break;
				case 4:
					memcpy(&byte4, &tlv->data[0],
					       sizeof(oid_size));
					printf("%d",
					       (unsigned int)
					       uap_le32_to_cpu(byte4));
					break;
				default:
					for (j = 0; j < oid_size; j++) {
						printf("%d ",
						       (t_u8)tlv->data[j]);
					}
					break;
				}
				tlv = (tlvbuf_header *)&(tlv->data[oid_size]);
				size -= (sizeof(tlvbuf_header) + oid_size);
				size = (size > 0) ? size : 0;
				printf("\n");
			}
		} else {
			printf("ERR:Command Response incorrect!\n");
			ret = UAP_FAILURE;
		}
	} else {
		printf("ERR:Command sending failed!\n");
	}
	free(buf);
	return ret;
}
int apcmd_uap_stats ( int argc , char * argv [ ] ) { t_u8 no_of_oids = sizeof ( snmp_oids ) / sizeof ( snmp_oids [ 0 ] ) ; t_u16 i , j ; int size ; apcmdbuf_snmp_mib * cmd_buf = NULL ; t_u8 * buf = NULL ; tlvbuf_header * tlv = NULL ; t_u16 cmd_len = 0 ; t_u16 buf_len = MRVDRV_SIZE_OF_CMD_BUFFER ; int opt ; t_u16 oid_size , byte2 = 0 ; t_u32 byte4 = 0 ; int ret = UAP_SUCCESS ; while ( ( opt = getopt_long ( argc , argv , " " , cmd_options , NULL ) ) != -1 ) { switch ( opt ) { default : print_apcmd_uap_stats ( ) ; return UAP_SUCCESS ; } } argc -= optind ; argv += optind ; if ( argc ) { printf ( " \n " ) ; print_apcmd_uap_stats ( ) ; return UAP_FAILURE ; } cmd_len += sizeof ( apcmdbuf_snmp_mib ) ; for ( i = 0 ; i < no_of_oids ; i ++ ) { cmd_len += snmp_oids [ i ] . len + sizeof ( tlvbuf_header ) ; } buf = ( t_u8 * ) malloc ( buf_len ) ; if ( ! buf ) { printf ( " \n " ) ; return UAP_FAILURE ; } memset ( buf , 0 , buf_len ) ; cmd_buf = ( apcmdbuf_snmp_mib * ) buf ; cmd_buf -> size = cmd_len - BUF_HEADER_SIZE ; cmd_buf -> result = 0 ; cmd_buf -> seq_num = 0 ; cmd_buf -> cmd_code = HostCmd_SNMP_MIB ; cmd_buf -> action = uap_cpu_to_le16 ( ACTION_GET ) ; tlv = ( tlvbuf_header * ) ( ( t_u8 * ) cmd_buf + sizeof ( apcmdbuf_snmp_mib ) ) ; for ( i = 0 ; i < no_of_oids ; i ++ ) { tlv -> type = uap_cpu_to_le16 ( snmp_oids [ i ] . type ) ; tlv -> len = uap_cpu_to_le16 ( snmp_oids [ i ] . len ) ; tlv = ( tlvbuf_header * ) & ( tlv -> data [ snmp_oids [ i ] . len ] ) ; } ret = uap_ioctl ( ( t_u8 * ) cmd_buf , & cmd_len , buf_len ) ; if ( ret == UAP_SUCCESS ) { if ( cmd_buf -> result == CMD_SUCCESS ) { tlv = ( tlvbuf_header * ) ( ( t_u8 * ) cmd_buf + sizeof ( apcmdbuf_snmp_mib ) ) ; size = cmd_buf -> size - ( sizeof ( apcmdbuf_snmp_mib ) - BUF_HEADER_SIZE ) ; while ( ( unsigned int ) size >= sizeof ( tlvbuf_header ) ) { tlv -> type = uap_le16_to_cpu ( tlv -> type ) ; for ( i = 0 ; i < no_of_oids ; i ++ ) { if ( snmp_oids [ i ] . type == tlv -> type ) { printf ( " " , snmp_oids [ i ] . name ) ; break ; } } oid_size = uap_le16_to_cpu ( tlv -> len ) ; switch ( oid_size ) { case 1 : printf ( " " , ( unsigned int ) tlv -> data [ 0 ] ) ; break ; case 2 : memcpy ( & byte2 , & tlv -> data [ 0 ] , sizeof ( oid_size ) ) ; printf ( " " , ( unsigned int ) uap_le16_to_cpu ( byte2 ) ) ; break ; case 4 : memcpy ( & byte4 , & tlv -> data [ 0 ] , sizeof ( oid_size ) ) ; printf ( " " , ( unsigned int ) uap_le32_to_cpu ( byte4 ) ) ; break ; default : for ( j = 0 ; j < oid_size ; j ++ ) { printf ( " " , ( t_u8 ) tlv -> data [ j ] ) ; } break ; } tlv = ( tlvbuf_header * ) & ( tlv -> data [ oid_size ] ) ; size -= ( sizeof ( tlvbuf_header ) + oid_size ) ; size = ( size > 0 ) ? size : 0 ; printf ( " \n " ) ; } } else { printf ( " \n " ) ; ret = UAP_FAILURE ; } } else { printf ( " \n " ) ; } free ( buf ) ; return ret ; }
@brief Get uAP stats
  @param argc     Number of arguments
  @param argv     Pointer to the arguments
@brief Get uAP stats @param argc Number of arguments @param argv Pointer to the arguments
/**  Command Header */ /**
         * Size of Oid + Oid_value + Oid_size
         */ /* Locate Headers */ /* Add oid, oid_size and oid_value for each OID */ /** Copy Index as Oid */ /** Copy its size */ /** Next TLV */ /** Next TLV */