1/*
2 * cfg_api.h
3 * Platform independent configuration interface
4 *
5 * Copyright (C) 2014, Broadcom Corporation
6 * All Rights Reserved.
7 *
8 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
9 * the contents of this file may not be disclosed to third parties, copied
10 * or duplicated in any form, in whole or in part, without the prior
11 * written permission of Broadcom Corporation.
12 *
13 * $Id: bcmseclib_api.h,v 1.3 2010-08-09 19:28:58 $
14*/
15
16#ifndef _CFG_API_H_
17#define _CFG_API_H_
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/*
24 * Usage model
25 * Startup/init the security library:
26 * bcmseclib_init(struct maincbs *cbfns);
27 * Return value indicates success/failure
28 *
29 * Create and run separate thread for bcmseclib_run()
30 * Returns when terminated via bcmseclib_deinit() or unrecoverable error occurs.
31 *
32 * Allocate a ctx (if possible):
33 * bcmseclib_ctx_init(clientdata_t *client, struct ctxcbs *cbfns);
34 * Upon success:
35 * cb fun gives ctx pointer for caller's future reference
36 *
37 *
38 * Set a configuration (e.g. p2p) on the ctx created above
39 * bcmseclib_set_config(struct sec_args *args, bcmseclib_ctx_t *ctx);
40 * cb fun advises of success/failure
41 *
42 *
43 * Termination:
44 * De-init a ctx: frees resources used by this ctx
45 * bcmseclib_ctx_cleanup(bcmseclib_ctx_t *ctx);
46 * cb fun advises of status
47 *
48 * Terminate everything:
49 * Frees all resources used by this library, terminates bcmseclib_run thread.
50 * bcmseclib_deinit(void);
51 * cb fun advises of status
52 * [Other] ctx holders will receive error/termination message
53 * via their registered callbacks
54 *
55 */
56
57
58typedef void bcmseclib_ctx_t;
59/* Callback functions */
60
61/* Registered at init time
62 * Called upon termination
63 */
64struct maincbs {
65   void (*main_status)(int status);
66};
67
68struct ctxcbs {
69
70	/* Notes on callback function cfg_status
71	 * ctx is returned by bcmseclib_ctx_init call, valid only if status == ok
72	 * client_data returned by all
73	 * status returned by all, zero for ok, non-zero otherwise
74	 */
75   void (*cfg_status)(void *ctx, clientdata_t * client_data, int status);
76
77   void (*event)(void *ctx, clientdata_t *client_data, const void *data);
78};
79
80
81/* startup
82 * register error callback function
83 * setup timers, allocate data structures ...
84 * returns zero if successful, non-zero otherwise
85 */
86int bcmseclib_init(struct maincbs *cbfns);
87
88/* run it:
89 * This is the thread containing the dispatch loop.
90 * Blocks on [io descriptors]
91 * Only returns if error or terminated by bcmseclib_deinit
92 */
93int bcmseclib_run();
94
95
96/* shutdown: terminate everything
97 * disconnect, close descriptors, free memory, ...
98 * Status reported in main_status cb
99 *
100 */
101int bcmseclib_deinit(void);
102
103/* [re]configure */
104
105#define CFG_MAX_USER_KEY_LEN	80
106/* outsized to hold windows names */
107#define MAX_IF_NAME_SIZE	80
108/* Not all done! */
109struct sec_args {
110	char ifname[MAX_IF_NAME_SIZE + 1]; /* NULL terminated string */
111	int	service;	/* wlan, btamp, other, ... */
112	int role;		/* auth/supp */
113	int WPA_auth;	/* WPA authentication mode bitvec, wlioctl.h */
114	int wsec;	/* wireless security bitvec, wlioctl.h */
115	int btamp_enabled;	/* this cfg is for btamp */
116	uint8 ssid[DOT11_MAX_SSID_LEN];	/* ssid */
117	int ssid_len;		/* ssid len */
118	uint8 psk[CFG_MAX_USER_KEY_LEN];		/* passphrase */
119	int psk_len;		/* passphrase len */
120	int bsscfg_index;	/* bsscfg index */
121	char pin[9]; /* wps pin (asciiz) */
122	uint16 key_index; /* key index */
123	uint8 peer_mac_addr[6];
124
125	/* code will be TRUE for success, FALSE for failure (for a reason)
126	 * reason is only valid for FALSE code
127	 * TRUE means successful handshake & keys plumbed
128	 * Reason values from src/include/proto/wpa.h
129	 *
130	 * May be NULL if no reports desired.
131	 */
132   void (*result)(clientdata_t *, unsigned char code, unsigned char reason);
133
134	/* Forward 8021x frames, events if desired
135	 * Just set to NULL if no forwarding desired
136	 */
137	void (*cb_8021x)(clientdata_t *client, char *frame, int len);
138	void (*cb_event)(clientdata_t *client, char *frame, int len);
139
140	/* Other elements? WAPI et al
141	 * Add them here ...
142	 */
143
144};
145
146
147/* Init ctx, client is caller private, will be used as arg in cb funs
148 * Status is reported by cb function supplied in arg list
149 */
150void bcmseclib_ctx_init(clientdata_t *client, struct ctxcbs *cbfns);
151
152/* Shutdown "this" ctx
153 * Use the ctx pointer returned by bcmseclib_ctx_init
154 * returns status in previously registered cbfn
155 */
156void bcmseclib_ctx_cleanup(bcmseclib_ctx_t *ctx);
157
158/* Use the ctx pointer from call to bcmseclib_ctx_init
159 * Set the cfg for "this" ctx
160 * Callback advises success/failure
161 */
162void bcmseclib_set_config(struct sec_args *args, bcmseclib_ctx_t *ctx);
163
164#ifdef __cplusplus
165}
166#endif
167
168#endif /* _CFG_API_H_ */
169