summaryrefslogtreecommitdiffstats
path: root/panels/thunderbolt/bolt-enums.h
blob: 6e2953fa2fd2c6b622ee28a79e930600e0e310c0 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
 * Copyright © 2017 Red Hat, Inc
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *       Christian J. Kellner <christian@kellner.me>
 */

#pragma once

#include "bolt-names.h"
#include "bolt-enum-types.h"


gboolean          bolt_enum_validate (GType    enum_type,
                                      gint     value,
                                      GError **error);

gboolean          bolt_enum_class_validate (GEnumClass *enum_class,
                                            gint        value,
                                            GError    **error);

const char *      bolt_enum_to_string (GType    enum_type,
                                       gint     value,
                                       GError **error);

gint              bolt_enum_from_string (GType       enum_type,
                                         const char *string,
                                         GError    **error);


char *            bolt_flags_class_to_string (GFlagsClass *flags_class,
                                              guint        value,
                                              GError     **error);

gboolean          bolt_flags_class_from_string (GFlagsClass *flags_class,
                                                const char  *string,
                                                guint       *flags_out,
                                                GError     **error);

char *            bolt_flags_to_string (GType    flags_type,
                                        guint    value,
                                        GError **error);

gboolean          bolt_flags_from_string (GType       flags_type,
                                          const char *string,
                                          guint      *flags_out,
                                          GError    **error);

gboolean          bolt_flags_update (guint  from,
                                     guint *to,
                                     guint  mask);

#define bolt_flag_isset(flags_, flag_)  (!!(flags_ & flag_))
#define bolt_flag_isclear(flags_, flag_) (!(flags_ & flag_))

/**
 * BoltStatus:
 * @BOLT_STATUS_UNKNOWN: Device is in an unknown state (should normally not happen).
 * @BOLT_STATUS_DISCONNECTED: Device is not connected.
 * @BOLT_STATUS_CONNECTING: Device is currently being connected.
 * @BOLT_STATUS_CONNECTED: Device is connected, but not authorized.
 * @BOLT_STATUS_AUTHORIZING: Device is currently authorizing.
 * @BOLT_STATUS_AUTH_ERROR: Failed to authorize a device via a key.
 * @BOLT_STATUS_AUTHORIZED: Device connected and authorized.
 * @BOLT_STATUS_AUTHORIZED_SECURE: Device connected and securely authorized via a key (deprecated).
 * @BOLT_STATUS_AUTHORIZED_NEWKEY: Device connected and authorized via a new key (deprecated).
 * @BOLT_STATUS_AUTHORIZED_DPONLY: Device authorized but with thunderbolt disabled (deprecated).
 *
 * The current status of the device.
 */
typedef enum {

  BOLT_STATUS_UNKNOWN = -1,
  BOLT_STATUS_DISCONNECTED = 0,
  BOLT_STATUS_CONNECTING,
  BOLT_STATUS_CONNECTED,
  BOLT_STATUS_AUTHORIZING,
  BOLT_STATUS_AUTH_ERROR,
  BOLT_STATUS_AUTHORIZED,

  /* deprecated, do not use */
  BOLT_STATUS_AUTHORIZED_SECURE,
  BOLT_STATUS_AUTHORIZED_NEWKEY,
  BOLT_STATUS_AUTHORIZED_DPONLY

} BoltStatus;

const char *     bolt_status_to_string (BoltStatus status);
gboolean         bolt_status_is_authorized (BoltStatus status);
gboolean         bolt_status_is_connected (BoltStatus status);
gboolean         bolt_status_is_pending (BoltStatus status);
gboolean         bolt_status_validate (BoltStatus status);

/**
 * BoltAuthFlags:
 * @BOLT_AUTH_NONE: No specific authorization.
 * @BOLT_AUTH_NOPCIE: PCIe tunnels are *not* authorized.
 * @BOLT_AUTH_SECURE: Device is securely authorized.
 * @BOLT_AUTH_NOKEY: Device does *not* support key verification.
 * @BOLT_AUTH_BOOT: Device was already authorized during pre-boot.
 *
 * More specific information about device authorization.
 */
typedef enum { /*< flags >*/

  BOLT_AUTH_NONE   = 0,
  BOLT_AUTH_NOPCIE = 1 << 0,
  BOLT_AUTH_SECURE = 1 << 1,
  BOLT_AUTH_NOKEY  = 1 << 2,
  BOLT_AUTH_BOOT   = 1 << 3,

} BoltAuthFlags;

