Back to index

im-sdk  12.3.91
im-simple.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <sys/types.h>
00004 #if defined(lint) && defined(HAVE_NOTE_H)
00005 #include <note.h>
00006 #endif /* lint && HAVE_NOTE_H */
00007 
00008 #include <iiimp-data.h>
00009 #include <iiimp-opcode.h>
00010 
00011 #include "iiimp-dataP.h"
00012 
00013 
00014 IIIMP_message *
00015 iiimp_simple_new(
00016     IIIMP_data_s *   data_s,
00017     IIIMP_card7             opcode,
00018     IIIMP_card16     im_id,
00019     IIIMP_card16     ic_id)
00020 {
00021     IIIMP_message *  m;
00022     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00023     if (NULL == m) {
00024        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00025        return NULL;
00026     }
00027     m->opcode = opcode;
00028     m->im_id = im_id;
00029     m->ic_id = ic_id;
00030     return m;
00031 }
00032 
00033 
00034 void
00035 iiimp_simple_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00036 {
00037 #if defined(lint) && defined(HAVE_NOTE_H)
00038     NOTE(ARGUNUSED(data_s))
00039 #endif /* lint && HAVE_NOTE_H */
00040     free(m);
00041     return;
00042 }
00043 
00044 
00045 uchar_t *
00046 iiimp_simple_pack(
00047     IIIMP_data_s *   data_s,
00048     IIIMP_card7             opcode,
00049     IIIMP_card16     im_id,
00050     IIIMP_card16     ic_id,
00051     size_t *         buf_size)
00052 {
00053     size_t           nbyte;
00054     int                     length;
00055     uchar_t *        buf;
00056     size_t           rest;
00057     uchar_t *        p;
00058 
00059     nbyte = (2 + 2);
00060     length = (nbyte >> 2);
00061     *buf_size = (1 + 3 + nbyte);
00062 
00063     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00064     if (NULL == buf) {
00065        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00066        return NULL;
00067     }
00068 
00069     PUT_PACKET_HEADER(buf, opcode, length);
00070 
00071     rest = nbyte;
00072     p = (buf + 4);
00073 
00074     PUTU16(im_id, rest, p, data_s->byte_swap);
00075     PUTU16(ic_id, rest, p, data_s->byte_swap);
00076 
00077     return buf;
00078 }
00079 
00080 
00081 IIIMP_message *
00082 iiimp_simple_unpack(
00083     IIIMP_data_s *   data_s,
00084     IIIMP_card7             opcode,
00085     size_t *         nbyte,
00086     const uchar_t ** ptr)
00087 {
00088     IIIMP_message *  m;
00089     size_t           rest;
00090     const uchar_t *  p;
00091 
00092     rest = *nbyte;
00093     p = *ptr;
00094 
00095     if (rest < 4) {
00096        data_s->status = IIIMP_DATA_INVALID;
00097        return NULL;
00098     }
00099 
00100     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00101     if (NULL == m) {
00102        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00103        return NULL;
00104     }
00105 
00106     m->opcode = opcode;
00107 
00108     GETU16(m->im_id, rest, p, data_s->byte_swap);
00109     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00110 
00111     *nbyte = rest;
00112     *ptr = p;
00113 
00114     return m;
00115 }
00116 
00117 
00118 IIIMP_message *
00119 iiimp_simple_im_unpack(
00120     IIIMP_data_s *   data_s,
00121     IIIMP_card7             opcode,
00122     size_t *         nbyte,
00123     const uchar_t ** ptr)
00124 {
00125     IIIMP_message *  m;
00126     size_t           rest;
00127     const uchar_t *  p;
00128 
00129     rest = *nbyte;
00130     p = *ptr;
00131 
00132     if (rest < 4) {
00133        data_s->status = IIIMP_DATA_INVALID;
00134        return NULL;
00135     }
00136 
00137     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00138     if (NULL == m) {
00139        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00140        return NULL;
00141     }
00142 
00143     m->opcode = opcode;
00144 
00145     GETU16(m->im_id, rest, p, data_s->byte_swap);
00146     SKIP16(rest, p);
00147     m->ic_id = -1;
00148 
00149     *nbyte = rest;
00150     *ptr = p;
00151 
00152     return m;
00153 }
00154 
00155 
00156 void
00157 iiimp_simple_im_print(
00158     IIIMP_data_s *   data_s,
00159     IIIMP_message *  m)
00160 {
00161     if (NULL == m) return;
00162     iiimp_message_header_print(data_s, m->opcode, m->im_id, -1);
00163 }
00164 
00165 
00166 void
00167 iiimp_simple_print(
00168     IIIMP_data_s *   data_s,
00169     IIIMP_message *  m)
00170 {
00171     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00172 }
00173 
00174 
00175 /* Local Variables: */
00176 /* c-file-style: "iiim-project" */
00177 /* End: */