smbmsg.c (129331) | smbmsg.c (129353) |
---|---|
1/*- 2 * Copyright (C) 2004 Joerg Wunsch 3 * All Rights Reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (C) 2004 Joerg Wunsch 3 * All Rights Reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/usr.sbin/smbmsg/smbmsg.c 129331 2004-05-17 10:56:05Z joerg $ | 26 * $FreeBSD: head/usr.sbin/smbmsg/smbmsg.c 129353 2004-05-17 19:19:08Z joerg $ |
27 */ 28 29/* 30 * Send or receive messages over an SMBus. 31 */ 32 33#include <err.h> 34#include <errno.h> --- 31 unchanged lines hidden (view full) --- 66/* 67 * The I2C specs say that all addresses below 16 and above or equal 68 * 240 are reserved. Address 0 is the global address, but we do not 69 * care for this detail. 70 */ 71#define MIN_I2C_ADDR 16 72#define MAX_I2C_ADDR 240 73 | 27 */ 28 29/* 30 * Send or receive messages over an SMBus. 31 */ 32 33#include <err.h> 34#include <errno.h> --- 31 unchanged lines hidden (view full) --- 66/* 67 * The I2C specs say that all addresses below 16 and above or equal 68 * 240 are reserved. Address 0 is the global address, but we do not 69 * care for this detail. 70 */ 71#define MIN_I2C_ADDR 16 72#define MAX_I2C_ADDR 240 73 |
74static int do_io(void); 75static int getnum(const char *s); 76static void probe_i2c(void); 77static void usage(void); 78 |
|
74static void 75usage(void) 76{ 77 fprintf(stderr, 78 "usage: smbmsg [-f dev] -p\n" 79 " smbmsg [-f dev] -s slave [-F fmt] [-c cmd] [-w] " 80 "[-i incnt] [-o outcnt] [outdata ...]\n"); | 79static void 80usage(void) 81{ 82 fprintf(stderr, 83 "usage: smbmsg [-f dev] -p\n" 84 " smbmsg [-f dev] -s slave [-F fmt] [-c cmd] [-w] " 85 "[-i incnt] [-o outcnt] [outdata ...]\n"); |
81 exit (EX_USAGE); | 86 exit(EX_USAGE); |
82} 83 84static int 85getnum(const char *s) 86{ 87 char *endp; 88 unsigned long l; 89 90 l = strtoul(s, &endp, 0); 91 if (*s != '\0' && *endp == '\0') 92 return (int)l; | 87} 88 89static int 90getnum(const char *s) 91{ 92 char *endp; 93 unsigned long l; 94 95 l = strtoul(s, &endp, 0); 96 if (*s != '\0' && *endp == '\0') 97 return (int)l; |
93 return -1; | 98 return (-1); |
94} 95 96static void 97probe_i2c(void) 98{ 99 unsigned char addr; 100 int flags; 101#define IS_READABLE 1 --- 228 unchanged lines hidden (view full) --- 330 close(fd); 331 errno = savederrno; 332 333 if (i == -1) 334 err(EX_UNAVAILABLE, "Error performing SMBus IO"); 335 else if (i == -2) 336 errx(EX_USAGE, "Invalid option combination"); 337 | 99} 100 101static void 102probe_i2c(void) 103{ 104 unsigned char addr; 105 int flags; 106#define IS_READABLE 1 --- 228 unchanged lines hidden (view full) --- 335 close(fd); 336 errno = savederrno; 337 338 if (i == -1) 339 err(EX_UNAVAILABLE, "Error performing SMBus IO"); 340 else if (i == -2) 341 errx(EX_USAGE, "Invalid option combination"); 342 |
338 return 0; | 343 return (0); |
339} | 344} |