00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <errno.h>
00026 #include <limits.h>
00027 #include <pthread.h>
00028
00029 #include <unistd.h>
00030 #include <sys/types.h>
00031 #include <sys/stat.h>
00032 #include <sys/ioctl.h>
00033 #include <fcntl.h>
00034
00035 #include <most-netservice.h>
00036
00037 #include "adjust.h"
00038 #include "mostdef1.h"
00039 #include "mostns1.h"
00040 #include "mostnetsdll.h"
00041
00042 #include "global.h"
00043 #include "service.h"
00044
00045
00046 int g_control_fd;
00047
00048
00049 pthread_mutex_t g_nets_mutex = PTHREAD_MUTEX_INITIALIZER;
00050
00054 #define NETSERVICE_DEVICE_FILE "/dev/mostnets%d"
00055
00056
00057 short OpenNetServices(void)
00058 {
00059 char buffer[PATH_MAX];
00060
00061 PRINT_TRACE();
00062
00063
00064 snprintf(buffer, PATH_MAX, NETSERVICE_DEVICE_FILE, InstID);
00065 g_control_fd = open(buffer, O_RDWR);
00066 if (g_control_fd < 0) {
00067 PERR_DEBUG("Failed to open control driver");
00068 return E_OPEN_DRIVER;
00069 }
00070
00071
00072 InitNetServices();
00073
00074
00075
00076
00077
00078 service_thread_init();
00079
00080 PRINT_TRACE("fd = %d", g_control_fd);
00081
00082 return E_SUCCESS;
00083 }
00084
00085
00086 void CloseNetServices(void)
00087 {
00088 PRINT_TRACE("Close NetServices, fd = %d", g_control_fd);
00089
00090
00091 service_thread_finish();
00092
00093 close(g_control_fd);
00094 g_control_fd = 0;
00095 }
00096
00097