FreeBSD/sbin/ifconfig/sfp.c
/*
 * Reads i2c data from opened kernel socket.
 */
Reads i2c data from opened kernel socket.
Reads i2c data from opened kernel socket .
static int
read_i2c(struct i2c_info *ii, uint8_t addr, uint8_t off, uint8_t len,
    uint8_t *buf)
{
	struct ifi2creq req;
	int i, l;
	if (ii->error != 0)
		return (ii->error);
	ii->ifr->ifr_data = (caddr_t)&req;
	i = 0;
	l = 0;
	memset(&req, 0, sizeof(req));
	req.dev_addr = addr;
	req.offset = off;
	req.len = len;
	while (len > 0) {
		l = MIN(sizeof(req.data), len);
		req.len = l;
		if (ioctl(ii->fd, SIOCGI2C, ii->ifr) != 0) {
			ii->error = errno;
			return (errno);
		}
		memcpy(&buf[i], req.data, l);
		len -= l;
		i += l;
		req.offset += l;
	}
	return (0);
}
static int read_i2c ( struct i2c_info * ii , uint8_t addr , uint8_t off , uint8_t len , uint8_t * buf ) { struct ifi2creq req ; int i , l ; if ( ii -> error != 0 ) return ( ii -> error ) ; ii -> ifr -> ifr_data = ( caddr_t ) & req ; i = 0 ; l = 0 ; memset ( & req , 0 , sizeof ( req ) ) ; req . dev_addr = addr ; req . offset = off ; req . len = len ; while ( len > 0 ) { l = MIN ( sizeof ( req . data ) , len ) ; req . len = l ; if ( ioctl ( ii -> fd , SIOCGI2C , ii -> ifr ) != 0 ) { ii -> error = errno ; return ( errno ) ; } memcpy ( & buf [ i ] , req . data , l ) ; len -= l ; i += l ; req . offset += l ; } return ( 0 ) ; }
Reads i2c data from opened kernel socket.
Reads i2c data from opened kernel socket .