~ubuntu-branches/debian/experimental/ion/experimental

« back to all changes in this revision

Viewing changes to ams/library/vmqts.c

  • Committer: Package Import Robot
  • Author(s): Leo Iannacone
  • Date: 2012-02-01 09:46:31 UTC
  • Revision ID: package-import@ubuntu.com-20120201094631-qpfwehc1b7ftkjgx
Tags: upstream-2.5.3~dfsg1
ImportĀ upstreamĀ versionĀ 2.5.3~dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        vmqts.c:        functions implementing VMQ (vxWorks message
 
3
                        queue) transport service for AMS.
 
4
 
 
5
        Author: Scott Burleigh, JPL
 
6
 
 
7
        Copyright (c) 2005, California Institute of Technology.
 
8
        ALL RIGHTS RESERVED.  U.S. Government Sponsorship
 
9
        acknowledged.
 
10
                                                                        */
 
11
#if defined (VXWORKS) || defined (RTEMS)
 
12
 
 
13
#include "amsP.h"
 
14
 
 
15
#define VMQTS_MAX_MSG_LEN       65535
 
16
 
 
17
typedef MSG_Q_ID                VmqTsep;
 
18
 
 
19
/*      *       *       *       MAMS stuff      *       *       *       */
 
20
 
 
21
/*      VMQ is not suitable as a primary transport service: the
 
22
 *      endpoint ID for the configuration server can't be specified
 
23
 *      before the endpoint is created, so it can't be advertised in
 
24
 *      the MIB to registrars and modules.  There may be some clever
 
25
 *      way around this, using indirection and artificial message
 
26
 *      queue IDs, but the ability to use VMQ as the PTS doesn't
 
27
 *      seem to be worth the extra complexity.  We just don't do it.    */
 
28
 
 
29
static int      vmqComputeCsepName(char *endpointSpec, char *endpointName)
 
30
{
 
31
        putErrmsg("Sorry, no PTS support implemented in vmqts.", NULL);
 
32
        return -1;
 
33
}
 
34
 
 
35
int     vmqMamsInit(MamsInterface *tsif)
 
36
{
 
37
        putErrmsg("Sorry, no PTS support implemented in vmqts.", NULL);
 
38
        return -1;
 
39
}
 
40
 
 
41
static void     *vmqMamsReceiver(void *parm)
 
42
{
 
43
        putErrmsg("Sorry, no PTS support implemented in vmqts.", NULL);
 
44
        return NULL;
 
45
}
 
46
 
 
47
static int      vmqParseMamsEndpoint(MamsEndpoint *ep)
 
48
{
 
49
        putErrmsg("Sorry, no PTS support implemented in vmqts.", NULL);
 
50
        return -1;
 
51
}
 
52
 
 
53
static void     vmqClearMamsEndpoint(MamsEndpoint *ep)
 
54
{
 
55
        putErrmsg("Sorry, no PTS support implemented in vmqts.", NULL);
 
56
}
 
57
 
 
58
static int      vmqSendMams(MamsEndpoint *ep, MamsInterface *tsif, char *msg,
 
59
                        int msgLen)
 
60
{
 
61
        putErrmsg("Sorry, no PTS support implemented in vmqts.", NULL);
 
62
        return -1;
 
63
}
 
64
 
 
65
/*      *       *       *       AMS stuff       *       *       *       */
 
66
 
 
67
static int      vmqAmsInit(AmsInterface *tsif, char *epspec)
 
68
{
 
69
        MSG_Q_ID        vmqSap;
 
70
        char            endpointNameText[32];
 
71
        int             eptLen;
 
72
 
 
73
        CHKERR(tsif);
 
74
        CHKERR(epspec);
 
75
#ifdef VXMP
 
76
        vmqSap = msgQSmCreate(1, VMQTS_MAX_MSG_LEN, MSG_Q_FIFO);
 
77
#else
 
78
        vmqSap = msgQCreate(1, VMQTS_MAX_MSG_LEN, MSG_Q_FIFO);
 
79
#endif
 
80
        if (vmqSap == NULL)
 
81
        {
 
82
                putSysErrmsg("vmqts can't open AMS SAP", NULL);
 
83
                return -1;
 
84
        }
 
85
 
 
86
        tsif->diligence = AmsAssured;
 
87
        tsif->sequence = AmsTransmissionOrder;
 
88
        isprintf(endpointNameText, sizeof endpointNameText, "%u", vmqSap);
 
89
        eptLen = strlen(endpointNameText) + 1;
 
90
        tsif->ept = MTAKE(eptLen);
 
91
        if (tsif->ept == NULL)
 
92
        {
 
93
                msgQDelete(vmqSap);
 
94
                putErrmsg("Can't record endpoint name.", NULL);
 
95
                return -1;
 
96
        }
 
97
 
 
98
        istrcpy(tsif->ept, endpointNameText, eptLen);
 
99
        tsif->sap = vmqSap;
 
100
        return 0;
 
101
}
 
