Esempio n. 1
0
int libvlc_load(const char *path)
{
  int nameId = lastElem;

  if (g_file_test(path, G_FILE_TEST_EXISTS) == 0) {
    DPRINT_ERR("%s doesn't exist", path);
    goto error;
  }

  soundInst[nameId] = libvlc_new(0, NULL);
  soundMedia[nameId] = libvlc_media_new_path(soundInst[nameId], path);
  soundPlay[nameId] = libvlc_media_player_new_from_media(soundMedia[nameId]);

  if (soundInst[nameId]  == NULL || soundMedia[nameId] == NULL ||
      soundPlay[nameId] == NULL) {
    DPRINT_ERR("fail to load %s", path);
    goto error;
  }

  /* if (loop != 0) { */
  /*   libvlc_media_add_option(media, "input-repeat=-1"); */
  /* } */

  is_used[nameId] = 1;
  ++lastElem;
  return nameId;
 error:
  libvlc_stop(nameId);
  return -1;
}
Esempio n. 2
0
static int netvsc_open(struct net_device *net)
{
	struct net_device_context *net_device_ctx = netdev_priv(net);
	struct hv_device *device_obj = &net_device_ctx->device_ctx->device_obj;
	int ret = 0;

	DPRINT_ENTER(NETVSC_DRV);

	if (netif_carrier_ok(net)) {
		/* Open up the device */
		ret = RndisFilterOnOpen(device_obj);
		if (ret != 0) {
			DPRINT_ERR(NETVSC_DRV,
				   "unable to open device (ret %d).", ret);
			return ret;
		}

		netif_start_queue(net);
	} else {
		DPRINT_ERR(NETVSC_DRV, "unable to open device...link is down.");
	}

	DPRINT_EXIT(NETVSC_DRV);
	return ret;
}
/* to validate hostname/ip given by the client */
int validate_server_address()
{
    struct hostent *he;
    struct ipv4_addr temp;
    if (!wl_atoip(g_rwl_servIP, &temp)) {
        /* Wrong IP address format check for hostname */
        if ((he = gethostbyname(g_rwl_servIP)) != NULL) {
            if (!wl_atoip(*he->h_addr_list, &temp)) {
                g_rwl_servIP =
                    inet_ntoa(*(struct in_addr *)*he->h_addr_list);
                if (g_rwl_servIP == NULL) {
                    DPRINT_ERR(ERR, "Error at inet_ntoa \n");
                    return FAIL;
                }
            } else {
                DPRINT_ERR(ERR, "Error in IP address \n");
                return FAIL;
            }
        } else {
            DPRINT_ERR(ERR, "Enter correct IP address/hostname format\n");
            return FAIL;
        }
    }
    return SUCCESS;
}
Esempio n. 4
0
int
rwl_close_transport(int remote_type, void* handle)
{
	switch (remote_type) {
#ifdef RWL_SOCKET
		case REMOTE_SOCKET:
			shutdown(*((int*)handle), 1);
			if (rwl_closesocket(*((int*)handle)) != 1) {
				 DPRINT_ERR(ERR, "Can't Close socket \n");
				 return FAIL;
			}
			break;
#endif /* RWL_SOCKET */
#if defined (RWL_SERIAL) || defined (RWL_DONGLE)
		case REMOTE_SERIAL:
		case REMOTE_DONGLE:
			if (handle != NULL) {
				if (PurgeComm(handle, PURGE_TXABORT | PURGE_TXCLEAR |
				    PURGE_RXABORT | PURGE_RXCLEAR) == 0) {
					DPRINT_ERR(ERR, "rwl_close_transport: PurgeComm failed.\n");
				}
				Sleep(10);
				if (CloseHandle(handle) == 0) {
					DPRINT_ERR(ERR, "Can't Close serial port.\n");
					return FAIL;
				}
			}
			break;
#endif /* RWL_SERIAL  || RWL_DONGLE */
		default:
		DPRINT_ERR(ERR, "close_pipe: Unknown remote_type %d\n", remote_type);
		break;
	}
	return SUCCESS;
}
Esempio n. 5
0
/*
 * wfaStaGetStats():
 * The function is to retrieve the statistics of the I/F's layer 2 txFrames, 
 * rxFrames, txMulticast, rxMulticast, fcsErrors/crc, and txRetries.
 * Currently there is not definition how to use these info. 
 */
