diff options
Diffstat (limited to 'mbglib/common/mbgerror.h')
-rw-r--r-- | mbglib/common/mbgerror.h | 326 |
1 files changed, 326 insertions, 0 deletions
diff --git a/mbglib/common/mbgerror.h b/mbglib/common/mbgerror.h new file mode 100644 index 0000000..d8bb5e4 --- /dev/null +++ b/mbglib/common/mbgerror.h @@ -0,0 +1,326 @@ + +/************************************************************************** + * + * $Id: mbgerror.h 1.7.1.6 2015/05/20 12:33:17 martin TEST $ + * + * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany + * + * Description: + * Error codes used with Meinberg devices and drivers. + * The codes can be translated into an OS dependent error code. + * + * ----------------------------------------------------------------------- + * $Log: mbgerror.h $ + * Revision 1.7.1.6 2015/05/20 12:33:17 martin + * Revision 1.7.1.5 2015/05/13 13:53:23 martin + * Revision 1.7.1.4 2014/10/30 11:15:36 martin + * Revision 1.7.1.3 2014/10/28 15:19:17 martin + * Revision 1.7.1.2 2014/09/26 11:45:34Z martin + * Revision 1.7.1.1 2014/06/25 08:52:50 martin + * Re-enabled some symbols which have been commented out.. + * Revision 1.7 2014/05/27 13:32:47Z martin + * Defined additional common error codes which can be + * translated from OS specific codes. + * Function prototypes from new module mbgerror.c. + * Comments in doxygen style. + * Revision 1.6 2012/10/02 18:42:26Z martin + * New codes MBG_ERR_N_POUT_EXCEEDS_SUPP and + * MBG_ERR_N_UC_MSTR_EXCEEDS_SUPP. + * Modified comments for doxygen. + * Revision 1.5 2011/03/31 10:56:17 martin + * Added MBG_ERR_COPY_TO_USER and MBG_ERR_COPY_FROM_USER. + * Revision 1.4 2008/12/05 13:28:50 martin + * Added new code MBG_ERR_IRQ_UNSAFE. + * Revision 1.3 2008/02/26 14:50:14Z daniel + * Added codes: + * MBG_ERR_NOT_SUPP_ON_OS, MBG_ERR_LIB_NOT_COMPATIBLE, + * MBG_ERR_N_COM_EXCEEDS_SUPP, MBG_ERR_N_STR_EXCEEDS_SUPP + * Added doxygen compatible comments. + * Revision 1.2 2007/09/27 07:26:22Z martin + * Define STATUS_SUCCESS for Windows if not in kernel mode. + * Revision 1.1 2007/09/26 08:08:54Z martin + * Initial revision. + * + **************************************************************************/ + +#ifndef _MBGERROR_H +#define _MBGERROR_H + + +/* Other headers to be included */ + +#include <mbg_tgt.h> + +#ifdef _MBGERROR + #define _ext + #define _DO_INIT +#else + #define _ext extern +#endif + + +/* Start of header body */ + +#if !defined( MBG_TGT_WIN32 ) || defined( MBG_TGT_KERNEL ) + //##++++ Surprisingly we need this also for Windows + // in kernel mode. This should be fixed. + #define DWORD uint32_t // just to avoid compiler errors +#endif + + +/** + * @brief Error codes used with Meinberg devices and drivers + * + * Some of the codes have to match codes which are defined in pcpsdefs.h + * and returned by the firmware of bus-level devices. + * + * The codes will be translated into an OS dependent error code + * when returned to the calling function. + * + * For Windows, these codes are made positive and or'ed with 0xE0000000 afterwards. + * + * Example: Code -19 (#MBG_ERR_GENERIC) will be converted to 0xE0000013 under Windows. + * + * @note Attention: + * The error codes below must match exactly the corresponding codes that are evaluated in user space. + * For Windows, they are located in messages.mc/.h in mbgsvctl.dll + * + * @anchor MBG_RETURN_CODES @{ */ + +#define MBG_SUCCESS 0 ///< no error, must match ::PCPS_SUCCESS + + /** @anchor MBG_ERROR_CODES @{ */ + +// Other codes which have to match codes defined in pcpsdefs.h returned by bus-level devices +#define MBG_ERR_STIME -1 ///< invalid date/time/status passed, must match ::PCPS_ERR_STIME +#define MBG_ERR_CFG -2 ///< invalid params with a configuration cmd, must match ::PCPS_ERR_CFG + + +// Codes returned by low level functions of the bus-level device driver +#define MBG_ERR_GENERIC -19 ///< generic error +#define MBG_ERR_TIMEOUT -20 ///< timeout accessing the device +#define MBG_ERR_FW_ID -21 ///< invalid firmware ID +#define MBG_ERR_NBYTES -22 ///< the number of parameter bytes passed to the device did not + ///< match the number of bytes expected by the device + +#define MBG_ERR_INV_TIME -23 ///< the device doesn't have valid time +#define MBG_ERR_FIFO -24 ///< the data FIFO of a bus-level device is empty, though it shouldn't be +#define MBG_ERR_NOT_READY -25 ///< bus-level device is temp. unable to respond e.g. during init. after RESET +#define MBG_ERR_INV_TYPE -26 ///< bus-level device didn't recognize data type + + +// Codes returned by the high level API functions +#define MBG_ERR_NO_MEM -27 ///< failed to allocate memory +#define MBG_ERR_CLAIM_RSRC -28 ///< failed to claim port or mem resource +#define MBG_ERR_DEV_NOT_SUPP -29 ///< specified device type not supported by driver +#define MBG_ERR_INV_DEV_REQUEST -30 ///< IOCTL call not supported by driver +#define MBG_ERR_NOT_SUPP_BY_DEV -31 ///< cmd or feature not supported by device +#define MBG_ERR_USB_ACCESS -32 ///< USB access failed +#define MBG_ERR_CYCLIC_TIMEOUT -33 ///< cyclic event (IRQ, etc.) didn't occur +#define MBG_ERR_NOT_SUPP_ON_OS -34 ///< function is not supported under this operating system +#define MBG_ERR_LIB_NOT_COMPATIBLE -35 ///< installed shared lib. version not compat. with version used at build time +#define MBG_ERR_N_COM_EXCEEDS_SUPP -36 ///< num. COM ports of the device exceeds max. supp. by driver +#define MBG_ERR_N_STR_EXCEEDS_SUPP -37 ///< num. string formats of the device exceeds max. supp. by driver +#define MBG_ERR_IRQ_UNSAFE -38 ///< enabled IRQ of bus-level device is unsafe with this firmware/ASIC version +#define MBG_ERR_N_POUT_EXCEEDS_SUPP -39 ///< num. prog. outputs of the device exceeds max. supp. by driver + +// Legacy codes used with DOS TSRs only: +#define MBG_ERR_INV_INTNO -40 ///< invalid interrupt number +#define MBG_ERR_NO_DRIVER -41 ///< a driver could not be found +#define MBG_ERR_DRV_VERSION -42 ///< the driver is too old + + +#define MBG_ERR_COPY_TO_USER -43 ///< kernel driver failed to copy data from kernel to user space +#define MBG_ERR_COPY_FROM_USER -44 ///< kernel driver failed to copy data from use to kernel space + + +// More codes returned by the driver's high level functions: +#define MBG_ERR_N_UC_MSTR_EXCEEDS_SUPP -45 ///< num. PTP unicast masters of the device exceeds max. supp. by driver +#define MBG_ERR_N_GNSS_EXCEEDS_SUPP -46 ///< num. of GNSS systems supp. by device exceeds max. supp. by driver +#define MBG_ERR_N_GPIO_EXCEEDS_SUPP -47 ///< num. of GPIO ports supp. by device exceeds max. supp. by driver +#define MBG_ERR_N_XMR_EXCEEDS_SUPP -48 ///< num. of XMR sources supp. by device exceeds max. supp. by driver + +#define MBG_ERR_UNSPEC -60 ///< unspecified error + +#define MBG_ERR_HDR_CSUM -61 ///< binary protocol header checksum error +#define MBG_ERR_DATA_CSUM -62 ///< binary protocol data checksum error +#define MBG_ERR_RCVD_NACK -63 ///< binary protocol received reply msg with a NACK code +#define MBG_ERR_RCVD_NO_ACK -64 ///< binary protocol received reply msg without expected ACK code +#define MBG_ERR_CONN_TYPE -65 ///< binary protocol no valid/supported connection type specified +#define MBG_ERR_BYTES_WRITTEN -66 ///< binary protocol failed to write all bytes +#define MBG_ERR_AUTH -67 ///< binary protocol failed authentication + +#define MBG_ERR_SOCK_INIT -68 ///< socket interface not initialized, or failed to initialize +#define MBG_ERR_INV_SOCK_FD -69 ///< invalid socket when tried to open network socket +#define MBG_ERR_NOT_A_SOCKET -70 ///< socket descriptor is not a socket +#define MBG_ERR_NBLOCK_WAIT_SLCT -71 ///< select timed out when waiting for non-blocking network port to become ready +#define MBG_ERR_NBLOCK_WAIT_WR_FD -72 ///< write fd not set after select when waiting for non-blocking network port to become ready + +#define MBG_ERR_IO -73 ///< generic I/O error +#define MBG_ERR_INV_PARM -74 ///< invalid parameter +#define MBG_ERR_NO_DEV -75 ///< specified device not found +#define MBG_ERR_NOT_FOUND -76 ///< specified item not found + +#define MBG_ERR_OVERFLOW -77 ///< buffer overflow +#define MBG_ERR_PIPE -78 ///< pipe error +#define MBG_ERR_INTR -79 ///< interrupted system call +#define MBG_ERR_ACCESS -80 ///< access denied, e.g. when trying to access a device +#define MBG_ERR_PERM -81 ///< operation not permitted, e.g. when trying to set the system time +#define MBG_ERR_BUSY -82 ///< device busy +#define MBG_ERR_INV_HANDLE -83 ///< invalid file/device handle specified + +#define MBG_ERR_XBP_CASC_LVL -84 ///< too many XBP cascading levels +#define MBG_ERR_ENCRYPT -85 ///< encryption failed +#define MBG_ERR_DECRYPT -86 ///< decryption failed + +/** @} anchor MBG_ERROR_CODES */ + +/** @} anchor MBG_RETURN_CODES */ + + + +// Depending on the operating system, the codes above have to be converted before +// they are sent up to user space +#if defined( MBG_TGT_WIN32 ) + #if !defined( STATUS_SUCCESS ) // not in kernel mode + #define STATUS_SUCCESS 0 + #endif + + #define _mbg_err_to_os( _c ) \ + ( ( _c == MBG_SUCCESS ) ? STATUS_SUCCESS : ( abs( _c ) | 0xE0000000 ) ) +#endif + + +// If no specific conversion has been defined +// then use the original codes. +#if !defined( _mbg_err_to_os ) + #define _mbg_err_to_os( _c ) ( _c ) +#endif + + + +/* function prototypes: */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* ----- function prototypes begin ----- */ + +/* This section was generated automatically */ +/* by MAKEHDR, do not remove the comments. */ + + /** + * @brief Translate a Windows non-socket API error code to one of the @ref MBG_ERROR_CODES + * + * @param wsa_err A Windows non-socket API error code as returned by GetLastError() + * @param info An optional informational text string, or NULL + * + * @return One of the @ref MBG_ERROR_CODES + */ + int mbg_win32_last_err_to_mbg( DWORD wsa_err, const char *info ) ; + + /** + * @brief Translate a Windows socket API error code to one of the @ref MBG_ERROR_CODES + * + * @param wsa_err A Windows socket API error code as returned by WSAGetLastError() + * @param info An optional informational text string, or NULL + * + * @return One of the @ref MBG_ERROR_CODES + */ + int mbg_win32_wsa_err_to_mbg( DWORD wsa_err, const char *info ) ; + + /** + * @brief Translate a POSIX errno error code to one of the @ref MBG_ERROR_CODES + * + * @param posix_errno A POSIX error code as usually defined in errno.h + * @param info An optional informational text string, or NULL + * + * @return One of the @ref MBG_ERROR_CODES + */ + int mbg_posix_errno_to_mbg( int posix_errno, const char *info ) ; + + /** + * @brief Translate a POSIX h_errno error code to one of the @ref MBG_ERROR_CODES + * + * This function is specific to translate error codes returned by + * gethostbyname() and gethostbyaddr(). In case of error these functions + * don't set errno but h_errno to a specific value. + * + * The functions gethostbyname() and gethostbyaddr() are obsolete, + * and getaddressinfo() should be used preferably. + * + * @param posix_h_errno An error code as usually defined in netdb.h + * @param info An optional informational text string, or NULL + * + * @return One of the @ref MBG_ERROR_CODES + */ + int mbg_posix_h_errno_to_mbg( int posix_h_errno, const char *info ) ; + + /** + * @brief Get and translate last error after non-socket function call + * + * Retrieve the "last error" code after a non-socket function has been called + * and translate to one of the @ref MBG_ERROR_CODES. + * + * On POSIX systems the "last error" code is always stored in errno, but + * e.g. under Windows the "last error" code after a socket function + * has to be retrieved by calling WSAGetLastError(), whereas the "last error" + * code from non-socket POSIX-like functions has to be retrieved + * by calling GetLastError(). + * + * @param info An optional informational text string, or NULL + * + * @return One of the @ref MBG_ERROR_CODES + */ + int mbg_get_last_error( const char *info ) ; + + /** + * @brief Get and translate last error after socket function call + * + * Retrieve the "last error" code after a socket function has been called + * and translate to one of the @ref MBG_ERROR_CODES. + * + * On POSIX systems the "last error" code is always stored in errno, but + * e.g. under Windows the "last error" code after a socket function + * has to be retrieved by calling WSAGetLastError, whereas the "last error" + * code from non-socket POSIX-like functions is stored in errno as usual. + * + * @param info An optional informational text string, or NULL + * + * @return One of the @ref MBG_ERROR_CODES + */ + int mbg_get_last_socket_error( const char *info ) ; + + /** + * @brief Retrieve and convert last error after gethostbyname() + * + * This function is specific to retrieve and translate error codes + * returned by gethostbyname() and gethostbyaddr(). In case of error + * these functions don't set errno but h_errno on POSIX systems, but + * under Windows the error code can be retrieved by WSAGetLastError() + * as usual. + * + * The functions gethostbyname() and gethostbyaddr() are obsolete, + * and getaddressinfo() should be used preferably. + * + * @param info An optional informational text string, or NULL + * + * @return One of the @ref MBG_ERROR_CODES + */ + int mbg_get_gethostbyname_error( const char *info ) ; + + +/* ----- function prototypes end ----- */ + +#ifdef __cplusplus +} +#endif + + +/* End of header body */ + +#undef _ext +#undef _DO_INIT + +#endif /* _MBGERROR_H */ |