1 /*
2     OW -- One-Wire filesystem
3     version 0.4 7/2/2003
4 
5     Function naming scheme:
6     OW -- Generic call to interaface
7     LI -- LINK commands
8     L1 -- 2480B commands
9     FS -- filesystem commands
10     UT -- utility functions
11 
12     LICENSE (As of version 2.5p4 2-Oct-2006)
13     owlib: GPL v2
14     owfs, owhttpd, owftpd, owserver: GPL v2
15     owshell(owdir owread owwrite owpresent): GPL v2
16     owcapi (libowcapi): GPL v2
17     owperl: GPL v2
18     owtcl: LGPL v2
19     owphp: GPL v2
20     owpython: GPL v2
21     owsim.tcl: GPL v2
22     where GPL v2 is the "Gnu General License version 2"
23     and "LGPL v2" is the "Lesser Gnu General License version 2"
24 
25 
26     Written 2003 Paul H Alfille
27         Fuse code based on "fusexmp" {GPL} by Miklos Szeredi, mszeredi@inf.bme.hu
28         Serial code based on "xt" {GPL} by David Querbach, www.realtime.bc.ca
29         in turn based on "miniterm" by Sven Goldt, goldt@math.tu.berlin.de
30     GPL license
31     This program is free software; you can redistribute it and/or
32     modify it under the terms of the GNU General Public License
33     as published by the Free Software Foundation; either version 2
34     of the License, or (at your option) any later version.
35 
36     This program is distributed in the hope that it will be useful,
37     but WITHOUT ANY WARRANTY; without even the implied warranty of
38     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39     GNU General Public License for more details.
40 
41     Other portions based on Dallas Semiconductor Public Domain Kit,
42     ---------------------------------------------------------------------------
43     Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
44         Permission is hereby granted, free of charge, to any person obtaining a
45         copy of this software and associated documentation files (the "Software"),
46         to deal in the Software without restriction, including without limitation
47         the rights to use, copy, modify, merge, publish, distribute, sublicense,
48         and/or sell copies of the Software, and to permit persons to whom the
49         Software is furnished to do so, subject to the following conditions:
50         The above copyright notice and this permission notice shall be included
51         in all copies or substantial portions of the Software.
52     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
53     OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54     MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55     IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
56     OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
57     ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
58     OTHER DEALINGS IN THE SOFTWARE.
59         Except as contained in this notice, the name of Dallas Semiconductor
60         shall not be used except as stated in the Dallas Semiconductor
61         Branding Policy.
62     ---------------------------------------------------------------------------
63     Implementation:
64     25-05-2003 iButtonLink device
65 */
66 
67 #ifndef OW_H					/* tedious wrapper */
68 #define OW_H
69 
70 #ifndef OWFS_CONFIG_H
71 #error Please make sure owfs_config.h is included *before* this header file
72 #endif
73 
74 // Define this to avoid some VALGRIND warnings... (just for testing)
75 // Warning: This will partially remove the multithreaded support since ow_net.c
76 // will wait for a thread to complete before executing a new one.
77 //#define VALGRIND 1
78 
79 #define _FILE_OFFSET_BITS   64
80 
81 /* For everything */
82 #define _GNU_SOURCE 1
83 
84 #ifdef __FreeBSD__
85 /* from Johan Ström: needed for sys/param.h if sys/types.h sees it */
86 #define __BSD_VISIBLE 1
87 #endif /* __FreeBSD__ */
88 
89 #ifdef __CYGWIN__
90 #define __BSD_VISIBLE 1 /* for strep and u_int */
91 #include <sys/select.h> /* for anything select on newer cygwin */
92 #endif /* __CYGWIN__ */
93 
94 #ifdef HAVE_FEATURES_H
95 #include <features.h>
96 #endif							/* HAVE_FEATURES_H */
97 
98 #ifdef HAVE_FEATURE_TESTS_H
99 #include <feature_tests.h>
100 #endif							/* HAVE_FEATURE_TESTS_H */
101 
102 #ifdef HAVE_SYS_PARAM_H
103 #include <sys/param.h>
104 #endif
105 
106 #ifdef HAVE_SYS_TYPES_H
107 #include <sys/types.h>			/* for stat */
108 #endif							/* HAVE_SYS_TYPES_H */
109 
110 #ifdef HAVE_SYS_TIMES_H
111 #include <sys/times.h>			/* for times */
112 #endif							/* HAVE_SYS_TIMES_H */
113 
114 #include <stdio.h> // for getline
115 
116 #include <ctype.h>
117 #include <stdlib.h>
118 
119 #ifdef HAVE_STRING_H
120 #include <string.h>
121 #endif
122 
123 #ifdef HAVE_STRINGS_H
124 #include <strings.h>			/* for strcasecmp */
125 #endif
126 
127 #include <dirent.h>
128 #include <signal.h>
129 
130 #ifdef HAVE_STDINT_H
131 #include <stdint.h>				/* for bit twiddling */
132 #if OW_CYGWIN
133 #define _MSL_STDINT_H
134 #endif							/* OW_CYGWIN */
135 #endif							/* HAVE_STDINT_H */
136 
137 #include <stdio.h>
138 #include <unistd.h>
139 #include <fcntl.h>
140 
141 #ifndef __USE_XOPEN
142 #define __USE_XOPEN				/* for strptime fuction */
143 #include <time.h>
144 #undef __USE_XOPEN				/* for strptime fuction */
145 #else							/* __USE_XOPEN */
146 #include <time.h>
147 #endif							/* __USE_XOPEN */
148 
149 #ifdef HAVE_TERMIOS_H
150 #include <termios.h>
151 #endif							/* HAVE_TERMIOS_H */
152 
153 #include <errno.h>
154 
155 #ifdef HAVE_SYSLOG_H
156 #include <syslog.h>
157 #endif							/* HAVE_SYSLOG_H */
158 
159 #ifdef HAVE_GETOPT_H
160 #include <getopt.h>				/* for long options */
161 #endif							/* HAVE_GETOPT_H */
162 
163 #ifdef HAVE_SYS_UIO_H
164 #include <sys/uio.h>
165 #endif
166 
167 /* Include gettimeofday and all the timerX macros */
168 #include "ow_timer.h"
169 #define NOW_TIME 	time(NULL)
170 
171 #ifdef HAVE_SYS_STAT_H
172 #include <sys/stat.h>			/* for stat */
173 #endif							/* HAVE_SYS_STAT_H */
174 
175 #ifdef HAVE_SYS_SOCKET_H
176 #include <sys/socket.h>
177 #endif							/* HAVE_SYS_SOCKET_H */
178 
179 #ifdef HAVE_NETINET_IN_H
180 #include <netinet/in.h>
181 #endif							/* HAVE_NETINET_IN_H */
182 
183 #ifndef INET_ADDRSTRLEN
184 #define INET_ADDRSTRLEN 16
185 #endif
186 
187 #ifdef HAVE_NETDB_H
188 #include <netdb.h>				/* for getaddrinfo */
189 #endif							/* HAVE_NETDB_H */
190 
191 /* for major() if sys/types.h is not enough */
192 #ifdef MAJOR_IN_MKDEV
193 #include <sys/mkdev.h>
194 #elif defined MAJOR_IN_SYSMACROS
195 #include <sys/sysmacros.h>
196 #endif
197 
198 #include <stddef.h> // for offsetof()
199 
200 /* Can't include search.h when compiling owperl on Fedora Core 1. */
201 #ifndef SKIP_SEARCH_H
202 #include <search.h>
203 #endif							/* SKIP_SEARCH_H */
204 
205 /* If no getline, use our version */
206 #ifndef HAVE_GETLINE
207 ssize_t getline (char **lineptr, size_t *n, FILE *stream) ;
208 #endif /* HAVE_GETLINE */
209 
210 /* If no timegm, use our version */
211 #if (!defined _BSD_SOURCE && !defined _SVID_SOURCE)
212 #include <time.h>
213 time_t timegm(struct tm *tm);
214 #endif
215 
216 /* Parport enabled uses two flags (one a holdover from the embedded work) */
217 #ifdef USE_NO_PARPORT
218 #undef OW_PARPORT
219 #endif							/* USE_NO_PARPORT */
220 
221 /* Include some compatibility functions */
222 #include "compat.h"
223 
224 /* Debugging and error messages separated out for readability */
225 #include "ow_debug.h"
226 
227 #ifndef PATH_MAX
228 #define PATH_MAX 2048
229 #endif
230 
231 /* Some errnos are not defined for MacOSX and gcc3.3 or openbsd */
232 #ifndef EBADMSG
233 #define EBADMSG ENOMSG
234 #endif							/* EBADMSG */
235 
236 #ifndef EPROTO
237 #define EPROTO EIO
238 #endif							/* EPROTO */
239 
240 #ifndef ENOTSUP
241 #define ENOTSUP EOPNOTSUPP
242 #endif							/* ENOTSUP */
243 
244 /* Bytes in a 1-wire address */
245 #define SERIAL_NUMBER_SIZE           8
246 
247 /* Allocation wrappers for debugging */
248 #include "ow_alloc.h"
249 
250 /* BYTE manipulation macros */
251 #include "ow_bitwork.h"
252 
253 /* Define our understanding of integers, floats, ... */
254 #include "ow_localtypes.h"
255 
256 /* Define our understanding of bus numbers ... */
257 #include "ow_busnumber.h"
258 
259 /* Define our understanding of function returns ... */
260 #include "ow_localreturns.h"
261 
262 /* Define our understanding of file descriptors ... */
263 #include "ow_fd.h"
264 
265 /* Include sone byte conversion convenience routines */
266 #include "ow_integer.h"
267 
268 /* Directory blob separated out for readability */
269 #include "ow_dirblob.h"
270 
271 /* Directory blob (strings) separated out for readability */
272 #include "ow_charblob.h"
273 
274 /* memory blob used for bundled transactions */
275 #include "ow_memblob.h"
276 
277 /* We use our own read-write locks */
278 #include "rwlock.h"
279 /* Many mutexes separated out for readability */
280 #include "ow_mutexes.h"
281 
282 // regular expressions
283 #include "ow_regex.h"
284 
285 /* Special checks for config file changes -- OS specific */
286  #ifdef HAVE_SYS_EVENT_H
287   /* BSD and OSX */
288   #define WE_HAVE_KEVENT
289 #elif defined( HAVE_SYS_INOTIFY_H )
290    #define WE_HAVE_INOTIFY
291 #else /* HAVE_SYS_EVENT_H */
292 	// no change notification available
293    #define Config_Monitor_Add(x)
294    #define Config_Monitor_Watch(v)
295 #endif /* HAVE_SYS_EVENT_H */
296 #include "ow_kevent.h"
297 #include "ow_inotify.h"
298 
299 /* Program startup type */
300 enum  e_inet_type { inet_none, inet_systemd , inet_launchd, } ;
301 
302 #if OW_ZERO
303 /* Zeroconf / Bonjour */
304 #include "ow_dl.h"
305 #include "ow_dnssd.h"
306 #endif							/* OW_ZERO */
307 #include "ow_avahi.h"
308 
309 #if OW_USB
310 #include <libusb.h>
311 #endif /* OW_USB */
312 
313 /*
314     OW -- One Wire
315     Globals variables -- each invokation will have it's own data
316 */
317 
318 /* command line options */
319 #include "ow_opt.h"
320 
321 /* Several different structures:
322   device -- one for each type of 1-wire device
323   filetype -- one for each type of file
324   parsedname -- translates a path into usable form
325 */
326 
327 /* --------------------------------------------------------- */
328 /* Filetypes -- directory entries for each 1-wire chip found */
329 /* predeclare connection_in/out */
330 struct connection_in;
331 struct connection_out;
332 
333 /* Maximum length of a file or directory name, and extension */
334 #define OW_NAME_MAX      (32)
335 #define OW_EXT_MAX       (6)
336 #define OW_FULLNAME_MAX  (OW_NAME_MAX+OW_EXT_MAX)
337 #define OW_DEFAULT_LENGTH (128)
338 
339 #include "ow_filetype.h"
340 /* ------------------------------------------- */
341 
342 /* -------------------------------- */
343 /* Devices -- types of 1-wire chips */
344 /*                                  */
345 #include "ow_device.h"
346 
347 /* Parsedname -- path converted into components */
348 #include "ow_parsedname.h"
349 
350 /* "Object-type" structure for the anctual owfs query --
351   holds name, flags, values, and path */
352 #include "ow_onewirequery.h"
353 
354 /* Delay for clearing buffer */
355 #define    WASTE_TIME    (2)
356 
357 /* device display format */
358 enum deviceformat { fdi, fi, fdidc, fdic, fidc, fic };
359 /* OWSERVER messages */
360 #include "ow_message.h"
361 
362 /* Globals information (for local control) */
363 /* Separated out into ow_global.h for readability */
364 #include "ow_global.h"
365 
366 /* Allow detail debugging of individual slave */
367 #include "ow_detail.h"
368 
369 /* State information for the program */
370 /* Separated out into ow_stateinfo.h for readability */
371 #include "ow_stateinfo.h"
372 
373 /* -------------------------------------------- */
374 /* Prototypes */
375 /* Separated out to ow_functions.h for clarity */
376 #include "ow_arg.h"
377 #include "ow_functions.h"
378 
379 /* Temperature scale handling */
380 #include "ow_temperature.h"
381 
382 /* Pressure scale handling */
383 #include "ow_pressure.h"
384 
385 /* Program control */
386 #include "ow_programs.h"
387 
388 /* Return and error codes */
389 #include "ow_return_code.h"
390 
391 /* Launchd  -- OSX-specific startup code */
392 #include "ow_launchd.h"
393 
394 /* Argument and restart */
395 #include "ow_exec.h"
396 
397 #endif							/* OW_H */
398