104 #if defined( MBG_TGT_WIN32 ) 106 #if defined( MBG_TGT_KERNEL ) 108 #define MBG_TGT_MISSING_DWORD 1 // missing even in kernel space. 109 #define MBG_TGT_MISSING_NTSTATUS 0 // available in kernel space 111 #else // Windows user space 113 #define MBG_TGT_MISSING_DWORD 0 // available in user space 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 127 #if MBG_TGT_HAS_BCRYPT_H 129 #define MBG_TGT_MISSING_NTSTATUS 0 131 #define MBG_TGT_MISSING_NTSTATUS 1 136 #else // non-Windows targets 138 #define MBG_TGT_MISSING_DWORD 1 139 #define MBG_TGT_MISSING_NTSTATUS 1 158 #if defined( MBG_TGT_WIN32 ) 160 #if defined( MBG_TGT_KERNEL ) 161 #define MBG_SYS_RC_SUCCESS STATUS_SUCCESS 163 #define MBG_SYS_RC_SUCCESS ERROR_SUCCESS 166 #elif defined( MBG_TGT_POSIX ) 168 #define MBG_SYS_RC_SUCCESS 0 172 #define MBG_SYS_RC_SUCCESS 0 177 #if !defined( _USE_WIN32_PRIVATE_STATUS_CODES ) // FIXME 178 #define _USE_WIN32_PRIVATE_STATUS_CODES 0 182 #if defined( MBG_TGT_WIN32 ) 184 #define STATUS_SEVERITY_SUCCESS 0x0 185 #define STATUS_SEVERITY_INFORMATIONAL 0x1 186 #define STATUS_SEVERITY_WARNING 0x2 187 #define STATUS_SEVERITY_ERROR 0x3 189 #define STATUS_SEVERITY_SHIFT_BITS 30 190 #define STATUS_SEVERITY_SHIFT_MASK 0x03 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 ) 197 #define _get_win_msg_severity( _st ) ( ( (_st) >> STATUS_SEVERITY_SHIFT_BITS ) & STATUS_SEVERITY_SHIFT_MASK ) 201 #define STATUS_CUSTOM_FLAG 0x1 203 #define STATUS_CUSTOM_FLAG_SHIFT_BITS 29 204 #define STATUS_CUSTOM_FLAG_SHIFT_MASK 0x01 206 #define STATUS_CUSTOM_FLAG_MASK ( STATUS_CUSTOM_FLAG << STATUS_CUSTOM_FLAG_SHIFT_BITS ) 208 #define _get_win_msg_custom_flag( _st ) ( ( (_st) >> STATUS_CUSTOM_FLAG_SHIFT_BITS ) & STATUS_CUSTOM_FLAG_SHIFT_MASK ) 210 #define _win_msg_is_custom( _st ) ( _get_win_msg_custom_flag( _st ) != 0 ) 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 ) ) 217 #endif // defined( MBG_TGT_WIN32 ) 221 #if MBG_TGT_MISSING_DWORD 226 #if MBG_TGT_MISSING_NTSTATUS 231 #define NTSTATUS NTSTATUS 259 #define MBG_SUCCESS 0 264 #define MBG_ERR_STIME -1 265 #define MBG_ERR_CFG -2 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 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 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 297 #define MBG_ERR_INV_INTNO -40 298 #define MBG_ERR_NO_DRIVER -41 299 #define MBG_ERR_DRV_VERSION -42 302 #define MBG_ERR_COPY_TO_USER -43 303 #define MBG_ERR_COPY_FROM_USER -44 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 312 #define MBG_ERR_UNSPEC -60 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 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 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 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 341 #define MBG_ERR_XBP_CASC_LVL -84 342 #define MBG_ERR_ENCRYPT -85 343 #define MBG_ERR_DECRYPT -86 345 #define MBG_ERR_DISCONN -87 346 #define MBG_ERR_INV_CFG -88 347 #define MBG_ERR_RANGE -89 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 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 361 #define MBG_ERR_NO_SPACE -100 362 #define MBG_ERR_NOT_CONFIGURED -101 363 #define MBG_ERR_INV_IDX -102 365 #define MBG_ERR_PARM_FMT -103 366 #define MBG_ERR_UNKNOWN -104 368 #define MBG_ERR_PAM -105 369 #define MBG_ERR_TIMER -106 371 #define MBG_ERR_AGAIN -107 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 382 #define MBG_ERR_RSRC_ITEM -115 383 #define MBG_ERR_BUFFER_TOO_SMALL -116 385 #define MBG_ERR_OUTDATED -117 387 #define MBG_ERR_STR_SUBSTR -118 388 #define MBG_ERR_BAD_ADDRESS -119 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" }, \ 472 { MBG_ERR_INV_TLV_UID, "MBG_ERR_INV_TLV_UID" }, \ 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" } 512 #if defined( MBG_TGT_DOS ) 514 #define MBG_ERR_STR_TABLE_EXT_ENG \ 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" } 550 #define MBG_ERR_STR_TABLE_ENG \ 552 MBG_ERR_STR_TABLE_BASE_ENG, \ 553 MBG_ERR_STR_TABLE_EXT_ENG, \ 559 #if defined( __mbg_inline ) 617 #define mbg_rc_is_error( _rc ) ( (_rc) < MBG_SUCCESS ) 618 #define mbg_rc_is_success( _rc ) ( !mbg_rc_is_error( _rc ) ) 620 #define mbg_rc_is_success_or_err_perm( _rc ) ( mbg_rc_is_success( _rc ) || ( (_rc) == MBG_ERR_PERM ) ) 836 #if _USE_WIN32_PRIVATE_STATUS_CODES 848 int mbg_ret_val_to_os(
int rc )
854 #endif // _USE_WIN32_PRIVATE_STATUS_CODES 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.
Requested action completed successfully.
#define MBG_SYS_RC_SUCCESS
int mbg_get_last_error(const char *info)
Get and translate last error after non-socket function call.
Unable to handle requested action, usage printed.
#define mbg_rc_is_success(_rc)
int mbg_get_last_socket_error(const char *info)
Get and translate last error after socket function call.
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.
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.
#define mbg_rc_is_success_or_err_perm(_rc)
const char * mbg_strerror(int mbg_errno)
Return an error string associated with the MBG_ERROR_CODES.
Device has no valid time to set the system time with.
int mbg_get_gethostbyname_error(const char *info)
Retrieve and convert last error after gethostbyname()
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.
Requested action not supported on the running OS.
Action failed for specified device.
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...
int mbg_errno_to_os(int err_no)
Convert one of the MBG_ERROR_CODES to an OS-specific format.
#define mbg_rc_is_error(_rc)
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...
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.