~vibhavp/ubuntu/raring/dahdi-tools/merge-from-debian

« back to all changes in this revision

Viewing changes to xpp/xtalk/xtalk.h

  • Committer: Vibhav Pant
  • Date: 2012-12-26 17:23:16 UTC
  • mfrom: (2.1.6 sid)
  • Revision ID: vibhavp@gmail.com-20121226172316-o2jojsfcnr0aqrme
* Merge from Debian unstable. Remaining changes:
  - Bug Fix: If linux-headers are not installed, don't block, and print
    information for the user.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  - debian/control: Added gawk as dependency for dkms build (LP: #493304)
  - Changes from Debian:
    - debian/control: Change Maintainer
    - debian/control: Removed Uploaders field.
    - debian/control: Removed Debian Vcs-Svn entry and replaced with
      ubuntu-voip Vcs-Bzr, to reflect divergence in packages.
    - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source 

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 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) {     \
 
100
                                        __VA_ARGS__             \
 
101
                                } PACKED XTALK_STRUCT(p, o)
 
102
#define MEMBER(p, o)    struct XTALK_STRUCT(p, o) XTALK_STRUCT(p, o)
 
103
 
 
104
/* Wrappers for transport (xusb) functions */
 
105
struct xtalk_ops {
 
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);
 
109
};
 
110
 
 
111
/*
 
112
 * Base XTALK device. A pointer to this struct
 
113
 * should be included in the struct representing
 
114
 * the dialect.
 
115
 */
 
116
struct xtalk_device;
 
117
 
 
118
/* high-level */
 
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);
 
124
 
 
125
/* low-level */
 
126
int process_command(
 
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);
 
134
 
 
135
/*
 
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)
 
140
 */
 
141
#define CMD_RECV(p,o,cb)        \
 
142
        [p ## _ ## o | XTALK_REPLY_MASK] {              \
 
143
                .op = p ## _ ## o | XTALK_REPLY_MASK,   \
 
144
                .name = #o "_reply",                    \
 
145
                .callback = (cb),                       \
 
146
                .len =                                  \
 
147
                        sizeof(struct xtalk_header) +   \
 
148
                        sizeof(struct XTALK_STRUCT(p,o)),       \
 
149
        }
 
150
 
 
151
#define CMD_SEND(p,o)   \
 
152
        [p ## _ ## o] {         \
 
153
                .op = p ## _ ## o,      \
 
154
                .name = #o,             \
 
155
                .callback = NULL,       \
 
156
                .len =                                  \
 
157
                        sizeof(struct xtalk_header) +   \
 
158
                        sizeof(struct XTALK_STRUCT(p,o)),       \
 
159
        }
 
160
 
 
161
/*
 
162
 * Convenience macro to define statuses:
 
163
 *   x          - status code (e.g: OK)
 
164
 *   m          - status message (const char *)
 
165
 */
 
166
#define ACK_STAT(x,m)   [ STAT_ ## x ] = (m)
 
167
 
 
168
#ifdef __cplusplus
 
169
}
 
170
#endif /* __cplusplus */
 
171
 
 
172
#endif  /* XTALK_H */