aboutsummaryrefslogtreecommitdiffstats
path: root/src/frontends/android/jni/libandroidbridge/charonservice.h
blob: 706eaa22052a8df11347805713e348538138eb5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (C) 2012 Tobias Brunner
 * Copyright (C) 2012 Giuliano Grassi
 * Copyright (C) 2012 Ralf Sager
 * Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

/**
 * @defgroup libandroidbridge libandroidbridge
 *
 * @defgroup android_backend backend
 * @ingroup libandroidbridge
 *
 * @defgroup android_kernel kernel
 * @ingroup libandroidbridge
 *
 * @defgroup charonservice charonservice
 * @{ @ingroup libandroidbridge
 */

#ifndef CHARONSERVICE_H_
#define CHARONSERVICE_H_

#include "vpnservice_builder.h"

#include <library.h>
#include <utils/linked_list.h>

typedef enum android_vpn_state_t android_vpn_state_t;
typedef struct charonservice_t charonservice_t;

/**
 * VPN status codes. As defined in CharonVpnService.java
 */
enum android_vpn_state_t {
	CHARONSERVICE_CHILD_STATE_UP = 1,
	CHARONSERVICE_CHILD_STATE_DOWN,
	CHARONSERVICE_AUTH_ERROR,
	CHARONSERVICE_PEER_AUTH_ERROR,
	CHARONSERVICE_LOOKUP_ERROR,
	CHARONSERVICE_UNREACHABLE_ERROR,
	CHARONSERVICE_GENERIC_ERROR,
};

/**
 * Public interface of charonservice.
 *
 * Used to communicate with CharonVpnService via JNI
 */
struct charonservice_t {

	/**
	 * Update the status in the Java domain (UI)
	 *
	 * @param code			status code
	 * @return				TRUE on success
	 */
	bool (*update_status)(charonservice_t *this, android_vpn_state_t code);

	/**
	 * Install a bypass policy for the given socket using the protect() Method
	 * of the Android VpnService interface
	 *
	 * @param fd			socket file descriptor
	 * @param family		socket protocol family
	 * @return				TRUE if operation successful
	 */
	bool (*bypass_socket)(charonservice_t *this, int fd, int family);

	/**
	 * Get a list of trusted certificates via JNI
	 *
	 * @return				list of DER encoded certificates (as chunk_t*),
	 *						NULL on failure
	 */
	linked_list_t *(*get_trusted_certificates)(charonservice_t *this);

	/**
	 * Get the current vpnservice_builder_t object
	 *
	 * @return				VpnService.Builder instance
	 */
	vpnservice_builder_t *(*get_vpnservice_builder)(charonservice_t *this);

};

/**
 * The single instance of charonservice_t.
 *
 * Set between JNI calls to initializeCharon() and deinitializeCharon().
 */
extern charonservice_t *charonservice;

#endif /** CHARONSERVICE_H_ @}*/