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 CMD_FIELD(cmd, p, o, field) (((union XTALK_PDATA(p) *)&((cmd)->alt))->XTALK_STRUCT(p, o).field)
99
#define CMD_DEF(p, o, ...) struct XTALK_STRUCT(p, o) { \
101
} PACKED XTALK_STRUCT(p, o)
102
#define MEMBER(p, o) struct XTALK_STRUCT(p, o) XTALK_STRUCT(p, o)
104
/* Wrappers for transport (xusb) functions */
106
int (*send_func)(void *transport_priv, void *data, size_t len, int timeout);
107
int (*recv_func)(void *transport_priv, void *data, size_t maxlen, int timeout);
108
int (*close_func)(void *transport_priv);
112
* Base XTALK device. A pointer to this struct
113
* should be included in the struct representing
119
struct xtalk_device *xtalk_new(const struct xtalk_ops *ops, size_t packet_size, void *transport_priv);
120
void xtalk_delete(struct xtalk_device *dev);
121
int xtalk_set_protocol(struct xtalk_device *xtalk_dev, const struct xtalk_protocol *xproto);
122
int xtalk_proto_query(struct xtalk_device *dev);
123
void xtalk_dump_command(struct xtalk_command *cmd);
127
struct xtalk_device *dev,
128
struct xtalk_command *cmd,
129
struct xtalk_command **reply_ref);
130
struct xtalk_command *new_command(
131
const struct xtalk_device *xtalk_dev,
132
uint8_t op, uint16_t extra_data);
133
void free_command(struct xtalk_command *cmd);
136
* Convenience macros to define entries in a protocol command table:
137
* p - signify the dialect prefix (XTALK for base protocol)
138
* o - signify command op (e.g: ACK)
139
* cb - A callback function (type xtalk_cmd_callback_t)
141
#define CMD_RECV(p,o,cb) \
142
[p ## _ ## o | XTALK_REPLY_MASK] { \
143
.op = p ## _ ## o | XTALK_REPLY_MASK, \
144
.name = #o "_reply", \
147
sizeof(struct xtalk_header) + \
148
sizeof(struct XTALK_STRUCT(p,o)), \
151
#define CMD_SEND(p,o) \
157
sizeof(struct xtalk_header) + \
158
sizeof(struct XTALK_STRUCT(p,o)), \
162
* Convenience macro to define statuses:
163
* x - status code (e.g: OK)
164
* m - status message (const char *)
166
#define ACK_STAT(x,m) [ STAT_ ## x ] = (m)
170
#endif /* __cplusplus */