contrib/hostapd/hostapd/driver_prism54.c
static int prism54_waitpim(void *priv, unsigned long oid, void *buf, int len,
			   int timeout)
{
	struct prism54_driver_data *drv = priv;
	struct timeval tv, stv, ctv;
	fd_set pfd;
	int rlen;
	pimdev_hdr *pkt;

	pkt = malloc(8192);
	if (pkt == NULL)
		return -1;

	FD_ZERO(&pfd);
	gettimeofday(&stv, NULL);
	do {
		FD_SET(drv->pim_sock, &pfd);
		tv.tv_sec = 0;
		tv.tv_usec = 10000;
		if (select(drv->pim_sock + 1, &pfd, NULL, NULL, &tv)) {
			rlen = recv(drv->pim_sock, pkt, 8192, 0);
			if (rlen > 0) {
				if (pkt->oid == htonl(oid)) {
					if (rlen <= len) {
						if (buf != NULL) {
							memcpy(buf, pkt, rlen);
						}
						free(pkt);
						return rlen;
					} else {
						printf("buffer too small\n");
						free(pkt);
						return -1;
					}
				} else {
					gettimeofday(&ctv, NULL);
					continue;
				}
			}
		}
		gettimeofday(&ctv, NULL);
	} while (((ctv.tv_sec - stv.tv_sec) * 100 +
		  (ctv.tv_usec - stv.tv_usec) / 10000) > timeout);
	free(pkt);
	return 0;
}
/* wait for a specific pimfor, timeout in 10ms resolution */
/* pim_sock must be non-block to prevent dead lock from no response */
/* or same response type in series */
wait for a specific pimfor, timeout in 10ms resolution
pim_sock must be non-block to prevent dead lock from no response
or same response type in series
wait for a specific pimfor timeout in 10ms resolution pim_sock must be non - block to prevent dead lock from no response or same response type in series
static int prism54_waitpim(void *priv, unsigned long oid, void *buf, int len,
			   int timeout)
{
	struct prism54_driver_data *drv = priv;
	struct timeval tv, stv, ctv;
	fd_set pfd;
	int rlen;
	pimdev_hdr *pkt;
	pkt = malloc(8192);
	if (pkt == NULL)
		return -1;
	FD_ZERO(&pfd);
	gettimeofday(&stv, NULL);
	do {
		FD_SET(drv->pim_sock, &pfd);
		tv.tv_sec = 0;
		tv.tv_usec = 10000;
		if (select(drv->pim_sock + 1, &pfd, NULL, NULL, &tv)) {
			rlen = recv(drv->pim_sock, pkt, 8192, 0);
			if (rlen > 0) {
				if (pkt->oid == htonl(oid)) {
					if (rlen <= len) {
						if (buf != NULL) {
							memcpy(buf, pkt, rlen);
						}
						free(pkt);
						return rlen;
					} else {
						printf("buffer too small\n");
						free(pkt);
						return -1;
					}
				} else {
					gettimeofday(&ctv, NULL);
					continue;
				}
			}
		}
		gettimeofday(&ctv, NULL);
	} while (((ctv.tv_sec - stv.tv_sec) * 100 +
		  (ctv.tv_usec - stv.tv_usec) / 10000) > timeout);
	free(pkt);
	return 0;
}
static int prism54_waitpim ( void * priv , unsigned long oid , void * buf , int len , int timeout ) { struct prism54_driver_data * drv = priv ; struct timeval tv , stv , ctv ; fd_set pfd ; int rlen ; pimdev_hdr * pkt ; pkt = malloc ( 8192 ) ; if ( pkt == NULL ) return -1 ; FD_ZERO ( & pfd ) ; gettimeofday ( & stv , NULL ) ; do { FD_SET ( drv -> pim_sock , & pfd ) ; tv . tv_sec = 0 ; tv . tv_usec = 10000 ; if ( select ( drv -> pim_sock + 1 , & pfd , NULL , NULL , & tv ) ) { rlen = recv ( drv -> pim_sock , pkt , 8192 , 0 ) ; if ( rlen > 0 ) { if ( pkt -> oid == htonl ( oid ) ) { if ( rlen <= len ) { if ( buf != NULL ) { memcpy ( buf , pkt , rlen ) ; } free ( pkt ) ; return rlen ; } else { printf ( " \n " ) ; free ( pkt ) ; return -1 ; } } else { gettimeofday ( & ctv , NULL ) ; continue ; } } } gettimeofday ( & ctv , NULL ) ; } while ( ( ( ctv . tv_sec - stv . tv_sec ) * 100 + ( ctv . tv_usec - stv . tv_usec ) / 10000 ) > timeout ) ; free ( pkt ) ; return 0 ; }
wait for a specific pimfor, timeout in 10ms resolution
pim_sock must be non-block to prevent dead lock from no response
or same response type in series
wait for a specific pimfor timeout in 10ms resolution pim_sock must be non - block to prevent dead lock from no response or same response type in series