/**
 * BoltKeyState:
 * @BOLT_KEY_UNKNOWN: unknown key state
 * @BOLT_KEY_MISSING: no key
 * @BOLT_KEY_HAVE: key exists
 * @BOLT_KEY_NEW: key is new
 *
 * The state of the key.
 */

typedef enum {

  BOLT_KEY_UNKNOWN = -1,
  BOLT_KEY_MISSING = 0,
  BOLT_KEY_HAVE = 1,
  BOLT_KEY_NEW = 2

} BoltKeyState;

/**
 * BoltSecurity:
 * @BOLT_SECURITY_UNKNOWN : Unknown security.
 * @BOLT_SECURITY_NONE    : No security, all devices are automatically connected.
 * @BOLT_SECURITY_DPONLY  : Display Port only devices only.
 * @BOLT_SECURITY_USER    : User needs to authorize devices.
 * @BOLT_SECURITY_SECURE  : User needs to authorize devices. Authorization can
 *     be done via key exchange to verify the device identity.
 * @BOLT_SECURITY_USBONLY : Only create a PCIe tunnel to the USB controller in a
 *     connected thunderbolt dock, allowing no downstream PCIe tunnels.
 *
 * The security level of the thunderbolt domain.
 */
typedef enum {

  BOLT_SECURITY_UNKNOWN = -1,
  BOLT_SECURITY_NONE = 0,
  BOLT_SECURITY_DPONLY = 1,
  BOLT_SECURITY_USER = '1',
  BOLT_SECURITY_SECURE = '2',
  BOLT_SECURITY_USBONLY = 4,

} BoltSecurity;


BoltSecurity     bolt_security_from_string (const char *str);
const char *     bolt_security_to_string (BoltSecurity security);
gboolean         bolt_security_validate (BoltSecurity security);
gboolean         bolt_security_allows_pcie (BoltSecurity security);

/**
 * BoltPolicy:
 * @BOLT_POLICY_UNKNOWN: Unknown policy.
 * @BOLT_POLICY_DEFAULT: Default policy.
 * @BOLT_POLICY_MANUAL: Manual authorization of the device.
 * @BOLT_POLICY_AUTO: Connect the device automatically,
 *   with the best possible security level supported
 *   by the domain controller.
 *
 * What do to for connected devices.
 */
typedef enum {

  BOLT_POLICY_UNKNOWN = -1,
  BOLT_POLICY_DEFAULT = 0,
  BOLT_POLICY_MANUAL = 1,
  BOLT_POLICY_AUTO = 2,

} BoltPolicy;


BoltPolicy       bolt_policy_from_string (const char *str);
const char *     bolt_policy_to_string (BoltPolicy policy);
gboolean         bolt_policy_validate (BoltPolicy policy);

/**
 * BoltAuthCtrl:
 * @BOLT_AUTHCTRL_NONE: No authorization flags.
 *
 * Control authorization.
 */
typedef enum { /*< flags >*/

  BOLT_AUTHCTRL_NONE = 0

} BoltAuthCtrl;

/**
 * BoltDeviceType:
 * @BOLT_DEVICE_UNKNOWN_TYPE: Unknown device type
 * @BOLT_DEVICE_HOST: The device representing the host
 * @BOLT_DEVICE_PERIPHERAL: A generic thunderbolt peripheral
 *
 * The type of the device.
 */
typedef enum {

  BOLT_DEVICE_UNKNOWN_TYPE = -1,
  BOLT_DEVICE_HOST = 0,
  BOLT_DEVICE_PERIPHERAL

} BoltDeviceType;

BoltDeviceType   bolt_device_type_from_string (const char *str);
const char *     bolt_device_type_to_string (BoltDeviceType type);
gboolean         bolt_device_type_validate (BoltDeviceType type);
gboolean         bolt_device_type_is_host (BoltDeviceType type);

/**
 * BoltAuthMode:
 * @BOLT_AUTH_DISABLED: Authorization is disabled
 * @BOLT_AUTH_ENABLED: Authorization is enabled.
 *
 * Control authorization.
 */
typedef enum { /*< flags >*/

  BOLT_AUTH_DISABLED = 0,
  BOLT_AUTH_ENABLED  = 1

} BoltAuthMode;

#define bolt_auth_mode_is_enabled(auth) ((auth & BOLT_AUTH_ENABLED) != 0)
#define bolt_auth_mode_is_disabled(auth) (!bolt_auth_mode_is_enabled (auth))