software/drivers/sd8887/src/wlan/mapp/uaputl/uaputl.c
/**
 *  @brief  Checks if command requires driver handling, and if so,
 *          repackage and send as regular command, instead of hostcmd.
 *
 *  @param cmd           Pointer to the command buffer
 *  @param size          Pointer to the command size. This value is
 *                       overwritten by the function with the size of the
 *                       received response.
 *  @param buf_size      Size of the allocated command buffer
 *  @param reroute_ret   Pointer to return value of rerouted command
 *  @return              UAP_SUCCESS (handled here, further processing not needed)
 *                    or UAP_FAILURE (not handled here, proceed as usual)
 */
@brief  Checks if command requires driver handling, and if so,
repackage and send as regular command, instead of hostcmd.

@param cmd           Pointer to the command buffer
@param size          Pointer to the command size. This value is
overwritten by the function with the size of the
received response.
@param buf_size      Size of the allocated command buffer
@param reroute_ret   Pointer to return value of rerouted command
@return              UAP_SUCCESS (handled here, further processing not needed)
or UAP_FAILURE (not handled here, proceed as usual)
@brief Checks if command requires driver handling and if so repackage and send as regular command instead of hostcmd . @param cmd Pointer to the command buffer @param size Pointer to the command size . This value is overwritten by the function with the size of the received response . @param buf_size Size of the allocated command buffer @param reroute_ret Pointer to return value of rerouted command @return UAP_SUCCESS ( handled here further processing not needed ) or UAP_FAILURE ( not handled here proceed as usual )
static int
uap_ioctl_reroute(t_u8 *cmd, t_u16 *size, t_u16 buf_size, int *reroute_ret)
{
	t_u8 reroute = 0;
	t_u16 cmd_code = 0;
	t_u16 cmd_action = 0;
	apcmdbuf_cfg_80211d *hcmd_domain = NULL;
	apcmdbuf_snmp_mib *hcmd_snmp = NULL;
	tlvbuf_header *tlv = NULL;
	struct ifreq ifr;
	t_s32 sockfd;
	t_u8 *buf = NULL;
	t_u16 buf_len = 0;
	snmp_mib_param *snmp_param = NULL;
	domain_info_param *domain_param = NULL;
	cmd_code = ((apcmdbuf *)(cmd))->cmd_code;
	switch (cmd_code) {
	case HostCmd_SNMP_MIB:
		hcmd_snmp = (apcmdbuf_snmp_mib *)cmd;
		tlv = (tlvbuf_header *)(cmd + sizeof(apcmdbuf_snmp_mib));
		cmd_action = uap_le16_to_cpu(hcmd_snmp->action);
		if (cmd_action == ACTION_SET) {
			reroute = 1;
			buf_len =
				sizeof(snmp_mib_param) +
				uap_le16_to_cpu(tlv->len);
		}
		break;
	case HostCmd_CMD_802_11D_DOMAIN_INFO:
		hcmd_domain = (apcmdbuf_cfg_80211d *)cmd;
		cmd_action = uap_le16_to_cpu(hcmd_domain->action);
		if (cmd_action == ACTION_SET) {
			reroute = 1;
			buf_len = sizeof(domain_info_param) + (*size
							       -
							       sizeof
							       (apcmdbuf_cfg_80211d)
							       +
							       sizeof
							       (domain_param_t));
		}
		break;
	}
	if (!reroute || uap_ioctl_no_reroute)
		return UAP_FAILURE;
#if DEBUG
	uap_printf(MSG_DEBUG, "DBG: rerouting CMD 0x%04x\n", cmd_code);
#endif
	buf = (t_u8 *)malloc(buf_len);
	if (!buf) {
		printf("ERR:Cannot allocate buffer for command!\n");
		goto done_no_socket;
	}
	memset(buf, 0, buf_len);
	switch (cmd_code) {
	case HostCmd_SNMP_MIB:
		snmp_param = (snmp_mib_param *)buf;
		snmp_param->subcmd = UAP_SNMP_MIB;
		snmp_param->action = cmd_action;
		snmp_param->oid = uap_le16_to_cpu(tlv->type);
		snmp_param->oid_val_len = uap_le16_to_cpu(tlv->len);
		memcpy(snmp_param->oid_value, tlv->data,
		       MIN(sizeof(t_u32), snmp_param->oid_val_len));
		break;
	case HostCmd_CMD_802_11D_DOMAIN_INFO:
		domain_param = (domain_info_param *)buf;
		domain_param->subcmd = UAP_DOMAIN_INFO;
		domain_param->action = cmd_action;
		memcpy(domain_param->tlv, &hcmd_domain->domain,
		       buf_len - sizeof(domain_info_param));
		tlv = (tlvbuf_header *)domain_param->tlv;
		tlv->type = uap_le16_to_cpu(tlv->type);
		tlv->len = uap_le16_to_cpu(tlv->len);
		break;
	}
#if DEBUG
	hexdump("Reroute Request buffer", buf, buf_len, ' ');
#endif
	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		printf("ERR:Cannot open socket\n");
		goto done_no_socket;
	}
	memset(&ifr, 0, sizeof(ifr));
	strncpy(ifr.ifr_ifrn.ifrn_name, dev_name, IFNAMSIZ - 1);
	ifr.ifr_ifru.ifru_data = (void *)buf;
	errno = 0;
	if (ioctl(sockfd, UAP_IOCTL_CMD, &ifr)) {
		*reroute_ret = UAP_FAILURE;
		perror("");
#if DEBUG
		uap_printf(MSG_DEBUG, "ERR: reroute of CMD 0x%04x failed\n",
			   cmd_code);
#endif
		goto done;
	}
	*reroute_ret = UAP_SUCCESS;