int wfaStaGetStats(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
{
	int ret = 0;
	caStaGetStatsResp_t statsResp;
	FILE *fd;
	char cmdStr[256];

	DPRINT_INFO(WFA_OUT, "Entering wfaStaGetStats ...\n");

	if ((fd = popen("/tmp/ASD/wl dump stats | grep txframe | awk '{print $2,\"\\n\",$10}'", "r")) == NULL){
		DPRINT_ERR(WFA_ERR, "Couldn't get txframe stats\n");
		goto wfaStaGetStats_error;
	} else {
		fgets(cmdStr, sizeof(cmdStr), fd);	/* line 1: tx frame */
		statsResp.txFrames =  atoi(cmdStr);
		fgets(cmdStr, sizeof(cmdStr), fd);	/* line 2: rx frame */
		statsResp.rxFrames =  atoi(cmdStr);
		pclose(fd);
	}

	if ((fd = popen("/tmp/ASD/wl dump stats | grep txmulti | awk '{print $4, \"\\n\", $6 + $8}'", "r")) == NULL){
		DPRINT_ERR(WFA_ERR, "Couldn't get d11_txmulti stats\n");
		goto wfaStaGetStats_error;
	} else {
		fgets(cmdStr, sizeof(cmdStr), fd);	/* line 1: txmulti */
		statsResp.txMulticast = atoi(cmdStr);
		fgets(cmdStr, sizeof(cmdStr), fd);	/* line 2: d11_txretry + d11_txretrie */
		statsResp.txRetries = atoi(cmdStr);
		pclose(fd);
	}

	if ((fd = popen("/tmp/ASD/wl dump stats | grep rxdfrmmcast | awk '{print $6 + $8}'", "r")) == NULL){
		DPRINT_ERR(WFA_ERR, "Couldn't get rxdfrmmcast stats\n");
		goto wfaStaGetStats_error;
	} else {
		fgets(cmdStr, sizeof(cmdStr), fd);	/* data + mngment mcast frames */
		statsResp.rxMulticast = atoi(cmdStr);
		pclose(fd);
	}

	if ((fd = popen("/tmp/ASD/wl dump stats | grep rxbadfcs | awk '{print $8}'", "r")) == NULL){
		DPRINT_ERR(WFA_ERR, "Couldn't get rxbadfcs  stats\n");
		goto wfaStaGetStats_error;
	} else {
		fgets(cmdStr, sizeof(cmdStr), fd);
		statsResp.fcsErrors = atoi(cmdStr);
		pclose(fd);
	}

	statsResp.status = STATUS_COMPLETE;
	wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, sizeof(statsResp), (BYTE *)&statsResp, respBuf);   
	*respLen = WFA_TLV_HDR_LEN + sizeof(statsResp);
	return TRUE;

wfaStaGetStats_error:
	ret = STATUS_ERROR;
	wfaEncodeTLV(WFA_STA_GET_STATS_RESP_TLV, 4, (BYTE *)&ret, respBuf);   
	*respLen = WFA_TLV_HDR_LEN + 4;
	return FALSE;
}
/** 
 * Create a UDP socket
 * @param ipaddr Local UDP ip address to bind.
 * @param port UDP port to receive and send packet.
 * @return socket id.
*/
int wfaCreateUDPSock(char *ipaddr, unsigned short port)
{
	int udpsock;                 /* socket to create */
	struct sockaddr_in servAddr; /* Local address */

	WSADATA wsadata;
	int wsaret=WSAStartup(MAKEWORD(2,2),&wsadata);

	if(wsaret!=0)
	{
		int errsv = WSAGetLastError();
		DPRINT_ERR(WFA_ERR, "createUDPSock socket() falled with error %d",errsv);
		return WFA_FAILURE;
	}
	if((udpsock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
	{
		int errsv = WSAGetLastError();
		DPRINT_ERR(WFA_ERR, "createUDPSock socket() failed with error %d for port %d",errsv,port);
		return WFA_FAILURE;
	}

	servAddr.sin_family      = AF_INET;
	servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servAddr.sin_port        = htons(port);

	bind(udpsock, (struct sockaddr *) &servAddr, sizeof(servAddr)); 

	return udpsock;
}
Esempio n. 7
0
static int netvsc_open(struct net_device *net)
{
	struct net_device_context *net_device_ctx = netdev_priv(net);
	struct driver_context *driver_ctx =
	    driver_to_driver_context(net_device_ctx->device_ctx->device.driver);
	struct netvsc_driver_context *net_drv_ctx =
		(struct netvsc_driver_context *)driver_ctx;
	struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj;
	struct hv_device *device_obj = &net_device_ctx->device_ctx->device_obj;
	int ret = 0;

	DPRINT_ENTER(NETVSC_DRV);

	if (netif_carrier_ok(net)) {
		memset(&net_device_ctx->stats, 0,
		       sizeof(struct net_device_stats));

		/* Open up the device */
		ret = net_drv_obj->OnOpen(device_obj);
		if (ret != 0) {
			DPRINT_ERR(NETVSC_DRV,
				   "unable to open device (ret %d).", ret);
			return ret;
		}

		netif_start_queue(net);
	} else {
		DPRINT_ERR(NETVSC_DRV, "unable to open device...link is down.");
	}

	DPRINT_EXIT(NETVSC_DRV);
	return ret;
}
Esempio n. 8
0
static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice)
{
	struct nvsp_message *revokePacket;
	int ret = 0;

	DPRINT_ENTER(NETVSC);

	
	if (NetDevice->ReceiveSectionCount) {
		DPRINT_INFO(NETVSC,
			    "Sending NvspMessage1TypeRevokeReceiveBuffer...");

		
		revokePacket = &NetDevice->RevokePacket;
		memset(revokePacket, 0, sizeof(struct nvsp_message));

		revokePacket->Header.MessageType = NvspMessage1TypeRevokeReceiveBuffer;
		revokePacket->Messages.Version1Messages.RevokeReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID;

		ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(
						NetDevice->Device,
						revokePacket,
						sizeof(struct nvsp_message),
						(unsigned long)revokePacket,
						VmbusPacketTypeDataInBand, 0);
		
		if (ret != 0) {
			DPRINT_ERR(NETVSC, "unable to send revoke receive "
				   "buffer to netvsp");
			DPRINT_EXIT(NETVSC);
			return -1;
		}
	}

	
	if (NetDevice->ReceiveBufferGpadlHandle) {
		DPRINT_INFO(NETVSC, "Tearing down receive buffer's GPADL...");

		ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl(
					NetDevice->Device,
					NetDevice->ReceiveBufferGpadlHandle);

		
		if (ret != 0) {
			DPRINT_ERR(NETVSC,
				   "unable to teardown receive buffer's gpadl");
			DPRINT_EXIT(NETVSC);
			return -1;
		}
		NetDevice->ReceiveBufferGpadlHandle = 0;
	}

	if (NetDevice->ReceiveBuffer) {
		DPRINT_INFO(NETVSC, "Freeing up receive buffer...");

		
		osd_PageFree(NetDevice->ReceiveBuffer,
			     NetDevice->ReceiveBufferSize >> PAGE_SHIFT);
		NetDevice->ReceiveBuffer = NULL;
	}
Esempio n. 9
0
int
rwl_read_serial_port(void* hndle, char* read_buf, uint data_size, uint *numread)
{
	uint total_numread = 0;
	int c = 0;

	while (total_numread < data_size) {
		if (ReadFile(hndle, read_buf, data_size - total_numread, numread, NULL) == 0) {
			DPRINT_ERR(ERR, "rwl_read_serial_port failed with:%d", WSAGetLastError());
			return FAIL;
		}
		if (*numread != data_size - total_numread) {
			c++;
			DPRINT_DBG(OUTPUT, "asked %d bytes got %d bytes\n",
				data_size - total_numread, *numread);
			if (c > MAX_SERIAL_READ_RETRY) {
			        DPRINT_ERR(ERR, "rwl_read_serial_port failed: "
				           "reached max retry limit.\n");
				return FAIL;
			}
			Sleep(10);
		}

		total_numread += *numread;
		read_buf += *numread;
	}
	return SUCCESS;
}
/*
 * find command in argv and execute it
 * Won't handle changing ifname yet, expects that to happen with the --interactive
 * Return an error if unable to find/execute command
 */
static int
wl_do_cmd(struct ifreq *ifr, char **argv)
{
    cmd_t *cmd = NULL;
    int err = 0;
    int help = 0;
    char *ifname = NULL;
    int status = CMD_WL;

    /* skip over 'wl' if it's there */
    if (*argv && strcmp (*argv, "wl") == 0) {
        argv++;
    }

    /* handle help or interface name changes */
    if (*argv && (status = wl_option (&argv, &ifname, &help)) == CMD_OPT) {
        if (ifname) {
            fprintf(stderr,
                    "Interface name change not allowed within --interactive\n");
        }
    }

    /* in case wl_option eats all the args */
    if (!*argv) {
        return err;
    }

    if (status != CMD_ERR) {
        /* search for command */
        cmd = wl_find_cmd(*argv);

        /* defaults to using the set_var and get_var commands */
        if (!cmd) {
            cmd = &wl_varcmd;
        }
        /* do command */
        err = (*cmd->func)((void *)ifr, cmd, argv);
    }
    /* provide for help on a particular command */
    if (help && *argv) {
        cmd = wl_find_cmd(*argv);
        if (cmd) {
            wl_cmd_usage(stdout, cmd);
        } else {
            DPRINT_ERR(ERR, "%s: Unrecognized command \"%s\", type -h for help\n",
                       wlu_av0, *argv);
        }
    } else if (!cmd)
        wl_usage(stdout, NULL);
    else if (err == USAGE_ERROR)
        wl_cmd_usage(stderr, cmd);
    else if (err == IOCTL_ERROR)
        wl_printlasterror((void *)ifr);
    else if (err == BCME_NODEVICE)
        DPRINT_ERR(ERR, "%s : wl driver adapter not found\n", g_rem_ifname);

    return err;
}
Esempio n. 11
0
/*
 * The function is to set 
 *   1. ssid
 *   2. passPhrase
 *   3. keyMangementType - wpa/wpa2
 *   4. encrypType - tkip or aes-ccmp
 */
int wfaStaSetPSK(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
{
	int ret = 0;
	int retVal = TRUE;
	caStaSetPSK_t *setPSK = (caStaSetPSK_t *)caCmdBuf;
	bcmSsidObj_t *bso;
	char *ssidStr;

	DPRINT_INFO(WFA_OUT, "wfaStaSetPSK()");

	ssidStr = setPSK->ssid;
	if (!(bso = bcmWfaSsidTblSsidFind(ssidStr))) {
		if (!(bso = bcmWfaSsidObjTblAdd(ssidStr))) {
			DPRINT_ERR(WFA_OUT, "bcmWfaSsidObjTblAdd(%s) failed.\n", ssidStr);
			retVal = FALSE;
			goto exit;
		}
	}

	if (!strcmp(setPSK->keyMgmtType, "wpa")) {
		bso->wpa_auth = BCM_WPA_AUTH_PSK; /* WPA-PSK/WPA-Personal */
	} else if (!strcmp(setPSK->keyMgmtType, "wpa2")) {
		bso->wpa_auth = BCM_WPA2_AUTH_PSK; /* WPA2-PSK/WPA2-Personal */
	} else {
		DPRINT_ERR(WFA_OUT, "invalid key_mgmt %s", setPSK->keyMgmtType); 
		retVal = FALSE;
		goto exit;
	}

	DPRINT_INFO(WFA_OUT, "wpa_auth %d\n", bso->wpa_auth);

	if (setPSK->encpType == ENCRYPT_TKIP) {
		bso->wsec = 3;
	} else if (setPSK->encpType == ENCRYPT_AESCCMP) {
		bso->wsec = 7;
	} else {
		DPRINT_ERR(WFA_OUT, "invalid encpType %d", setPSK->encpType); 
		goto exit;
	}
	DPRINT_INFO(WFA_OUT, "encpType %d wsec %d\n", setPSK->encpType, bso->wsec);

	strcpy((char *)bso->passphrase, (char *)setPSK->passphrase);
	bso->auth = 0;

	if (wfa_defined_debug & (WFA_DEBUG_ERR | WFA_DEBUG_INFO)) {
		bcmWfaSsidObjPrint(bso);
	}

	retVal = TRUE;

exit:	
	ret = STATUS_COMPLETE;
	wfaEncodeTLV(WFA_STA_SET_PSK_RESP_TLV, 4, (BYTE *)&ret, respBuf);   
	*respLen = WFA_TLV_HDR_LEN + 4;
	
	return retVal; 
}
Esempio n. 12
0
rem_ioctl_t *
remote_CDC_rx_hdr(void *remote, int debug)
{
#ifdef RWL_SOCKET
	int ret;
#endif /* RWL_SOCKET */
	uint numread = 0;
	rem_ioctl_t *rem_ptr = &rem_cdc;
	memset(rem_ptr, 0, sizeof(rem_ioctl_t));

#ifdef RWL_WIFI
	UNUSED_PARAMETER(remote);
	UNUSED_PARAMETER(numread);
#endif /* RWL_WIFI */

	UNUSED_PARAMETER(debug);

	switch (remote_type)	{
#if defined(RWL_SERIAL) || defined(RWL_DONGLE)
		case REMOTE_SERIAL:
		case REMOTE_DONGLE:
			if (rwl_read_serial_port(remote, (char *)rem_ptr, sizeof(rem_ioctl_t),
				&numread) < 0) {
				DPRINT_ERR(ERR, "remote_CDC_rx_hdr: Header Read failed \n");
				return (NULL);
			}
			break;
#endif /* RWL_SERIAL |  RWL_DONGLE */


#ifdef RWL_SOCKET
		case REMOTE_SOCKET:
			ret = rwl_receive_from_streamsocket(*(int*)remote, (char *)rem_ptr,
				sizeof(rem_ioctl_t), 0);
			numread = ret;
			if (ret == -1) {
				DPRINT_ERR(ERR, "remote_CDC_rx_hdr: numread:%d", numread);
				return (NULL);
			}
		if (numread == 0) {
		      DPRINT_DBG(OUTPUT, "\n remote_CDC_rx_hdr:No data to receive\n");
			return NULL;
			}
			break;
#endif
		default:
			DPRINT_ERR(ERR, "\n Unknown Transport Type\n");
			break;
	}

	return (rem_ptr);
}
Esempio n. 13
0
/* Note in case of error ( returned value == FAIL) it is assumed that wl is closed by caller,
 * no treatment in this function
 */
static int
rwl_socket_shellresp(void *wl, rem_ioctl_t *rem_ptr, uchar *input_buf)
{
	uchar* resp_buf = NULL;
	int pid, msg_len, error;
	g_sig_ctrlc = 1;
	// only for linux
	
	//g_child_pid = pid = rwl_shell_createproc(wl);
	g_child_pid = pid = 1;
	if (pid == 0) {
		while (g_sig_ctrlc);
		remote_CDC_tx(wl, 0, input_buf, 0, 0, CTRLC_FLAG, 0);
		exit(0);
	}

	do {
		if ((rem_ptr = remote_CDC_rx_hdr(wl, 0)) == NULL) {
		DPRINT_ERR(ERR, "rwl_socket_shellresp: Receiving CDC"
			"header failed\n");
		return FAIL;
		}
		msg_len = rem_ptr->msg.len;
		if ((resp_buf = malloc(rem_ptr->msg.len + 1)) == NULL) {
			DPRINT_ERR(ERR, "rwl_socket_shellresp: Mem alloc fails\n");
			return FAIL;
		}
		if (msg_len > 0) {
			if (remote_CDC_rx(wl, rem_ptr, resp_buf,
				rem_ptr->msg.len, 0) == FAIL) {
				DPRINT_ERR(ERR, "rwl_socket_shellresp: No results!\n");
				free(resp_buf);
				return FAIL;
			}
		}
		/* print the shell result */
		resp_buf[rem_ptr->msg.len] = '\0';
		/* The return value of the shell command
		 * will be stored in rem_ptr->msg.cmd
		 * Return that value to the client process
		 */
		if (rem_ptr->msg.flags & REMOTE_REPLY)
			error = rem_ptr->msg.cmd;
#ifdef LINUX
		write(1, resp_buf, msg_len);
#else
		fputs((char*)resp_buf, stdout);
#endif
	} while (msg_len);
	//rwl_shell_killproc(pid);
	return error;
}
Esempio n. 14
0
static int
rwl_dongle_shellresp(void *wl, rem_ioctl_t *rem_ptr, uchar *input_buf, int cmd)
{
	int pid, msg_len, error;
	uchar *resp_buf;

	g_sig_ctrlc = 1;
	g_child_pid = pid = rwl_shell_createproc(wl);
	if (pid == 0) {
		while (g_sig_ctrlc);
		remote_CDC_tx(wl, cmd, input_buf, 0, 0, CTRLC_FLAG, 0);
		exit(0);
	}

	do {
		if ((rem_ptr = remote_CDC_rx_hdr(wl, 0)) == NULL) {
			DPRINT_ERR(ERR, "shell_info_fe: Receiving CDC header failed\n");
			return BCME_SERIAL_PORT_ERR;
		}
		/* In case of shell or ASD commands the response size is not known in advance
		* Hence based on response from the server memory is allocated
		*/
		msg_len = rem_ptr->msg.len;
		if ((resp_buf = malloc(rem_ptr->msg.len + 1)) == NULL) {
			DPRINT_ERR(ERR, "Mem alloc fails for shell response buffer\n");
			return FAIL;
		}
		/* Response comes in one shot not in fragments */
		if (remote_CDC_rx(wl, rem_ptr, resp_buf,
			rem_ptr->msg.len, 0) == FAIL) {
			DPRINT_ERR(ERR, "shell_info_fe: No results!\n");
			free(resp_buf);
			return FAIL;
		}
		/* print the shell result */
		resp_buf[rem_ptr->msg.len] = '\0';
		/* The return value of the shell command will be stored in rem_ptr->msg.cmd
		 * Return that value to the client process
		 */
		if (rem_ptr->msg.flags & REMOTE_REPLY)
			error = rem_ptr->msg.cmd;
#ifdef LINUX
		write(1, resp_buf, msg_len);
#else
		fputs((char*)resp_buf, stdout);
#endif
	} while (msg_len);
	rwl_shell_killproc(pid);
	return error;
}
void*
rwl_open_transport(int remote_type, char *port, int ReadTotalTimeout, int debug)
{
	void* hndle;

	UNUSED_PARAMETER(port);
	UNUSED_PARAMETER(ReadTotalTimeout);
	UNUSED_PARAMETER(debug);

	switch (remote_type) {
#if defined(RWL_DONGLE) || defined(RWL_SERIAL)
	case REMOTE_SERIAL:
#ifdef RWL_SERIAL
			g_rwl_device_name_serial = port;
#endif
	case REMOTE_DONGLE:
			if ((g_irh = rwl_open_serial(remote_type, g_rwl_device_name_serial))
				 == FAIL) {
			/* Initial port opening settings failed in reboot. 
			 * So retry opening the serial port
			 */
				if ((g_irh = rwl_open_serial(remote_type, g_rwl_device_name_serial))
					 == FAIL) {
					DPRINT_ERR(ERR, "Can't open serial port\n");
					return NULL;
				}
			}
			break;
#endif /* RWL_DONGLE || RWL_SERIAL */

#ifdef RWL_SOCKET
		case REMOTE_SOCKET:
			if ((g_irh = rwl_opensocket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == FAIL) {
				DPRINT_ERR(ERR, "\nCan't open socket \n");
				return NULL;
			}

			break;
#endif /* RWL_SOCKET */

		default:
		DPRINT_ERR(ERR, "rwl_open_transport: Unknown remote_type %d\n", remote_type);
		return NULL;
		break;
	} /* end - switch case */

	hndle = (void*) &g_irh;
	return hndle;
}
Esempio n. 16
0
/* This routine is used for both Get and Set Ioctls for the socket */
static int
rwl_information_socket(void *wl, int cmd, void* input_buf, unsigned long *input_len,
	unsigned long *tx_len, uint flags)
{
	int error, Sockfd;
	rem_ioctl_t *rem_ptr = NULL;

	if ((Sockfd = rwl_connect_socket_server()) < 0) {
		DPRINT_ERR(ERR, "Error in getting the Socket Descriptor\n");
		return FAIL;
	}
	wl = (void *)(&Sockfd);

	if (remote_CDC_tx(wl, cmd, input_buf, *input_len,
		*tx_len, flags, 0) < 0) {
		DPRINT_ERR(ERR, "query_info_fe: Send command failed\n");
		rwl_close_pipe(remote_type, wl);
		return FAIL;
	}

	if ((rem_ptr = remote_CDC_rx_hdr(wl, 0)) == NULL) {
		DPRINT_ERR(ERR, "query_info_fe: Reading CDC header 	failed\n");
		rwl_close_pipe(remote_type, wl);
		return FAIL;
	}
	rwl_swap_header(rem_ptr, NETWORK_TO_HOST);

	if (rem_ptr->msg.len > *input_len) {
		DPRINT_ERR(ERR, "query_info_fe: needed size(%d) > "
		           "actual size(%ld)\n", rem_ptr->msg.len, *input_len);
		rwl_close_pipe(remote_type, wl);
		return FAIL;
	}

	if (remote_CDC_rx(wl, rem_ptr, input_buf, *input_len, 0) == FAIL) {
		DPRINT_ERR(ERR, "query_info_fe: No results!\n");
		rwl_close_pipe(remote_type, wl);
		return FAIL;
	}

	if (rem_ptr->msg.flags & REMOTE_REPLY)
		error = rem_ptr->msg.cmd;
	else
		error = 0;

	rwl_close_pipe(remote_type, wl);

	return error;
}
Esempio n. 17
0
int
rwl_read_serial_port(void* hndle, char* read_buf, uint data_size, uint *numread)
{
	uint total_numread = 0;
	int c = 0;

	while (total_numread < data_size) {
		if (ReadFile(hndle, read_buf, data_size - total_numread, (LPDWORD) numread, NULL) == 0) {
			DPRINT_ERR(ERR, "rwl_read_serial_port failed with:%d", GetLastError());
			return FAIL;
		}
		if (*numread != data_size - total_numread) {
			c++;
			DPRINT_DBG(OUTPUT, "asked %d bytes got %d bytes\n",
				data_size - total_numread, *numread);
			if (c > MAX_SERIAL_READ_RETRY) {
			        DPRINT_ERR(ERR, "rwl_read_serial_port failed: "
				           "reached max retry limit.\n");
				return FAIL;
			}
			Sleep(10);
		}

		total_numread += *numread;
		read_buf += *numread;
	}
#ifdef DEBUG_SERIAL
    printf( "\nr %04d < ", total_numread);
    int i;
    for( i = 0; i < total_numread; i++ )
    {
#ifdef READABLE_SERIAL_DUMP
        if ( ( orig_read_buf[i] >= 0x20 ) && ( orig_read_buf[i] <= 0x7E ) )
        {
            printf( "%c",orig_read_buf[i]);
        }
        else
        {
            printf( "\\x%02X",(unsigned char)orig_read_buf[i]);
        }
#else /* ifdef READABLE_SERIAL_DUMP */
        printf( " %02X",(unsigned char)orig_read_buf[i]);
#endif /* ifdef READABLE_SERIAL_DUMP */
    }
    printf("\n");
#endif /* ifdef DEBUG_SERIAL */
	return SUCCESS;
}
/** 
 * Create a TCP socket
 * @param serverIpAddr TCP Local ip address to bind.
 * @param port TCP port to receive and send packet.
 * @return socket id.
*/
int wfaCreateTCPServSockImpl(char *serverIpAddr, unsigned short port)
{
    int sock;                    /* socket to create */
    struct sockaddr_in servAddr; /* Local address */
    const int on = 1;
    WSADATA wsaData;
    BOOL bOpt = TRUE;

    int wsaret = WSAStartup(0x101,&wsaData);
    if(wsaret != 0)
    {
        DPRINT_ERR(WFA_ERR, "socket init failed");
        return WFA_FAILURE;
    }

    /* Create socket for incoming connections */
    if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    {
        DPRINT_ERR(WFA_ERR, "createTCPServSock socket() failed");
        return WFA_FAILURE;
    }

    setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,(char*)&bOpt,sizeof(BOOL));
      
    /* Construct local address structure */
    memset(&servAddr, 0, sizeof(servAddr));

    servAddr.sin_family = AF_INET;        /* Internet address family */
    //servAddr.sin_addr.s_addr = inet_addr(serverIpAddr); /* Any incoming interface */
    servAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */
    servAddr.sin_port = htons(port);              /* Local port */

    /* Bind to the local address */
    if (bind(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
    {
        DPRINT_ERR(WFA_ERR, "bind() failed");
        return WFA_FAILURE;
    }

    /* Mark the socket so it will listen for incoming connections */
    if (listen(sock, MAXPENDING) < 0)
    {
        DPRINT_ERR(WFA_ERR, "listen() failed");
        return WFA_FAILURE;
    }

    return sock;
}
Esempio n. 19
0
/*
 * wfaStaGetMacAddress()
 *    This function is to retrieve the MAC address of a wireless I/F.
 */
int wfaStaGetMacAddress(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
{
	dutCmdResponse_t getmacResp;
	FILE *tmpfd;

	DPRINT_INFO(WFA_OUT, "Entering wfaStaGetMacAddress ...\n");

	if ((tmpfd = popen("/tmp/ASD/wl dump | grep perm | awk '{print $4}'", "r")) == NULL){
		int status = STATUS_ERROR;
		wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, 4, (BYTE *)&status, respBuf);   
		*respLen = WFA_TLV_HDR_LEN + 4;

		DPRINT_ERR(WFA_ERR, "Pipe open for wl dump failed\n");
		return FALSE;
	}
	fgets(getmacResp.cmdru.mac, sizeof(getmacResp.cmdru.mac), tmpfd);
	getmacResp.cmdru.mac[strlen(getmacResp.cmdru.mac) - 1] = 0;		/* Get rid of NL */
	printf("get_mac_addr: returning mac :%s:\n", getmacResp.cmdru.mac);
	pclose (tmpfd);
	getmacResp.status = STATUS_COMPLETE;
 
	wfaEncodeTLV(WFA_STA_GET_MAC_ADDRESS_RESP_TLV, sizeof(getmacResp), 
		(BYTE *)&getmacResp, respBuf);   

	*respLen = WFA_TLV_HDR_LEN + sizeof(getmacResp);
	return TRUE;
}
Esempio n. 20
0
bcmSsidObj_t *bcmWfaSsidObjTblAdd(char *ssidStr)
{
	bcmSsidObj_t *bso;

	DPRINT_INFO(WFA_OUT, "bcmWfaSsidObjTblAdd: ssidStr %s\n", ssidStr);

	if (bcmSsidIsGood(ssidStr) == FALSE) {
		return (NULL);
	}

	if ((bso = bcmWfaSsidTblSsidFind(ssidStr))) {
		DPRINT_ERR(WFA_OUT, "bcmWfaSsidObjTblAdd(%s): ssid already exists\n", ssidStr);
		return (bso);
	}

	if (!(bso = bcmWfaSsidTblFreeEntry())) {
		DPRINT_INFO(WFA_OUT, "no free entry\n");
		return (NULL);
	}	

	strcpy(bso->ssidStr, ssidStr);
	bso->bssType = BCM_BSS_INFRA; /* init it to infrastructure bss */
	bso->primary_key = BCM_PRI_KEY_BAD; /* init it to bad one */

	bsotbl.addCnt++;
	bsotbl.entries++;

	return (bso);
}
Esempio n. 21
0
/* 
 * check for the channel of remote and respond if it matches with its current
 * channel. Once the server gets the handshake cmd, it will check the channel
 * number of the remote with its channel and if it matches , then it send out the
 * ack to the remote client. This fucntion is used only by the server.
 */
void
rwl_wifi_find_server_response(void *wl, dot11_action_wifi_vendor_specific_t *rec_frame)
{
	int error, send, server_channel;

	if (rec_frame->type == RWL_WIFI_FIND_MY_PEER) {

		rec_frame->type = RWL_WIFI_FOUND_PEER;
		/* read channel on of the SERVER */
		rwl_wifi_config_channel(wl, WLC_GET_CHANNEL, &server_channel);
		/* overlapping channel not supported, 
		so server will only respond to client on the channel of the client
		*/
		if (rec_frame->data[RWL_WIFI_CLIENT_CHANNEL_OFFSET] == server_channel) {
			/* send the response by updating server channel in the frame */
			rec_frame->data[RWL_WIFI_SERVER_CHANNEL_OFFSET] = server_channel;
			/* change the TYPE feild for giving the ACK */
			for (send = 0; send < RWL_WIFI_SEND; send++) {
				if ((error = rwl_var_setbuf(wl, RWL_WIFI_ACTION_CMD, rec_frame,
					RWL_WIFI_ACTION_FRAME_SIZE)) < 0) {
					DPRINT_ERR(ERR, "rwl_wifi_find_server_response: Failed"
					"to Send the Frame %d\n", error);
					break;
				}
				rwl_sleep(RWL_WIFI_SEND_DELAY);
			}
		}
	}
	return;
}
Esempio n. 22
0
/* 
 * Read the valid action frame through the REF/DUT driver interface.
 * Retry for no of times, wait for action frame for the specified time.
 */
int
remote_CDC_DATA_wifi_rx(void *wl, dot11_action_wifi_vendor_specific_t * rec_frame)
{
	int error, read_try;
	void *ptr = NULL;


	/* retry is to ensure to read late arrival action frame */
	for (read_try = 0; read_try < RWL_WIFI_RX_RETRY; read_try++) {
		/* read the action frame queued in the local driver wifi queue */
		if ((error = rwl_var_getbuf(wl, RWL_WIFI_GET_ACTION_CMD, rec_frame,
		 RWL_WIFI_ACTION_FRAME_SIZE, &ptr)) < 0) {
			DPRINT_ERR(ERR, "remote_CDC_DATA_wifi_rx: Error in reading the frame %d\n",
			error);
			return error;
		}
		/* copy the read action frame to the user frame and cjheck for the action category. 
		 *  If the action category matches with RWL_ACTION_WIFI_CATEGORY ,
		 *  then its the valid frame, otherwise ignore it.
		 */
		memcpy((char*)rec_frame, ptr, RWL_WIFI_ACTION_FRAME_SIZE);

		if (rec_frame->category == RWL_ACTION_WIFI_CATEGORY) {
			break;
		} else {
			rwl_sleep(RWL_WIFI_RX_DELAY);
		}
	}
	/* If failed to get the valid frame , indicate the error  */
	if (!(rec_frame->category == RWL_ACTION_WIFI_CATEGORY)) {
		return (FAIL);
	}
	return error;
}
/*
 * netvsc_linkstatus_callback - Link up/down notification
 */
static void netvsc_linkstatus_callback(struct hv_device *device_obj,
				       unsigned int status)
{
	struct vm_device *device_ctx = to_vm_device(device_obj);
	struct net_device *net = dev_get_drvdata(&device_ctx->device);
	struct net_device_context *ndev_ctx;

	DPRINT_ENTER(NETVSC_DRV);

	if (!net) {
		DPRINT_ERR(NETVSC_DRV, "got link status but net device "
				"not initialized yet");
		return;
	}

	if (status == 1) {
		netif_carrier_on(net);
		netif_wake_queue(net);
		netif_notify_peers(net);
		ndev_ctx = netdev_priv(net);
		schedule_work(&ndev_ctx->work);
	} else {
		netif_carrier_off(net);
		netif_stop_queue(net);
	}
	DPRINT_EXIT(NETVSC_DRV);
}
Esempio n. 24
0
/* 
 * This function runs a set of commands before running the wi-fi server
 * This is avoids packet drops and improves performance.
 * We run the following wl commands
 * up, mpc 0, wsec 0, slow_timer 999999, fast_timer 999999, glacial_timer 999999
 * legacylink 1, monitor 1.
 */
void remote_wifi_ser_init_cmds(void *wl)
{
	int err;
	char bigbuf[RWL_WIFI_BUF_LEN];
	uint len = 0, count;
	/* The array stores command, length and then data format */
	remote_wifi_cmds_t wifi_cmds[] = {
						{WLC_UP,  NULL, 0x0},
						{WLC_SET_VAR,  "mpc", 0},
						{WLC_SET_WSEC,  NULL, 0x0},
						{WLC_SET_VAR, "slow_timer", 999999},
						{WLC_SET_VAR, "fast_timer", 999999},
						{WLC_SET_VAR, "glacial_timer", 999999},
						{WLC_SET_MONITOR, NULL, 0x1},
						{WLC_SET_PM, NULL, 0x0}
	};

	for (count = 0; count < ARRAYSIZE(wifi_cmds); count++) {

		if (wifi_cmds[count].data == NULL)
			len = sizeof(int);
		else
			len = strlen(wifi_cmds[count].data) + 1 + sizeof(int);

		/* If the command length exceeds the buffer length continue 
		 * executing the next command
		 */
		if (len > sizeof(bigbuf)) {
			DPRINT_ERR(ERR, "Err: command len exceeds buf len. Check"
				"initialization cmds\n");
			continue;
		}

		if (wifi_cmds[count].data != NULL) {
			strcpy(bigbuf, wifi_cmds[count].data);
			memcpy(&bigbuf[strlen(wifi_cmds[count].data)+1],
			(char*)&wifi_cmds[count].value, sizeof(int));
		} else {
			memcpy(&bigbuf[0], (char*)&wifi_cmds[count].value, sizeof(int));
		}
#ifdef WIN32
		/* Add OID base for NDIS commands */

		err = (int)ir_setinformation(wl, wifi_cmds[count].cmd + WL_OID_BASE,
		bigbuf, &len);
#endif

		if (wifi_cmds[count].cmd == WLC_UP)
			/* NULL needs to be passed to the driver if WL UP command needs to 
			 * be executed Otherwise driver hangs
			 */
			err = wl_ioctl(wl, wifi_cmds[count].cmd,
				NULL, 0, TRUE);
		else
			err = wl_ioctl(wl, wifi_cmds[count].cmd,
			(void*)&bigbuf, len, TRUE);

		rwl_sleep(INIT_CMD_SLEEP);
	}
}
Esempio n. 25
0
/* Function: remote_rx_data
 * This function will receive the data from client
 * for different transports
 * In case of socket the data comes from a open TCP socket
 * However in case of dongle UART or wi-fi the data is accessed
 * from the driver buffers.
 */
int
remote_rx_data(void* buf_ptr)
{
#if defined (RWL_SOCKET) || defined (RWL_SERIAL)

	if ((remote_CDC_rx((void *)&g_rwl_hndle, g_rem_ptr, buf_ptr,
	                             g_rem_ptr->msg.len, 0)) == BCME_ERROR) {
		DPRINT_ERR(ERR, "Reading CDC %d data bytes failed\n", g_rem_ptr->msg.len);
		return BCME_ERROR;
	}
#elif defined (RWL_DONGLE) || defined (RWL_WIFI)
	if (g_rem_ptr->data_len != 0) {
		int length = g_rem_ptr->data_len;
		if (g_rem_ptr->data_len > g_rem_ptr->msg.len) {
			length = g_rem_ptr->msg.len;
		}
		memcpy(buf_ptr, g_rem_pkt_ptr->message, length);
	}
	else
		buf_ptr = NULL;
#else
	UNUSED_PARAMETER(buf_ptr);
#endif /* RWL_SOCKET || RWL_SERIAL */
	return SUCCESS;
}
int
rwl_read_serial_port(void* hndle, char* read_buf, uint data_size, uint *numread)
{
	int ret;
	uint total_numread = 0;
	while (total_numread < data_size) {
		ret = read(*(int *)hndle, read_buf, data_size - total_numread);
		*numread = ret;
		if (ret == -1) {

			perror("ReadFromPort Failed");
			DPRINT_ERR(ERR, "Errno:%d\n", errno);
			return FAIL;
		}
		if (*numread != data_size - total_numread) {
			DPRINT_DBG(OUTPUT, "asked for %d bytes got %d bytes\n",
			data_size - total_numread, *numread);
		}
		if (*numread == 0)
			break;

		total_numread += *numread;
		read_buf += *numread;
	}
	return SUCCESS;
}
/* Receive the response from the opened TCP stream socket */
int
rwl_receive_from_streamsocket(int SocketDes, char* RecvBuff, int data_size, int Flag)
{
	int numread;
	int total_numread = 0;

	while (total_numread < data_size) {
		if ((numread = recv(SocketDes, RecvBuff, data_size - total_numread, Flag)) == -1) {
			perror("Failed to Receive()");
			DPRINT_ERR(ERR, "\n errno:%d\n", errno);
			return FAIL;
		}

		if (numread != data_size - total_numread) {
			DPRINT_DBG(OUTPUT, "asked %d bytes got %d bytes\n",
				data_size - total_numread, numread);
		}

		if (numread == 0)
			break;

		total_numread += numread;
		RecvBuff += numread;
	}

	return numread;
}
/* Transmit the response in the opened TCP stream socket */
int
rwl_send_to_streamsocket(int SocketDes, const char* SendBuff, int data_size, int Flag)
{
	int total_numwritten = 0,  numwritten = 0;
	while (total_numwritten < data_size) {
		if ((numwritten = send(SocketDes, SendBuff,
			data_size - total_numwritten, Flag)) == -1) {
			perror("Failed to send()");
			DPRINT_ERR(ERR, "\n errno:%d\n", errno);
			return (FAIL);
		}

		/* Sent successfully at first attempt no more retries */
		if (numwritten == data_size) {
			total_numwritten = numwritten;
			break;
		}

		/* If socket is busy we may hit this condition */
		if (numwritten != data_size - total_numwritten) {
			DPRINT_DBG(OUTPUT, "wanted to send %d bytes sent only %d bytes\n",
				data_size - total_numwritten, numwritten);
		}

		/* Now send the remaining buffer */
		total_numwritten += numwritten;
		SendBuff += numwritten;
	}

	return total_numwritten;
}
int
rwl_close_transport(int remote_type, void* Des)
{
	switch (remote_type) {
#ifdef RWL_SOCKET
		case REMOTE_SOCKET:
			if (rwl_closesocket(*(int *)Des) == FAIL)
				return FAIL;
		break;
#endif /* RWL_SOCKET */

#if defined(RWL_DONGLE) || defined(RWL_SERIAL)
	case REMOTE_DONGLE:
	case REMOTE_SERIAL:
			if (close(*(int *)Des) == -1)
				return FAIL;
		break;
#endif /* RWL_DONGLE || RWL_SERIAL */

		default:
			DPRINT_ERR(ERR, "close_pipe: Unknown remote_type %d\n", remote_type);
		break;
	}
	return SUCCESS;
}
/* Function to get the shell response from the file */
int
remote_shell_async_get_resp(char* shell_fname, char* buf_ptr, int msg_len)
{
	int sts = 0;
	FILE *shell_fpt;

	shell_fpt = fopen(shell_fname, "rb");

	if (shell_fpt == NULL) {
		DPRINT_ERR(ERR, "\nShell Cmd:File open error\n");
		return sts;
	}

	/* If there is any response from the shell, Read the file and 
	 * update the buffer for the shell response
	 * else Just send the return value of the command executed
	 */
	if (g_shellsync_pid != SHELL_ASYNCCMD_ID) {
		if (msg_len)
			sts  = fread(buf_ptr, sizeof(char), msg_len, shell_fpt);
		fscanf(shell_fpt, "%2x", &sts);
	}
	else
		sts  = fread(buf_ptr, sizeof(char), MAX_SHELL_CMD_LENTH, shell_fpt);

	fclose(shell_fpt);

	remove(shell_fname);

	DPRINT_DBG(OUTPUT, "\n Resp buff from shell cmdis %s\n", buf_ptr);

	return sts;
}