#ifndef __SCNC_MAIN__
#define __SCNC_MAIN__
#include <net/if.h>
#include <sys/queue.h>
#include <netinet/in.h>
#include <vproc.h>
#include "../Drivers/L2TP/L2TP-plugin/vpn_control.h"
#include <CoreFoundation/CFUserNotification.h>
#ifdef TARGET_EMBEDDED_OS
#include <CoreTelephony/CTServerConnectionPriv.h>
#endif
#define PRINTF(x)
#define DEBUG 1
#define FAKE_L2TP_IPSEC 1
struct service_client {
TAILQ_ENTRY(service_client) next;
void *client;
int autoclose;
};
enum {
FLAG_SETUP = 0x1,
FLAG_FREE = 0x2,
FLAG_CONNECT = 0x4,
FLAG_CONFIGCHANGEDNOW = 0x8,
FLAG_CONFIGCHANGEDLATER = 0x10,
FLAG_ONTRAFFIC = 0x20,
FLAG_ALERTERRORS = 0x40,
FLAG_ALERTPASSWORDS = 0x80,
FLAG_FIRSTDIAL = 0x200,
FLAG_ONDEMAND = 0x400,
FLAG_USECERTIFICATE = 0x800,
FLAG_SETUP_ONTRAFFIC = 0x00010000,
FLAG_SETUP_DISCONNECTONLOGOUT = 0x00020000,
FLAG_SETUP_DISCONNECTONSLEEP = 0x00040000,
FLAG_SETUP_PREVENTIDLESLEEP = 0x00080000,
FLAG_SETUP_DISCONNECTONFASTUSERSWITCH = 0x00100000,
FLAG_SETUP_ONDEMAND = 0x00200000
};
enum {
TYPE_PPP = 0x0,
TYPE_IPSEC = 0x1
};
struct ppp_service {
CFBundleRef bundle;
int controlfd[2];
int statusfd[2];
int ndrv_socket;
u_int32_t phase;
u_char ifname[IFNAMSIZ];
u_int32_t laststatus;
u_int32_t lastdevstatus;
CFDictionaryRef newconnectopts;
uid_t newconnectuid;
gid_t newconnectgid;
mach_port_t newconnectbootstrap;
};
struct ipsec_service {
u_int32_t phase;
u_int32_t laststatus;
CFMutableDictionaryRef config;
struct sockaddr_in our_address;
struct sockaddr_in peer_address;
CFRunLoopTimerRef timerref ;
int controlfd;
CFSocketRef controlref;
int eventfd;
CFSocketRef eventref;
u_int8_t *msg; u_int32_t msglen; u_int32_t msgtotallen; struct vpnctl_hdr msghdr; int config_applied; int policies_installed;
int modecfg_installed;
CFMutableDictionaryRef modecfg_policies;
int modecfg_defaultroute;
int modecfg_peer_route_set;
int modecfg_routes_installed;
u_int32_t inner_local_addr;
u_int32_t inner_local_mask;
int kernctl_sock;
struct in_addr ping_addr;
int ping_count;
char if_name[16];
u_int16_t xauth_flags;
char lower_interface[16];
struct in_addr lower_gateway;
CFRunLoopTimerRef interface_timerref ;
CFStringRef banner;
#ifdef TARGET_EMBEDDED_OS
CFMachPortRef edgePort;
CFRunLoopSourceRef edgeRLS;
CTServerConnectionRef edgeConnection;
CFRunLoopTimerRef edge_timerref;
#else
u_int32_t lower_interface_media;
#endif
u_int32_t timeout_lower_interface_change;
CFMachPortRef dnsPort;
struct timeval dnsQueryStart;
CFArrayRef resolvedAddress;
int resolvedAddressError;
int next_address; CFAbsoluteTime display_reenroll_alert_time;
};
struct service {
TAILQ_ENTRY(service) next;
CFStringRef serviceID;
CFStringRef typeRef;
CFStringRef subtypeRef;
u_char *sid;
u_int16_t type;
u_int16_t subtype;
u_int16_t unit;
u_int32_t flags;
CFStringRef device;
uid_t uid;
gid_t gid;
mach_port_t bootstrap;
pid_t pid;
CFDictionaryRef connectopts;
CFDictionaryRef systemprefs;
#ifdef TARGET_EMBEDDED_OS
CFStringRef profileIdentifier;
#endif
CFUserNotificationRef userNotificationRef;
CFRunLoopSourceRef userNotificationRLS;
#ifndef TARGET_EMBEDDED_OS
vproc_transaction_t vt;
#endif
u_int32_t connecttime;
u_int32_t establishtime;
TAILQ_HEAD(, service_client) client_head;
union {
struct ppp_service ppp;
struct ipsec_service ipsec;
} u;
};
#ifndef kSCValNetInterfaceTypeIPSec
#define kSCValNetInterfaceTypeIPSec CFSTR("IPSec")
#endif
extern CFURLRef gBundleURLRef;
extern CFBundleRef gBundleRef;
extern CFURLRef gIconURLRef;
extern CFStringRef gPluginsDir;
extern CFURLRef gPluginsURLRef;
extern SCDynamicStoreRef gDynamicStore;
extern CFStringRef gLoggedInUser;
extern uid_t gLoggedInUserUID;
extern int gSleeping;
extern uint64_t gWakeUpTime;
extern double gTimeScaleSeconds;
extern CFRunLoopSourceRef gStopRls;
extern char *gIPSecAppVersion;
extern int gSCNCVerbose;
extern int gSCNCDebug;
#ifdef TARGET_EMBEDDED_OS
extern int gNattKeepAliveInterval;
#endif
int client_gone(void *client);
int allow_sleep();
int allow_stop();
int allow_dispose(struct service *serv);
void service_started(struct service *serv);
void service_ended(struct service *serv);
void phase_changed(struct service *serv, int phase);
void disable_ondemand(struct service *serv);
void user_notification_callback(CFUserNotificationRef userNotification, CFOptionFlags responseFlags);
int scnc_stop(struct service *serv, void *client, int signal);
int scnc_start(struct service *serv, CFDictionaryRef options, void *client, int autoclose, uid_t uid, gid_t gid, mach_port_t bootstrap);
int scnc_getstatus(struct service *serv);
int scnc_copyextendedstatus(struct service *serv, void **reply, u_int16_t *replylen);
int scnc_copystatistics(struct service *serv, void **reply, u_int16_t *replylen);
int scnc_getconnectdata(struct service *serv, void **reply, u_int16_t *replylen, int all);
int scnc_getconnectsystemdata(struct service *serv, void **reply, u_int16_t *replylen);
int scnc_suspend(struct service *serv);
int scnc_resume(struct service *serv);
struct service *findbyserviceID(CFStringRef serviceID);
struct service *findbypid(pid_t pid);
struct service *findbysid(u_char *data, int len);
struct service *findbyref(u_int16_t type, u_int32_t ref);
u_int32_t makeref(struct service *serv);
#endif