done:
	close(sockfd);
done_no_socket:
	if (buf)
		free(buf);
	return UAP_SUCCESS;
}
static int uap_ioctl_reroute ( t_u8 * cmd , t_u16 * size , t_u16 buf_size , int * reroute_ret ) { t_u8 reroute = 0 ; t_u16 cmd_code = 0 ; t_u16 cmd_action = 0 ; apcmdbuf_cfg_80211d * hcmd_domain = NULL ; apcmdbuf_snmp_mib * hcmd_snmp = NULL ; tlvbuf_header * tlv = NULL ; struct ifreq ifr ; t_s32 sockfd ; t_u8 * buf = NULL ; t_u16 buf_len = 0 ; snmp_mib_param * snmp_param = NULL ; domain_info_param * domain_param = NULL ; cmd_code = ( ( apcmdbuf * ) ( cmd ) ) -> cmd_code ; switch ( cmd_code ) { case HostCmd_SNMP_MIB : hcmd_snmp = ( apcmdbuf_snmp_mib * ) cmd ; tlv = ( tlvbuf_header * ) ( cmd + sizeof ( apcmdbuf_snmp_mib ) ) ; cmd_action = uap_le16_to_cpu ( hcmd_snmp -> action ) ; if ( cmd_action == ACTION_SET ) { reroute = 1 ; buf_len = sizeof ( snmp_mib_param ) + uap_le16_to_cpu ( tlv -> len ) ; } break ; case HostCmd_CMD_802_11D_DOMAIN_INFO : hcmd_domain = ( apcmdbuf_cfg_80211d * ) cmd ; cmd_action = uap_le16_to_cpu ( hcmd_domain -> action ) ; if ( cmd_action == ACTION_SET ) { reroute = 1 ; buf_len = sizeof ( domain_info_param ) + ( * size - sizeof ( apcmdbuf_cfg_80211d ) + sizeof ( domain_param_t ) ) ; } break ; } if ( ! reroute || uap_ioctl_no_reroute ) return UAP_FAILURE ; #if DEBUG uap_printf ( MSG_DEBUG , " \n " , cmd_code ) ; #endif buf = ( t_u8 * ) malloc ( buf_len ) ; if ( ! buf ) { printf ( " \n " ) ; goto done_no_socket ; } memset ( buf , 0 , buf_len ) ; switch ( cmd_code ) { case HostCmd_SNMP_MIB : snmp_param = ( snmp_mib_param * ) buf ; snmp_param -> subcmd = UAP_SNMP_MIB ; snmp_param -> action = cmd_action ; snmp_param -> oid = uap_le16_to_cpu ( tlv -> type ) ; snmp_param -> oid_val_len = uap_le16_to_cpu ( tlv -> len ) ; memcpy ( snmp_param -> oid_value , tlv -> data , MIN ( sizeof ( t_u32 ) , snmp_param -> oid_val_len ) ) ; break ; case HostCmd_CMD_802_11D_DOMAIN_INFO : domain_param = ( domain_info_param * ) buf ; domain_param -> subcmd = UAP_DOMAIN_INFO ; domain_param -> action = cmd_action ; memcpy ( domain_param -> tlv , & hcmd_domain -> domain , buf_len - sizeof ( domain_info_param ) ) ; tlv = ( tlvbuf_header * ) domain_param -> tlv ; tlv -> type = uap_le16_to_cpu ( tlv -> type ) ; tlv -> len = uap_le16_to_cpu ( tlv -> len ) ; break ; } #if DEBUG hexdump ( " " , buf , buf_len , ' ' ) ; #endif if ( ( sockfd = socket ( AF_INET , SOCK_STREAM , 0 ) ) < 0 ) { printf ( " \n " ) ; goto done_no_socket ; } memset ( & ifr , 0 , sizeof ( ifr ) ) ; strncpy ( ifr . ifr_ifrn . ifrn_name , dev_name , IFNAMSIZ - 1 ) ; ifr . ifr_ifru . ifru_data = ( void * ) buf ; errno = 0 ; if ( ioctl ( sockfd , UAP_IOCTL_CMD , & ifr ) ) { * reroute_ret = UAP_FAILURE ; perror ( " " ) ; #if DEBUG uap_printf ( MSG_DEBUG , " \n " , cmd_code ) ; #endif goto done ; } * reroute_ret = UAP_SUCCESS ; done : close ( sockfd ) ; done_no_socket : if ( buf ) free ( buf ) ; return UAP_SUCCESS ; }
@brief  Checks if command requires driver handling, and if so,
          repackage and send as regular command, instead of hostcmd.
@brief Checks if command requires driver handling and if so repackage and send as regular command instead of hostcmd .
/* assume input is a hostcmd */ /* just check if we need to re-route right now */ /* reroute CMD_SNMP_MIB: SET */ /* reroute CMD_DOMAIN_INFO: SET */ /* Exit early if not re-routing */ /* Prepare buffer */ /* Prepare param */ /* Dump request buffer */ /* Open socket */ /* Initialize the ifr structure */ /* Perform ioctl */ /* Close socket */