software/drivers/sd8887/src/wlan/mapp/uaputl/uaputl.c
/**
 *  @brief Process cmd52 read/write handler
 *
 *
 *  @param argc     Number of arguments
 *  @param argv     Pointer to the arguments
 *  @return         N/A
 */
@brief Process cmd52 read/write handler
@param argc     Number of arguments
@param argv     Pointer to the arguments
@return         N/A
@brief Process cmd52 read / write handler @param argc Number of arguments @param argv Pointer to the arguments @return N / A
int
apcmd_cmd52_readwrite(int argc, char *argv[])
{
	int opt;
	sdcmd52_para param;
	struct ifreq ifr;
	t_s32 sockfd;
	while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
		switch (opt) {
		default:
			print_cmd52rw_usage();
			return UAP_SUCCESS;
		}
	}
	argc -= optind;
	argv += optind;
	memset(&param, 0, sizeof(sdcmd52_para));
	if (argc < 2 || argc > 3) {
		printf("ERR:wrong arguments.\n");
		print_cmd52rw_usage();
		return UAP_FAILURE;
	}
	if ((IS_HEX_OR_DIGIT(argv[0]) == UAP_FAILURE) ||
	    (IS_HEX_OR_DIGIT(argv[1]) == UAP_FAILURE)) {
		printf("ERR: Only Number values are allowed\n");
		print_cmd52rw_usage();
		return UAP_FAILURE;
	}
	param.cmd52_params[0] = (t_u8)A2HEXDECIMAL(argv[0]);
	if (param.cmd52_params[0] > 7) {
		printf("ERR: Invalid function number!\n");
		return UAP_FAILURE;
	}
	param.cmd52_params[1] = (t_u8)A2HEXDECIMAL(argv[1]);
	param.action = 0;
	if (argc == 3) {
		if (IS_HEX_OR_DIGIT(argv[2]) == UAP_FAILURE) {
			printf("ERR: Only Number values are allowed\n");
			print_cmd52rw_usage();
			return UAP_FAILURE;
		}
		param.cmd52_params[2] = (t_u8)A2HEXDECIMAL(argv[2]);
		param.action = 1;
	}
	param.subcmd = UAP_SDCMD52_RW;
	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		printf("ERR:Cannot open socket\n");
		return UAP_FAILURE;
	}
	memset(&ifr, 0, sizeof(ifr));
	strncpy(ifr.ifr_ifrn.ifrn_name, dev_name, IFNAMSIZ - 1);
	ifr.ifr_ifru.ifru_data = (void *)&param;
	errno = 0;
	if (ioctl(sockfd, UAP_IOCTL_CMD, &ifr)) {
		perror("");
		printf("ERR:cmd52rw failed\n");
		close(sockfd);
		return UAP_FAILURE;
	}
	if (argc == 2)
		printf("Cmd52 read done. ");
	else
		printf("Cmd52 write done. ");
	printf("func=%d, reg=%d, data=0x%02X\n",
	       param.cmd52_params[0], param.cmd52_params[1],
	       param.cmd52_params[2]);
	close(sockfd);
	return UAP_SUCCESS;
}
int apcmd_cmd52_readwrite ( int argc , char * argv [ ] ) { int opt ; sdcmd52_para param ; struct ifreq ifr ; t_s32 sockfd ; while ( ( opt = getopt_long ( argc , argv , " " , cmd_options , NULL ) ) != -1 ) { switch ( opt ) { default : print_cmd52rw_usage ( ) ; return UAP_SUCCESS ; } } argc -= optind ; argv += optind ; memset ( & param , 0 , sizeof ( sdcmd52_para ) ) ; if ( argc < 2 || argc > 3 ) { printf ( " \n " ) ; print_cmd52rw_usage ( ) ; return UAP_FAILURE ; } if ( ( IS_HEX_OR_DIGIT ( argv [ 0 ] ) == UAP_FAILURE ) || ( IS_HEX_OR_DIGIT ( argv [ 1 ] ) == UAP_FAILURE ) ) { printf ( " \n " ) ; print_cmd52rw_usage ( ) ; return UAP_FAILURE ; } param . cmd52_params [ 0 ] = ( t_u8 ) A2HEXDECIMAL ( argv [ 0 ] ) ; if ( param . cmd52_params [ 0 ] > 7 ) { printf ( " \n " ) ; return UAP_FAILURE ; } param . cmd52_params [ 1 ] = ( t_u8 ) A2HEXDECIMAL ( argv [ 1 ] ) ; param . action = 0 ; if ( argc == 3 ) { if ( IS_HEX_OR_DIGIT ( argv [ 2 ] ) == UAP_FAILURE ) { printf ( " \n " ) ; print_cmd52rw_usage ( ) ; return UAP_FAILURE ; } param . cmd52_params [ 2 ] = ( t_u8 ) A2HEXDECIMAL ( argv [ 2 ] ) ; param . action = 1 ; } param . subcmd = UAP_SDCMD52_RW ; if ( ( sockfd = socket ( AF_INET , SOCK_STREAM , 0 ) ) < 0 ) { printf ( " \n " ) ; return UAP_FAILURE ; } memset ( & ifr , 0 , sizeof ( ifr ) ) ; strncpy ( ifr . ifr_ifrn . ifrn_name , dev_name , IFNAMSIZ - 1 ) ; ifr . ifr_ifru . ifru_data = ( void * ) & param ; errno = 0 ; if ( ioctl ( sockfd , UAP_IOCTL_CMD , & ifr ) ) { perror ( " " ) ; printf ( " \n " ) ; close ( sockfd ) ; return UAP_FAILURE ; } if ( argc == 2 ) printf ( " " ) ; else printf ( " " ) ; printf ( " \n " , param . cmd52_params [ 0 ] , param . cmd52_params [ 1 ] , param . cmd52_params [ 2 ] ) ; close ( sockfd ) ; return UAP_SUCCESS ; }
@brief Process cmd52 read/write handler
  @param argc     Number of arguments
  @param argv     Pointer to the arguments
  @return         N/A
@brief Process cmd52 read / write handler @param argc Number of arguments @param argv Pointer to the arguments @return N / A
/* Check arguments */ /* Open socket */ /* Initialize the ifr structure */ /* Perform ioctl */ /* Close socket */