~ubuntu-branches/ubuntu/saucy/dahdi-tools/saucy-proposed

« back to all changes in this revision

Viewing changes to xpp/xtalk/xtalk.h

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2013-08-25 12:48:37 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130825124837-wtefi7f9dsihg8is
Tags: 1:2.7.0-1ubuntu1
* Merge from debian. Remaining changes:
  - debian/control: Added gawk as dependency for dkms build
  - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source
  - debian/control: Set ubuntu maintainer    
  - added debian/dahdi.postinst
  - debian/control: Removed Uploaders field.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef XTALK_H
 
2
#define XTALK_H
 
3
/*
 
4
 * Written by Oron Peled <oron@actcom.co.il>
 
5
 * Copyright (C) 2009, Xorcom
 
6
 *
 
7
 * All rights reserved.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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.
 
22
 *
 
23
 */
 
24
 
 
25
#ifdef __cplusplus
 
26
extern "C"
 
27
{
 
28
#endif /* __cplusplus */
 
29
 
 
30
/*
 
31
 * XTALK - Base protocol for our USB devices
 
32
 *         It is meant to provide a common base for layered
 
33
 *         protocols (dialects)
 
34
 */
 
35
 
 
36
#include <stdint.h>
 
37
#include <stdlib.h>
 
38
/* Definitions common to the firmware (in include/ directory) */
 
39
#include <xtalk_defs.h>
 
40
 
 
41
#ifdef  __GNUC__
 
42
#define PACKED  __attribute__((packed))
 
43
#else
 
44
#error "We do not know how your compiler packs structures"
 
45
#endif
 
46
 
 
47
struct xtalk_device;
 
48
struct xtalk_command_desc;
 
49
 
 
50
typedef int (*xtalk_cmd_callback_t)(
 
51
        struct xtalk_device *xtalk_dev,
 
52
        struct xtalk_command_desc *xtalk_cmd);
 
53
 
 
54
/* Describe a single xtalk command */
 
55
struct xtalk_command_desc {
 
56
        uint8_t                 op;
 
57
        const char              *name;
 
58
        xtalk_cmd_callback_t    callback;
 
59
        uint16_t                len;    /* Minimal length */
 
60
};
 
61
 
 
62
/* Define a complete protocol */
 
63
struct xtalk_protocol {
 
64
        const char                      *name;
 
65
        uint8_t                         proto_version;
 
66
        struct xtalk_command_desc       commands[MAX_OPS];
 
67
        const char                      *ack_statuses[MAX_STATUS];
 
68
};
 
69
 
 
70
/*
 
71
 * The common header of every xtalk command
 
72
 * in every xtalk dialect.
 
73
 */
 
74
struct xtalk_header {
 
75
        uint16_t        len;
 
76
        uint16_t        seq;
 
77
        uint8_t         op;     /* MSB: 0 - to device, 1 - from device */
 
78
} PACKED;
 
79
 
 
80
struct xtalk_command {
 
81
        /* Common part */
 
82
        struct xtalk_header     header;
 
83
        /* Each dialect has its own data members */
 
84
        union private_data {
 
85
                uint8_t raw_data[0];
 
86
        } PACKED alt;
 
87
} PACKED;
 
88
 
 
89
/*
 
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)
 
95
 */
 
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) {     \
 
102
                                        __VA_ARGS__             \
 
103
                                } PACKED XTALK_STRUCT(p, o)
 
104
#define MEMBER(p, o)    struct XTALK_STRUCT(p, o) XTALK_STRUCT(p, o)
 
105
 
 
106
/* Wrappers for transport (xusb) functions */
 
107
struct xtalk_ops {
 
108
        int     (*send_func)(void *transport_priv, void *data, size_t len,
 
109
                        int timeout);
 
110
        int     (*recv_func)(void *transport_priv, void *data, size_t maxlen,
 
111
                        int timeout);
 
112
        int     (*close_func)(void *transport_priv);
 
113
};
 
114
 
 
115
/*
 
116
 * Base XTALK device. A pointer to this struct
 
117
 * should be included in the struct representing
 
118
 * the dialect.
 
119
 */
 
120
struct xtalk_device;
 
121
 
 
122
/* high-level */
 
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);
 
130
 
 
131
/* low-level */
 
132
int process_command(
 
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);
 
140
 
 
141
/*
 
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)
 
146
 */
 
147
#define CMD_RECV(p, o, cb)      \
 
148
        [p ## _ ## o | XTALK_REPLY_MASK] = {            \
 
149
                .op = (p ## _ ## o) | XTALK_REPLY_MASK, \
 
150
                .name = (#o "_reply"),                  \
 
151
                .callback = (cb),                       \
 
152
                .len =                                  \
 
153
                        sizeof(struct xtalk_header) +   \
 
154
                        sizeof(struct XTALK_STRUCT(p, o)),      \
 
155
        }
 
156
 
 
157
#define CMD_SEND(p, o)  \
 
158
        [p ## _ ## o] = {               \
 
159
                .op = (p ## _ ## o),    \
 
160
                .name = (#o),           \
 
161
                .callback = NULL,       \
 
162
                .len =                                  \
 
163
                        sizeof(struct xtalk_header) +   \
 
164
                        sizeof(struct XTALK_STRUCT(p, o)),      \
 
165
        }
 
166
 
 
167
/*
 
168
 * Convenience macro to define statuses:
 
169
 *   x          - status code (e.g: OK)
 
170
 *   m          - status message (const char *)
 
171
 */
 
172
#define ACK_STAT(x, m)  [STAT_ ## x] = (m)
 
173
 
 
174
#ifdef __cplusplus
 
175
}
 
176
#endif /* __cplusplus */
 
177
 
 
178
#endif  /* XTALK_H */