mbgtools-lx  4.2.8
mbgerror.h
Go to the documentation of this file.
1 
2 /**************************************************************************
3  *
4  * $Id: mbgerror.h 1.21 2019/03/13 16:17:10 martin REL_M $
5  *
6  * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
7  *
8  * Description:
9  * Error codes used with Meinberg devices and drivers.
10  * The codes can be translated into an OS dependent error code.
11  *
12  * -----------------------------------------------------------------------
13  * $Log: mbgerror.h $
14  * Revision 1.21 2019/03/13 16:17:10 martin
15  * New code MBG_ERR_BAD_ADDRESS (for EFAULT).
16  * Revision 1.20 2019/03/13 09:44:30 martin
17  * Moved predefined program exit codes here.
18  * Revision 1.19 2019/02/08 10:42:56 martin
19  * Distinguish more detailed if an NTSTATUS replacement
20  * is required for a particular build environment.
21  * Revision 1.18 2018/11/22 11:25:56 martin
22  * New error code MBG_ERR_STR_SUBSTR merged from 1.15.1.x branch.
23  * Refactored surrogate definitions.
24  * Updated function prototypes.
25  * Revision 1.17 2018/09/21 09:49:57 martin
26  * Renamed MBG_ERR_FIFO to MBG_ERR_NO_DATA.
27  * Added strings for MBG_ERR_NO_DRIVER and MBG_ERR_DRV_VERSION.
28  * New code MBG_ERR_BUFFER_TOO_SMALL.
29  * MBG_ERR_OUTDATED error code added by philipp.
30  * Added some Windows stuff.
31  * Updated function prototypes.
32  * Revision 1.16 2018/06/25 14:26:38Z martin
33  * Some new error codes were introduced.
34  * New macro mbg_rc_is_success_or_err_perm().
35  * New control macro _USE_WIN32_PRIVATE_STATUS_CODES.
36  * Split table initializers for error strings into two
37  * separate initializers to avoid overhead on target
38  * systems which don't support extended functions.
39  * Updated comments, string tables, and function prototypes.
40  * Revision 1.15 2017/07/05 09:27:25 martin
41  * New error code MBG_ERR_PARM_FMT.
42  * Changed message text for MBG_ERR_NO_ENTITY.
43  * Replaced old _mbg_err_to_os() macro by new inline functions
44  * mbg_errno_to_os() and mbg_ret_val_to_os().
45  * Fixed build under Windows.
46  * Updated doxygen comments.
47  * Updated function prototypes.
48  * Revision 1.14 2017/05/10 15:21:39 martin
49  * Tiny cleanup.
50  * Revision 1.13 2017/02/28 15:23:14 gregoire
51  * error code MBG_ERR_INV_IDX added
52  * Revision 1.12 2017/01/10 15:54:56 philipp
53  * Fixed syntax error
54  * Revision 1.11 2017/01/10 14:26:31 philipp
55  * Added error MBG_ERR_NOT_CONFIGURED
56  * Revision 1.10 2016/12/16 12:40:33 thomas-b
57  * Added MBG_ERR_NO_SPACE
58  * Revision 1.9 2016/10/31 17:41:55 martin
59  * New error code MBG_ERR_DATA_FMT.
60  * Revision 1.8 2016/08/05 12:29:20 martin
61  * Re-enabled some symbols which have been commented out.
62  * Added new codes, and initializers for code/string conversion tables.
63  * Updated doxygen comments.
64  * Updated function prorotypes.
65  * Revision 1.7 2014/05/27 13:32:47Z martin
66  * Defined additional common error codes which can be
67  * translated from OS specific codes.
68  * Function prototypes from new module mbgerror.c.
69  * Comments in doxygen style.
70  * Revision 1.6 2012/10/02 18:42:26Z martin
71  * New codes MBG_ERR_N_POUT_EXCEEDS_SUPP and
72  * MBG_ERR_N_UC_MSTR_EXCEEDS_SUPP.
73  * Modified comments for doxygen.
74  * Revision 1.5 2011/03/31 10:56:17 martin
75  * Added MBG_ERR_COPY_TO_USER and MBG_ERR_COPY_FROM_USER.
76  * Revision 1.4 2008/12/05 13:28:50 martin
77  * Added new code MBG_ERR_IRQ_UNSAFE.
78  * Revision 1.3 2008/02/26 14:50:14Z daniel
79  * Added codes:
80  * MBG_ERR_NOT_SUPP_ON_OS, MBG_ERR_LIB_NOT_COMPATIBLE,
81  * MBG_ERR_N_COM_EXCEEDS_SUPP, MBG_ERR_N_STR_EXCEEDS_SUPP
82  * Added doxygen compatible comments.
83  * Revision 1.2 2007/09/27 07:26:22Z martin
84  * Define STATUS_SUCCESS for Windows if not in kernel mode.
85  * Revision 1.1 2007/09/26 08:08:54Z martin
86  * Initial revision.
87  *
88  **************************************************************************/
89 
90 #ifndef _MBGERROR_H
91 #define _MBGERROR_H
92 
93 
94 /* Other headers to be included */
95 
96 #include <mbg_tgt.h>
97 #include <words.h>
98 
99 // We may need surrogate declarations for target-specific
100 // types that are used in common function prototypes.
101 // Without such declarations we'd get compiler errors
102 // on targets that don't have them.
103 
104 #if defined( MBG_TGT_WIN32 )
105 
106  #if defined( MBG_TGT_KERNEL )
107 
108  #define MBG_TGT_MISSING_DWORD 1 // missing even in kernel space.
109  #define MBG_TGT_MISSING_NTSTATUS 0 // available in kernel space
110 
111  #else // Windows user space
112 
113  #define MBG_TGT_MISSING_DWORD 0 // available in user space
114 
115  // Some (but not all) Windows build environments provide a
116  // bcrypt.h file which has a definition for NTSTATUS, so we
117  // use.that if available to avoid duplicate / mismatching
118  // definitions in case an application uses bcrypt.h anyway.
119  #if !defined( MBG_TGT_HAS_BCRYPT_H ) // unless already defined elsewhere
120  #if defined( _MSC_VER ) && ( _MSC_VER >= 1500 ) // at least VS2008 has it
121  #define MBG_TGT_HAS_BCRYPT_H 1
122  #else // older MSVC versions or other build environments may not have it
123  #define MBG_TGT_HAS_BCRYPT_H 0
124  #endif
125  #endif
126 
127  #if MBG_TGT_HAS_BCRYPT_H
128  #include <bcrypt.h>
129  #define MBG_TGT_MISSING_NTSTATUS 0
130  #else
131  #define MBG_TGT_MISSING_NTSTATUS 1
132  #endif
133 
134  #endif
135 
136 #else // non-Windows targets
137 
138  #define MBG_TGT_MISSING_DWORD 1
139  #define MBG_TGT_MISSING_NTSTATUS 1
140 
141 #endif
142 
143 
144 #ifdef _MBGERROR
145  #define _ext
146  #define _DO_INIT
147 #else
148  #define _ext extern
149 #endif
150 
151 
152 /* Start of header body */
153 
154 #ifdef __cplusplus
155 extern "C" {
156 #endif
157 
158 #if defined( MBG_TGT_WIN32 )
159 
160  #if defined( MBG_TGT_KERNEL )
161  #define MBG_SYS_RC_SUCCESS STATUS_SUCCESS
162  #else
163  #define MBG_SYS_RC_SUCCESS ERROR_SUCCESS
164  #endif
165 
166 #elif defined( MBG_TGT_POSIX )
167 
168  #define MBG_SYS_RC_SUCCESS 0
169 
170 #else
171 
172  #define MBG_SYS_RC_SUCCESS 0
173 
174 #endif
175 
176 
177 #if !defined( _USE_WIN32_PRIVATE_STATUS_CODES ) // FIXME
178  #define _USE_WIN32_PRIVATE_STATUS_CODES 0
179 #endif
180 
181 
182 #if defined( MBG_TGT_WIN32 )
183 
184 #define STATUS_SEVERITY_SUCCESS 0x0
185 #define STATUS_SEVERITY_INFORMATIONAL 0x1
186 #define STATUS_SEVERITY_WARNING 0x2
187 #define STATUS_SEVERITY_ERROR 0x3
188 
189 #define STATUS_SEVERITY_SHIFT_BITS 30
190 #define STATUS_SEVERITY_SHIFT_MASK 0x03
191 
192 #define STATUS_SEVERITY_SUCCESS_MASK ( STATUS_SEVERITY_SUCCESS << STATUS_SEVERITY_SHIFT_BITS )
193 #define STATUS_SEVERITY_INFORMATIONAL_MASK ( STATUS_SEVERITY_INFORMATIONAL << STATUS_SEVERITY_SHIFT_BITS )
194 #define STATUS_SEVERITY_WARNING_MASK ( STATUS_SEVERITY_WARNING << STATUS_SEVERITY_SHIFT_BITS )
195 #define STATUS_SEVERITY_ERROR_MASK ( STATUS_SEVERITY_ERROR << STATUS_SEVERITY_SHIFT_BITS )
196 
197 #define _get_win_msg_severity( _st ) ( ( (_st) >> STATUS_SEVERITY_SHIFT_BITS ) & STATUS_SEVERITY_SHIFT_MASK )
198 
199 
200 
201 #define STATUS_CUSTOM_FLAG 0x1
202 
203 #define STATUS_CUSTOM_FLAG_SHIFT_BITS 29
204 #define STATUS_CUSTOM_FLAG_SHIFT_MASK 0x01
205 
206 #define STATUS_CUSTOM_FLAG_MASK ( STATUS_CUSTOM_FLAG << STATUS_CUSTOM_FLAG_SHIFT_BITS )
207 
208 #define _get_win_msg_custom_flag( _st ) ( ( (_st) >> STATUS_CUSTOM_FLAG_SHIFT_BITS ) & STATUS_CUSTOM_FLAG_SHIFT_MASK )
209 
210 #define _win_msg_is_custom( _st ) ( _get_win_msg_custom_flag( _st ) != 0 )
211 
212 
213 #define _mbg_msg_id_inf( num ) ((DWORD) ( STATUS_SEVERITY_INFORMATIONAL_MASK | STATUS_CUSTOM_FLAG_MASK | num ) )
214 #define _mbg_msg_id_wrn( num ) ((DWORD) ( STATUS_SEVERITY_WARNING_MASK | STATUS_CUSTOM_FLAG_MASK | num ) )
215 #define _mbg_msg_id_err( num ) ((DWORD) ( STATUS_SEVERITY_ERROR_MASK | STATUS_CUSTOM_FLAG_MASK | num ) )
216 
217 #endif // defined( MBG_TGT_WIN32 )
218 
219 
220 
221 #if MBG_TGT_MISSING_DWORD
222  typedef uint32_t DWORD;
223  #define DWORD DWORD
224 #endif
225 
226 #if MBG_TGT_MISSING_NTSTATUS
227  // We intentionally define an uncommon type to
228  // enforce build errors in case NTSTATUS is really
229  // used on targets that should not use it.
230  typedef int *NTSTATUS;
231  #define NTSTATUS NTSTATUS
232 #endif
233 
234 
235 
245 /* ### TODO FIXME
246  * Under Windows, some message strings are provided as resources appended
247  * to the mbgctrl DLL, but the codes specified here have to be translated
248  * to Windows-specific message IDs before the appropriate resource string
249  * can be retrieved. Actually this is done by taking the absolute number
250  * of an error code and have it or'ed with 0xE0000000 afterwards, e.g.
251  * ::MBG_ERR_GENERIC (-19) will yield Windows code 0xE0000013.
252  * * See ::_mbg_err_to_os
253  */
254 
255 // NOTE: Some of these codes have to match codes which are defined in pcpsdefs.h
256 // and returned by the firmware of bus-level devices, so the definitions
257 // must *not* be renumbered.
258 
259 #define MBG_SUCCESS 0
260 
261 
263 // Other codes which have to match codes defined in pcpsdefs.h returned by bus-level devices
264 #define MBG_ERR_STIME -1
265 #define MBG_ERR_CFG -2
266 
267 
268 // Codes returned by low level functions of the bus-level device driver
269 #define MBG_ERR_GENERIC -19
270 #define MBG_ERR_TIMEOUT -20
271 #define MBG_ERR_FW_ID -21
272 #define MBG_ERR_NBYTES -22
273 
275 #define MBG_ERR_INV_TIME -23
276 #define MBG_ERR_NO_DATA -24
277 #define MBG_ERR_NOT_READY -25
278 #define MBG_ERR_INV_TYPE -26
279 
280 
281 // Codes returned by the high level API functions
282 #define MBG_ERR_NO_MEM -27
283 #define MBG_ERR_CLAIM_RSRC -28
284 #define MBG_ERR_DEV_NOT_SUPP -29
285 #define MBG_ERR_INV_DEV_REQUEST -30
286 #define MBG_ERR_NOT_SUPP_BY_DEV -31
287 // #define MBG_ERR_USB_ACCESS -32
288 #define MBG_ERR_CYCLIC_TIMEOUT -33
289 #define MBG_ERR_NOT_SUPP_ON_OS -34
290 #define MBG_ERR_LIB_NOT_COMPATIBLE -35
291 #define MBG_ERR_N_COM_EXCEEDS_SUPP -36
292 #define MBG_ERR_N_STR_EXCEEDS_SUPP -37
293 #define MBG_ERR_IRQ_UNSAFE -38
294 #define MBG_ERR_N_POUT_EXCEEDS_SUPP -39
295 
296 // Legacy codes used with DOS TSRs only:
297 #define MBG_ERR_INV_INTNO -40
298 #define MBG_ERR_NO_DRIVER -41
299 #define MBG_ERR_DRV_VERSION -42
300 
301 
302 #define MBG_ERR_COPY_TO_USER -43
303 #define MBG_ERR_COPY_FROM_USER -44
304 
305 
306 // More codes returned by the driver's high level functions:
307 #define MBG_ERR_N_UC_MSTR_EXCEEDS_SUPP -45
308 #define MBG_ERR_N_GNSS_EXCEEDS_SUPP -46
309 #define MBG_ERR_N_GPIO_EXCEEDS_SUPP -47
310 #define MBG_ERR_N_XMR_EXCEEDS_SUPP -48
311 
312 #define MBG_ERR_UNSPEC -60
313 
314 #define MBG_ERR_HDR_CSUM -61
315 #define MBG_ERR_DATA_CSUM -62
316 #define MBG_ERR_RCVD_NACK -63
317 #define MBG_ERR_RCVD_NO_ACK -64
318 #define MBG_ERR_CONN_TYPE -65
319 #define MBG_ERR_BYTES_WRITTEN -66
320 #define MBG_ERR_AUTH -67
321 
322 #define MBG_ERR_SOCK_INIT -68
323 #define MBG_ERR_INV_SOCK_FD -69
324 #define MBG_ERR_NOT_A_SOCKET -70
325 #define MBG_ERR_NBLOCK_WAIT_SLCT -71
326 #define MBG_ERR_NBLOCK_WAIT_WR_FD -72
327 
328 #define MBG_ERR_IO -73
329 #define MBG_ERR_INV_PARM -74
330 #define MBG_ERR_NO_DEV -75
331 #define MBG_ERR_NOT_FOUND -76
332 
333 #define MBG_ERR_OVERFLOW -77
334 #define MBG_ERR_PIPE -78
335 #define MBG_ERR_INTR -79
336 #define MBG_ERR_ACCESS -80
337 #define MBG_ERR_PERM -81
338 #define MBG_ERR_BUSY -82
339 #define MBG_ERR_INV_HANDLE -83
340 
341 #define MBG_ERR_XBP_CASC_LVL -84
342 #define MBG_ERR_ENCRYPT -85
343 #define MBG_ERR_DECRYPT -86
344 
345 #define MBG_ERR_DISCONN -87
346 #define MBG_ERR_INV_CFG -88
347 #define MBG_ERR_RANGE -89
348 
349 #define MBG_ERR_INV_TLV_ANN_BYTES -90
350 #define MBG_ERR_INV_TLV_SIZE -91
351 #define MBG_ERR_INV_TLV_UID -92
352 
353 #define MBG_ERR_EXIST -93
354 #define MBG_ERR_DATA_SIZE -94
355 #define MBG_ERR_NO_ENTITY -95
356 #define MBG_ERR_ALREADY_ALLOC -96
357 #define MBG_ERR_HOST_NOT_FOUND -97
358 #define MBG_ERR_CONN_RESET -98
359 #define MBG_ERR_DATA_FMT -99
360 
361 #define MBG_ERR_NO_SPACE -100
362 #define MBG_ERR_NOT_CONFIGURED -101
363 #define MBG_ERR_INV_IDX -102
364 
365 #define MBG_ERR_PARM_FMT -103
366 #define MBG_ERR_UNKNOWN -104
367 
368 #define MBG_ERR_PAM -105
369 #define MBG_ERR_TIMER -106
370 
371 #define MBG_ERR_AGAIN -107
372 
374 #define MBG_ERR_STR_CHAR -108
375 #define MBG_ERR_STR_LEN -109
376 #define MBG_ERR_SN_GCODE_LEN -110
377 #define MBG_ERR_SN_GCODE_UNKN -111
378 #define MBG_ERR_SN_GCODE_WRONG -112
379 #define MBG_ERR_SN_LEN -113
380 #define MBG_ERR_SN_VRFY -114
381 
382 #define MBG_ERR_RSRC_ITEM -115
383 #define MBG_ERR_BUFFER_TOO_SMALL -116
384 
385 #define MBG_ERR_OUTDATED -117
386 
387 #define MBG_ERR_STR_SUBSTR -118
388 #define MBG_ERR_BAD_ADDRESS -119
389 
390 // NOTE: New codes have to be appended to this list, and the sequence of codes must not
391 // be changed. Whenever new codes have been defined, appropriate entries have to be added
392 // to the ::MBG_ERR_STR_TABLE_ENG table initializer below, and the Windows-specific message
393 // texts specified in messages.mc/.h from which the resources appended to mbgsvctl.dll
394 // are generated have to be updated accordingly.
395 
419 #define MBG_ERR_STR_TABLE_BASE_ENG \
420  { MBG_SUCCESS, "Success" }, \
421  { MBG_ERR_STIME, "Invalid date/time for device" }, \
422  { MBG_ERR_CFG, "Invalid configuration parameters for device" }, \
423  { MBG_ERR_GENERIC, "Generic error" }, \
424  { MBG_ERR_TIMEOUT, "Timeout" }, \
425  { MBG_ERR_FW_ID, "Invalid firmware ID" }, \
426  { MBG_ERR_NBYTES, "Unexpected number of data bytes for this API" }, \
427  { MBG_ERR_INV_TIME, "The device has no valid time" }, \
428  { MBG_ERR_NO_DATA, "The device's data buffer unexpectedly empty" }, \
429  { MBG_ERR_NOT_READY, "Device not ready" }, \
430  { MBG_ERR_INV_TYPE, "Unsupported data type" }, \
431  { MBG_ERR_NO_MEM, "Memory allocation error" }, \
432  { MBG_ERR_CLAIM_RSRC, "Faild to claim resources" }, \
433  { MBG_ERR_DEV_NOT_SUPP, "Device not supported" }, \
434  { MBG_ERR_INV_DEV_REQUEST, "Request not supported" }, \
435  { MBG_ERR_NOT_SUPP_BY_DEV, "Not supported by device" }, \
436  { MBG_ERR_CYCLIC_TIMEOUT, "Cyclic message timeout" }, \
437  { MBG_ERR_NOT_SUPP_ON_OS, "Not supported by OS" }, \
438  { MBG_ERR_LIB_NOT_COMPATIBLE, "Shared lib not compatible" }, \
439  { MBG_ERR_N_COM_EXCEEDS_SUPP, "Num. COM ports exceeds supported" }, \
440  { MBG_ERR_N_STR_EXCEEDS_SUPP, "Num. string formats exceeds supported" }, \
441  { MBG_ERR_IRQ_UNSAFE, "Unsafe IRQ support" }, \
442  { MBG_ERR_N_POUT_EXCEEDS_SUPP, "Num prog. outputs exceeds supported" }, \
443  { MBG_ERR_INV_INTNO, "Invalid interrupt number" }, \
444  { MBG_ERR_NO_DRIVER, "Driver not found" }, \
445  { MBG_ERR_DRV_VERSION, "Driver too old" }, \
446  { MBG_ERR_N_UC_MSTR_EXCEEDS_SUPP, "Num. PTP Unicast masters exceeds supported" }, \
447  { MBG_ERR_N_GNSS_EXCEEDS_SUPP, "Num. GNSS systems exceeds supported" }, \
448  { MBG_ERR_N_GPIO_EXCEEDS_SUPP, "Num. GPIO ports exceeds supported" }, \
449  { MBG_ERR_N_XMR_EXCEEDS_SUPP, "Num. XMR sources exceeds supported" }, \
450  { MBG_ERR_UNSPEC, "Unspecified error" }, \
451  { MBG_ERR_HDR_CSUM, "Header checksum error" }, \
452  { MBG_ERR_DATA_CSUM, "Data checksum error" }, \
453  { MBG_ERR_RCVD_NACK, "Received NACK message" }, \
454  { MBG_ERR_RCVD_NO_ACK, "Didn't receive ACK message" }, \
455  { MBG_ERR_CONN_TYPE, "Invalid I/O connection type" }, \
456  { MBG_ERR_BYTES_WRITTEN, "Failed to write all bytes" }, \
457  { MBG_ERR_IO, "Input/output error" }, \
458  { MBG_ERR_INV_PARM, "Invalid parameter passed to function" }, \
459  { MBG_ERR_NO_DEV, "No such device, or attempted an inappropriate function." }, \
460  { MBG_ERR_NOT_FOUND, "Specified item not found" }, \
461  { MBG_ERR_OVERFLOW, "Buffer overflow" }, \
462  { MBG_ERR_BUSY, "Device busy" }, \
463  { MBG_ERR_INV_HANDLE, "Invalid handle" }, \
464  { MBG_ERR_XBP_CASC_LVL, "Too many XBP cascading levels" }, \
465  { MBG_ERR_ENCRYPT, "Encryption failed" }, \
466  { MBG_ERR_DECRYPT, "Decryption failed" }, \
467  { MBG_ERR_DISCONN, "Connection closed by remote site/host" }, \
468  { MBG_ERR_INV_CFG, "Invalid/inconsistent configuration read from device" }, \
469  { MBG_ERR_RANGE, "Input parameter was out of range" }, \
470  { MBG_ERR_INV_TLV_ANN_BYTES, "TLV num of transferred bytes differs from num of announced bytes" }, \
471  { MBG_ERR_INV_TLV_SIZE, "MBG_ERR_INV_TLV_SIZE" }, /* ### TODO */ \
472  { MBG_ERR_INV_TLV_UID, "MBG_ERR_INV_TLV_UID" }, /* ### TODO */ \
473  { MBG_ERR_DATA_SIZE, "Received data size mismatch" }, \
474  { MBG_ERR_ALREADY_ALLOC, "Memory already allocated" }, \
475  { MBG_ERR_DATA_FMT, "Invalid data format" }, \
476  { MBG_ERR_NOT_CONFIGURED, "Configuration is not active and/or configured" }, \
477  { MBG_ERR_INV_IDX, "Invalid or unsupported index value used"}, \
478  { MBG_ERR_PARM_FMT, "Parameter string format error" }, \
479  { MBG_ERR_UNKNOWN, "Unknown error code from external API" }, \
480  { MBG_ERR_PAM, "PAM authentication error" }, \
481  { MBG_ERR_TIMER, "Timer expired" }, \
482  { MBG_ERR_AGAIN, "Try again (later)" }, \
483  { MBG_ERR_STR_CHAR, "Invalid character in string" }, \
484  { MBG_ERR_STR_LEN, "Wrong string length" }, \
485  { MBG_ERR_SN_GCODE_LEN, "Invalid device group code length" }, \
486  { MBG_ERR_SN_GCODE_UNKN, "Unknown device group code" }, \
487  { MBG_ERR_SN_GCODE_WRONG, "Wrong device group code in S/N" }, \
488  { MBG_ERR_SN_VRFY, "Serial number could not be verified" }, \
489  { MBG_ERR_RSRC_ITEM, "Too many resource items" }, \
490  { MBG_ERR_BUFFER_TOO_SMALL, "Data buffer too small" }, \
491  { MBG_ERR_OUTDATED, "Software/Module is too old/outdated. Please update!" }, \
492  { MBG_ERR_STR_SUBSTR, "Invalid substring in string" }
493 
494 
512 #if defined( MBG_TGT_DOS )
513 
514 #define MBG_ERR_STR_TABLE_EXT_ENG \
515  { 0, NULL }
516 
517 #else
518 
519 #define MBG_ERR_STR_TABLE_EXT_ENG \
520  { MBG_ERR_COPY_TO_USER, "Error copying to user space" }, \
521  { MBG_ERR_COPY_FROM_USER, "Error copying from user space" }, \
522  { MBG_ERR_AUTH, "Authentication failed" }, \
523  { MBG_ERR_SOCK_INIT, "Failed to initialize socket" }, \
524  { MBG_ERR_INV_SOCK_FD, "Invalid socket descriptor" }, \
525  { MBG_ERR_NOT_A_SOCKET, "Not a socket descriptor" }, \
526  { MBG_ERR_NBLOCK_WAIT_SLCT, "Select timed out waiting for port ready" }, \
527  { MBG_ERR_NBLOCK_WAIT_WR_FD, "Write file descriptor not ready after waiting for port ready" }, \
528  { MBG_ERR_PIPE, "Pipe error" }, \
529  { MBG_ERR_INTR, "Interrupted function call" }, \
530  { MBG_ERR_ACCESS, "Access denied, insufficient permission" }, \
531  { MBG_ERR_PERM, "Operation not permitted, insufficient rights" }, \
532  { MBG_ERR_EXIST, "File exists" }, \
533  { MBG_ERR_NO_ENTITY, "No such file or directory" }, \
534  { MBG_ERR_HOST_NOT_FOUND, "Host not found" }, \
535  { MBG_ERR_CONN_RESET, "Connection reset by peer" }, \
536  { MBG_ERR_NO_SPACE, "Insufficient disk space" }, \
537  { MBG_ERR_PAM, "PAM authentication was not successful" }, \
538  { MBG_ERR_TIMER, "Timer expired" }, \
539  { MBG_ERR_BAD_ADDRESS, "Bad Address" }
540 
541 #endif
542 
543 
544 
550 #define MBG_ERR_STR_TABLE_ENG \
551 { \
552  MBG_ERR_STR_TABLE_BASE_ENG, \
553  MBG_ERR_STR_TABLE_EXT_ENG, \
554  { 0, NULL } /* end of table */ \
555 }
556 
557 
558 
559 #if defined( __mbg_inline )
560 
561 static __mbg_inline
570 bool mbg_rc_is_error( int rc )
571 {
572  // MBG_SUCCESS is 0, and all Meinberg error codes are < 0.
573  return rc < MBG_SUCCESS;
574 
575 } // mbg_rc_is_error
576 
577 
578 
579 static __mbg_inline
588 bool mbg_rc_is_success( int rc )
589 {
590  // There are functions which don't only return MBG_SUCCESS
591  // on success but some arbitrary positive number, e.g. the
592  // number of bytes sent. So success just means "not an error".
593  return !mbg_rc_is_error( rc );
594 
595 } // mbg_rc_is_success
596 
597 
598 
599 static __mbg_inline
608 bool mbg_rc_is_success_or_err_perm( int rc )
609 {
610  return mbg_rc_is_success( rc ) || ( rc == MBG_ERR_PERM );
611 
612 } // mbg_rc_is_success_or_err_perm
613 
614 
615 #else
616 
617  #define mbg_rc_is_error( _rc ) ( (_rc) < MBG_SUCCESS )
618  #define mbg_rc_is_success( _rc ) ( !mbg_rc_is_error( _rc ) )
619 
620  #define mbg_rc_is_success_or_err_perm( _rc ) ( mbg_rc_is_success( _rc ) || ( (_rc) == MBG_ERR_PERM ) )
621 
622 #endif
623 
624 
625 
630 {
637 };
638 
639 
640 
641 /* ----- function prototypes begin ----- */
642 
643 /* This section was generated automatically */
644 /* by MAKEHDR, do not remove the comments. */
645 
655  int mbg_errno_to_os( int err_no ) ;
656 
664  const char *mbg_strerror( int mbg_errno ) ;
665 
674  bool mbg_cond_err_msg( int rc, const char *what ) ;
675 
695  bool mbg_cond_err_msg_info( int rc, const char *what, const char *info ) ;
696 
707  int mbg_cvi_rs232_error_to_mbg( int cvi_rc, const char *info ) ;
708 
717  int mbg_win32_ntstatus_to_mbg( NTSTATUS st, const char *info ) ;
718 
727  int mbg_win32_sys_err_to_mbg( DWORD win32_sys_rc, const char *info ) ;
728 
737  int mbg_win32_wsa_err_to_mbg( int wsa_err, const char *info ) ;
738 
747  int mbg_posix_errno_to_mbg( int posix_errno, const char *info ) ;
748 
764  int mbg_posix_h_errno_to_mbg( int posix_h_errno, const char *info ) ;
765 
782  int mbg_get_last_error( const char *info ) ;
783 
799  int mbg_get_last_socket_error( const char *info ) ;
800 
817  int mbg_get_gethostbyname_error( const char *info ) ;
818 
829  int mbg_zlib_error_to_mbg( int zlib_error, const char *info, const char *msg ) ;
830 
831 
832 /* ----- function prototypes end ----- */
833 
834 
835 
836 #if _USE_WIN32_PRIVATE_STATUS_CODES
837 
838 static __mbg_inline /*HDR*/
848 int mbg_ret_val_to_os( int rc )
849 {
851 
852 } // mbg_ret_val_to_os
853 
854 #endif // _USE_WIN32_PRIVATE_STATUS_CODES
855 
856 
857 #ifdef __cplusplus
858 }
859 #endif
860 
861 
862 /* End of header body */
863 
864 #undef _ext
865 #undef _DO_INIT
866 
867 #endif /* _MBGERROR_H */
int mbg_win32_ntstatus_to_mbg(NTSTATUS st, const char *info)
Translate a Windows NTSTATUS code to one of the MBG_ERROR_CODES.
bool mbg_cond_err_msg(int rc, const char *what)
Check if a value is an error code and print an associated error message.
Definition: mbgerror.c:714
Requested action completed successfully.
Definition: mbgerror.h:631
#define MBG_SYS_RC_SUCCESS
Definition: mbgerror.h:168
int mbg_get_last_error(const char *info)
Get and translate last error after non-socket function call.
Definition: mbgerror.c:993
Unable to handle requested action, usage printed.
Definition: mbgerror.h:632
#define mbg_rc_is_success(_rc)
Definition: mbgerror.h:618
int mbg_get_last_socket_error(const char *info)
Get and translate last error after socket function call.
Definition: mbgerror.c:1038
int mbg_posix_errno_to_mbg(int posix_errno, const char *info)
Translate a POSIX errno error code to one of the MBG_ERROR_CODES.
Definition: mbgerror.c:920
int mbg_win32_wsa_err_to_mbg(int wsa_err, const char *info)
Translate a Windows socket API error code to one of the MBG_ERROR_CODES.
int mbg_posix_h_errno_to_mbg(int posix_h_errno, const char *info)
Translate a POSIX h_errno error code to one of the MBG_ERROR_CODES.
Definition: mbgerror.c:956
#define mbg_rc_is_success_or_err_perm(_rc)
Definition: mbgerror.h:620
#define NTSTATUS
Definition: mbgerror.h:231
const char * mbg_strerror(int mbg_errno)
Return an error string associated with the MBG_ERROR_CODES.
Definition: mbgerror.c:685
Device has no valid time to set the system time with.
Definition: mbgerror.h:635
int mbg_get_gethostbyname_error(const char *info)
Retrieve and convert last error after gethostbyname()
Definition: mbgerror.c:1090
int mbg_zlib_error_to_mbg(int zlib_error, const char *info, const char *msg)
Retrieve and convert last zlib internal error code.
#define MBG_SUCCESS
Error codes used with Meinberg devices and drivers.
Definition: mbgerror.h:259
Requested action not supported on the running OS.
Definition: mbgerror.h:633
Action failed for specified device.
Definition: mbgerror.h:634
int mbg_win32_sys_err_to_mbg(DWORD win32_sys_rc, const char *info)
Translate a Windows non-socket API return code to one of the MBG_RETURN_CODES.
#define MBG_ERR_PERM
Operation not permitted, e.g. when trying to set the system time without sufficient permissions...
Definition: mbgerror.h:337
#define DWORD
Definition: mbgerror.h:223
int mbg_errno_to_os(int err_no)
Convert one of the MBG_ERROR_CODES to an OS-specific format.
Definition: mbgerror.c:626
#define mbg_rc_is_error(_rc)
Definition: mbgerror.h:617
bool mbg_cond_err_msg_info(int rc, const char *what, const char *info)
Check if a value is an general or a "not supported" error code and print an associated message...
Definition: mbgerror.c:742
int mbg_cvi_rs232_error_to_mbg(int cvi_rc, const char *info)
Translate an error code from the Labwindows/CVI RS-232 library to one of the MBG_ERROR_CODES.
MBG_EXIT_CODES
Predefined exit codes returned by some tools.
Definition: mbgerror.h:629