+int mISDN_initialize(void)
+{
+ /* try to open raw socket to check kernel */
+ mISDNsocket = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE);
+ if (mISDNsocket < 0)
+ {
+ fprintf(stderr, "Cannot open mISDN due to %s. (Does your Kernel support socket based mISDN?)\n", strerror(errno));
+ return(-1);
+ }
+
+ /* initialize stuff of the NT lib */
+ if (options.deb & DEBUG_STACK)
+ {
+ global_debug = 0xffffffff & ~DBGM_MSG;
+// global_debug = DBGM_L3DATA;
+ } else
+ global_debug = DBGM_MAN;
+ SPRINT(debug_log, "%s/debug.log", INSTALL_DATA);
+ if (options.deb & DEBUG_LOG)
+ mISDN_debug_init(global_debug, debug_log, debug_log, debug_log);
+ else
+ mISDN_debug_init(global_debug, NULL, NULL, NULL);
+
+ /* init mlayer3 */
+ init_layer3(4); // buffer of 4
+
+ return(0);
+}
+
+void mISDN_deinitialize(void)
+{
+ cleanup_layer3();
+
+ mISDN_debug_close();
+
+ if (mISDNsocket > -1)
+ close(mISDNsocket);
+}
+#else
+int entity = 0; /* used for udevice */
+int mISDNdevice = -1; /* the device handler and port list */
+
+int mISDN_initialize(void)
+{
+ char debug_log[128];
+ unsigned char buff[1025];
+ iframe_t *frm = (iframe_t *)buff;
+ int ret;
+
+ /* initialize stuff of the NT lib */
+ if (options.deb & DEBUG_STACK)
+ {
+ global_debug = 0xffffffff & ~DBGM_MSG;
+// global_debug = DBGM_L3DATA;
+ } else
+ global_debug = DBGM_MAN;
+ SPRINT(debug_log, "%s/debug.log", INSTALL_DATA);
+ if (options.deb & DEBUG_LOG)
+ debug_init(global_debug, debug_log, debug_log, debug_log);
+ else
+ debug_init(global_debug, NULL, NULL, NULL);
+ msg_init();
+
+ /* open mISDNdevice if not already open */
+ if (mISDNdevice < 0)
+ {
+ ret = mISDN_open();
+ if (ret < 0)
+ {
+ fprintf(stderr, "cannot open mISDN device ret=%d errno=%d (%s) Check for mISDN modules!\nAlso did you create \"/dev/mISDN\"? Do: \"mknod /dev/mISDN c 46 0\"\n", ret, errno, strerror(errno));
+ return(-1);
+ }
+ mISDNdevice = ret;
+ PDEBUG(DEBUG_ISDN, "mISDN device opened.\n");
+
+ /* create entity for layer 3 TE-mode */
+ mISDN_write_frame(mISDNdevice, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
+ ret = mISDN_read_frame(mISDNdevice, frm, sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC);
+ if (ret < (int)mISDN_HEADER_LEN)
+ {
+ noentity:
+ FATAL("Cannot request MGR_NEWENTITY from mISDN. Exitting due to software bug.");
+ }
+ entity = frm->dinfo & 0xffff;
+ if (!entity)
+ goto noentity;
+ PDEBUG(DEBUG_ISDN, "our entity for l3-processes is %d.\n", entity);
+ }
+ return(0);
+}
+
+void mISDN_deinitialize(void)
+{
+ unsigned char buff[1025];
+
+ debug_close();
+
+ if (mISDNdevice >= 0)
+ {
+ /* free entity */
+ mISDN_write_frame(mISDNdevice, buff, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC);
+ /* close device */
+ mISDN_close(mISDNdevice);
+ mISDNdevice = -1;
+ PDEBUG(DEBUG_ISDN, "mISDN device closed.\n");
+ }
+}
+#endif