102
 
 
103
static void     *vmqAmsReceiver(void *parm)
 
104
{
 
105
        AmsInterface    *tsif = (AmsInterface *) parm;
 
106
        MSG_Q_ID        vmqSap;
 
107
        AmsSAP          *amsSap;
 
108
        char            *buffer;
 
109
        sigset_t        signals;
 
110
        int             length;
 
111
        int             errnbr;
 
112
 
 
113
        CHKNULL(tsif);
 
114
        vmqSap = (MSG_Q_ID) (tsif->sap);
 
115
        CHKNULL(vmqSap);
 
116
        amsSap = tsif->amsSap;
 
117
        CHKNULL(amsSap);
 
118
        buffer = MTAKE(VMQTS_MAX_MSG_LEN);
 
119
        CHKNULL(buffer);
 
120
        sigfillset(&signals);
 
121
        pthread_sigmask(SIG_BLOCK, &signals, NULL);
 
122
        while (1)
 
123
        {
 
124
                length = msgQReceive(vmqSap, buffer, VMQTS_MAX_MSG_LEN,
 
125
                                WAIT_FOREVER);
 
126
                if (length == ERROR)
 
127
                {
 
128
                        msgQDelete(vmqSap);
 
129
                        MRELEASE(buffer);
 
130
                        tsif->sap = NULL;
 
131
                        return NULL;
 
132
                }
 
133
 
 
134
                /*      Got an AMS message.                             */
 
135
 
 
136
                if (enqueueAmsMsg(amsSap, buffer, length) < 0)
 
137
                {
 
138
                        writeMemo("[?] vmqts discarded AMS message.");
 
139
                }
 
140
        }
 
141
}
 
142
 
 
143
static int      vmqParseAmsEndpoint(AmsEndpoint *dp)
 
144
{
 
145
        VmqTsep tsep;
 
146
 
 
147
        CHKERR(dp);
 
148
        CHKERR(dp->ept);
 
149
        if (sscanf(dp->ept, "%u", &tsep) != 1)
 
150
        {
 
151
                putErrmsg("vmqts found AMS endpoint name invalid.", dp->ept);
 
152
                return -1;
 
153
        }
 
154
 
 
155
        dp->tsep = MTAKE(sizeof(VmqTsep));
 
156
        CHKERR(dp->tsep);
 
157
        memcpy((char *) (dp->tsep), (char *) &tsep, sizeof(VmqTsep));
 
158
 
 
159
        /*      Also parse out the service mode of this endpoint.       */
 
160
 
 
161
        dp->diligence = AmsAssured;
 
162
        dp->sequence = AmsTransmissionOrder;
 
163
        return 0;
 
164
}
 
165
 
 
166
static void     vmqClearAmsEndpoint(AmsEndpoint *dp)
 
167
{
 
168
        CHKERR(dp);
 
169
        if (dp->tsep)
 
170
        {
 
171
                MRELEASE(dp->tsep);
 
172
        }
 
173
}
 
174
 
 
175
static int      vmqSendAms(AmsEndpoint *dp, AmsSAP *sap,
 
176
                        unsigned char flowLabel, char *header,
 
177
                        int headerLen, char *content, int contentLen)
 
