-
Notifications
You must be signed in to change notification settings - Fork 5
/
controller.h
117 lines (91 loc) · 3.54 KB
/
controller.h
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
/*
* 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 3 of the License, or
* (at your option) any later version.
* 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.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* Author: Alexandre Bailon <[email protected]>
* Copyright (c) 2016 Alexandre Bailon
*/
#ifndef __CONTROLLER_H__
#define __CONTROLLER_H__
#include <pthread.h>
#include <sys/queue.h>
#include <gbridge.h>
struct connection {
uint16_t cport1_id;
uint16_t cport2_id;
struct interface *intf1;
struct interface *intf2;
void *priv;
TAILQ_ENTRY(connection) node;
pthread_t thread;
};
struct interface {
uint32_t vendor_id;
uint32_t product_id;
uint64_t serial_id;
void *priv;
/* gb intf private data */
uint8_t id;
struct controller *ctrl;
TAILQ_ENTRY(interface) node;
pthread_t thread;
struct greybus_driver *gb_drivers[GB_NETLINK_NUM_CPORT];
};
struct controller {
const char *name;
int (*init) (struct controller * ctrl);
void (*exit) (struct controller * ctrl);
int (*event_loop) (struct controller * ctrl);
void (*event_loop_stop) (struct controller * ctrl);
int (*interface_create) (struct interface * intf);
void (*interface_destroy) (struct interface * intf);
int (*connection_create) (struct connection * conn);
int (*connection_destroy) (struct connection * conn);
int (*write) (struct connection * conn, void *data, size_t len);
int (*read) (struct connection * conn, void *data, size_t len);
int (*intf_read) (struct interface * intf,
uint16_t * cport_id, void *data, size_t len);
void *priv;
/* gb controller private data */
pthread_t thread;
TAILQ_ENTRY(controller) node;
TAILQ_HEAD(head, interface) interfaces;
int event_loop_run;
};
extern struct controller bluetooth_controller;
extern struct controller tcpip_controller;
extern struct controller netlink_controller;
void cport_pack(struct gb_operation_msg_hdr *header, uint16_t cport_id);
uint16_t cport_unpack(struct gb_operation_msg_hdr *header);
void cport_clear(struct gb_operation_msg_hdr *header);
int read_gb_msg(int fd, void *data, size_t len);
struct interface *interface_create(struct controller *ctrl,
uint32_t vendor_id, uint32_t product_id,
uint64_t serial_id, void *priv);
int interface_hotplug(struct interface *intf);
int interface_hot_unplug(struct interface *intf);
void interface_destroy(struct interface *intf);
void interfaces_destroy(struct controller *ctrl);
int connection_create(uint8_t intf1_id, uint16_t cport1_id,
uint8_t intf2_id, uint16_t cport2_id);
int connection_destroy(uint8_t intf1_id, uint16_t cport1_id,
uint8_t intf2_id, uint16_t cport2_id);
int controller_write(uint8_t intf_id, uint16_t cport_id,
void *data, size_t len);
void controllers_init(void);
void controllers_exit(void);
void register_controller(struct controller *controller);
void register_controllers(void);
struct interface *get_interface(uint8_t intf_id);
struct connection *get_connection(uint8_t intf_id, uint16_t cport_id);
int hd_to_intf_cport_id(uint16_t hd_cport_id,
uint8_t *intf, uint16_t *cport_id);
int register_gbsim_controller(const char *manifest_file);
#endif /* __CONTROLLER_H__ */