4
* Written by Oron Peled <oron@actcom.co.il>
5
* Copyright (C) 2009, Xorcom
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
#endif /* __cplusplus */
31
* XTALK - Base protocol for our USB devices
32
* It is meant to provide a common base for layered
33
* protocols (dialects)
38
/* Definitions common to the firmware (in include/ directory) */
39
#include <xtalk_defs.h>
42
#define PACKED __attribute__((packed))
44
#error "We do not know how your compiler packs structures"
48
struct xtalk_command_desc;
50
typedef int (*xtalk_cmd_callback_t)(
51
struct xtalk_device *xtalk_dev,
52
struct xtalk_command_desc *xtalk_cmd);
54
/* Describe a single xtalk command */
55
struct xtalk_command_desc {
58
xtalk_cmd_callback_t callback;
59
uint16_t len; /* Minimal length */
62
/* Define a complete protocol */
63
struct xtalk_protocol {
65
uint8_t proto_version;
66
struct xtalk_command_desc commands[MAX_OPS];
67
const char *ack_statuses[MAX_STATUS];
71
* The common header of every xtalk command
72
* in every xtalk dialect.
77
uint8_t op; /* MSB: 0 - to device, 1 - from device */
80
struct xtalk_command {
82
struct xtalk_header header;
83
/* Each dialect has its own data members */
90
* Macros to unify access to protocol packets and fields:
91
* p - signify the dialect prefix (XTALK for base protocol)
92
* o - signify command op (e.g: ACK)
93
* cmd - A pointer to struct xtalk_command
94
* field - field name (e.g: raw_data)
96
#define XTALK_STRUCT(p, o) p ## _struct_ ## o
97
#define XTALK_PDATA(o) xtalk_privdata_ ## o
98
#define XTALK_CMD_PTR(cmd, p) ((union XTALK_PDATA(p)*)&((cmd)->alt))
99
#define CMD_FIELD(cmd, p, o, field) \
100
(XTALK_CMD_PTR(cmd, p)->XTALK_STRUCT(p, o).field)
101
#define CMD_DEF(p, o, ...) struct XTALK_STRUCT(p, o) { \
103
} PACKED XTALK_STRUCT(p, o)
104
#define MEMBER(p, o) struct XTALK_STRUCT(p, o) XTALK_STRUCT(p, o)
106
/* Wrappers for transport (xusb) functions */
108
int (*send_func)(void *transport_priv, void *data, size_t len,
110
int (*recv_func)(void *transport_priv, void *data, size_t maxlen,
112
int (*close_func)(void *transport_priv);
116
* Base XTALK device. A pointer to this struct
117
* should be included in the struct representing
123
struct xtalk_device *xtalk_new(const struct xtalk_ops *ops,
124
size_t packet_size, void *transport_priv);
125
void xtalk_delete(struct xtalk_device *dev);
126
int xtalk_set_protocol(struct xtalk_device *xtalk_dev,
127
const struct xtalk_protocol *xproto);
128
int xtalk_proto_query(struct xtalk_device *dev);
129
void xtalk_dump_command(struct xtalk_command *cmd);
133
struct xtalk_device *dev,
134
struct xtalk_command *cmd,
135
struct xtalk_command **reply_ref);
136
struct xtalk_command *new_command(
137
const struct xtalk_device *xtalk_dev,
138
uint8_t op, uint16_t extra_data);
139
void free_command(struct xtalk_command *cmd);
142
* Convenience macros to define entries in a protocol command table:
143
* p - signify the dialect prefix (XTALK for base protocol)
144
* o - signify command op (e.g: ACK)
145
* cb - A callback function (type xtalk_cmd_callback_t)
147
#define CMD_RECV(p, o, cb) \
148
[p ## _ ## o | XTALK_REPLY_MASK] = { \
149
.op = (p ## _ ## o) | XTALK_REPLY_MASK, \
150
.name = (#o "_reply"), \
153
sizeof(struct xtalk_header) + \
154
sizeof(struct XTALK_STRUCT(p, o)), \
157
#define CMD_SEND(p, o) \
159
.op = (p ## _ ## o), \
163
sizeof(struct xtalk_header) + \
164
sizeof(struct XTALK_STRUCT(p, o)), \
168
* Convenience macro to define statuses:
169
* x - status code (e.g: OK)
170
* m - status message (const char *)
172
#define ACK_STAT(x, m) [STAT_ ## x] = (m)
176
#endif /* __cplusplus */