178
{
 
179
        char            *vmqAmsBuf;
 
180
        int             len;
 
181
        VmqTsep         *tsep;
 
182
        unsigned short  checksum;
 
183
        int             result;
 
184
 
 
185
        CHKERR(dp);
 
186
        CHKERR(sap);
 
187
        CHKERR(header);
 
188
        CHKERR(headerLen >= 0);
 
189
        CHKERR(contentLen == 0 || (contentLen > 0 && content != NULL));
 
190
        len = headerLen + contentLen + 2;
 
191
        CHKERR(contentLen <= VMQTS_MAX_MSG_LEN);
 
192
        tsep = (VmqTsep *) (dp->tsep);
 
193
#if AMSDEBUG
 
194
printf("in vmqSendAms, tsep is %lu.\n", (unsigned long) tsep);
 
195
#endif
 
196
        if (tsep == NULL)       /*      Lost connectivity to endpoint.  */
 
197
        {
 
198
                return 0;
 
199
        }
 
200
 
 
201
        vmqAmsBuf = MTAKE(headerLen + contentLen + 2);
 
202
        CHKERR(vmqAmsBuf);
 
203
        memcpy(vmqAmsBuf, header, headerLen);
 
204
        if (contentLen > 0)
 
205
        {
 
206
                memcpy(vmqAmsBuf + headerLen, content, contentLen);
 
207
        }
 
208
 
 
209
        checksum = computeAmsChecksum((unsigned char *) vmqAmsBuf,
 
210
                        headerLen + contentLen);
 
211
        checksum = htons(checksum);
 
212
        memcpy(vmqAmsBuf + headerLen + contentLen, (char *) &checksum, 2);
 
213
        result = msgQSend(*tsep, vmqAmsBuf, len, WAIT_FOREVER, MSG_PRI_NORMAL);
 
214
        MRELEASE(vmqAmsBuf);
 
215
        if (result == ERROR)
 
216
        {
 
217
#if AMSDEBUG
 
218
PUTS("vmqSendAms failed.");
 
219
#endif
 
220
                return -1;
 
221
        }
 
222
 
 
223
#if AMSDEBUG
 
224
PUTS("vmqSendAms succeeded.");
 
225
#endif
 
226
        return 0;
 
227
}
 
228
 
 
229
static void     vmqShutdown(void *sap)
 
230
{
 
231
        MSG_Q_ID        vmqSap = (MSG_Q_ID) sap;
 
232
 
 
233
        CHVOID(sap);
 
234
        msgQDelete(vmqSap);
 
235
}
 
236
 
 
237
void    vmqtsLoadTs(TransSvc *ts)
 
238
{
 
239
        char            ownHostName[MAXHOSTNAMELEN + 1];
 
240
        unsigned int    ipAddress;
 
241
        static char     vmqName[32];
 
242
 
 
243
        /*      NOTE: VX message queue endpoints are uniquely
 
244
         *      identified by MSG_Q_ID (a pointer to a message
 
245
         *      queue structure, as returned by msgQCreate or
 
246
         *      msgQSmCreate) within transport service name,
 
247
         *      which is different for each memory space within
 
248
         *      which message queues can be created.  We assume
 
249
         *      that IP address can be used as the unique identifier
 
250
         *      of each such message space.  For a shared-memory
 
251
         *      message queue, the message space identifier needs
 
252
         *      to uniquely identify the set of processors sharing
 
253
         *      access to the memory board in which the shared-memory
 
254
         *      message queues are constructed; IP address may not
 
255
         *      be sufficient for this purpose, in which case some
 
256
         *      other unique identifier will be needed, e.g.,
 
257
         *      spacecraft ID.  We haven't yet figured out how to
 
258
         *      implement this.                                         */
 
259
 
 
260
        CHKVOID(ts);
 
261
        getNameOfHost(ownHostName, sizeof ownHostName);
 
262
        ipAddress = getInternetAddress(ownHostName);
 
263
        isprintf(vmqName, sizeof vmqName, "vmq%u", ipAddress);
 
264
        ts->name = vmqName;
 
265
        ts->csepNameFn = vmqComputeCsepName;
 
266
        ts->mamsInitFn = vmqMamsInit;
 
267
        ts->mamsReceiverFn = vmqMamsReceiver;
 
268
        ts->parseMamsEndpointFn = vmqParseMamsEndpoint;
 
269
        ts->clearMamsEndpointFn = vmqClearMamsEndpoint;
 
270
        ts->sendMamsFn = vmqSendMams;
 
271
        ts->amsInitFn = vmqAmsInit;
 
272
        ts->amsReceiverFn = vmqAmsReceiver;
 
273
        ts->parseAmsEndpointFn = vmqParseAmsEndpoint;
 
274
        ts->clearAmsEndpointFn = vmqClearAmsEndpoint;
 
275
        ts->sendAmsFn = vmqSendAms;
 
276
        ts->shutdownFn = vmqShutdown;
 
277
}
 
278
 
 
279
#endif