summaryrefslogtreecommitdiff
path: root/cleopatre/application/libmme/inc/libmme.h
blob: 64d58187cdce0ca0808289d4b475cc990b1dcb9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* SPC300 bundle {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    application/libmme/inc/libmme.h
 * \brief   structures and function prototypes of libmme
 * \defgroup libmme libmme : MME management library
 *
 */

#ifndef LIBMME_H
#define LIBMME_H

#include <linux/if_ether.h>
/* Include the auto-generated file from mmtcgen. */
#include "mmtypes.h"
#include "ethernet.h"

#define MME_TYPE        0x88e1      /* MME Ethertype (SPiDCOM MME Protocol)   */
#define MME_VERSION     0x01
#define MME_HEADER_SIZE 5 /* MMV - MMTYPE - FMI */
#define MME_MAX_SIZE    (ETH_PACKET_MAX_PAYLOAD_SIZE - MME_HEADER_SIZE)        /* maximum size of MME payload */
#define MME_MIN_SIZE    (ETH_PACKET_MIN_PAYLOAD_SIZE - MME_HEADER_SIZE)       /* minimum size of MME payload */
#define MME_TOUT        5           /* communication timeout in seconds */
#define MME_IFACE_LOOPBACK "lo"
#define MME_IFACE_BRIDGE   "br0"

#define OUI_SPIDCOM     "\x00\x13\xd7"
#define MME_TYPE_MASK 0x0003

typedef struct
{
    unsigned char   mme_dest[ETH_ALEN];     /* Destination node                         */
    unsigned char   mme_src[ETH_ALEN];      /* Source node                              */
    /* unsigned int        vlan_tag; */     /* ieee 802.1q VLAN tag (optional) [0x8100] */
    unsigned short      mtype;              /* 0x88e1 (iee assigned Ethertype)          */
    unsigned char       mmv;                /* Management Message Version               */
    unsigned short      mmtype;             /* Management Message Type                  */
    unsigned short      fmi;                /* Fragmentation Management Info            */
} __attribute__ ((__packed__)) MME_t;

typedef struct
{
    unsigned char       mme_dest[ETH_ALEN]; /* Destination node                         */
    unsigned char       mme_src[ETH_ALEN];  /* Source node                              */
    unsigned int        vlan_tag;           /* ieee 802.1q VLAN tag (optional) [0x8100]	*/
    unsigned short      mtype;              /* 0x88e1 (iee assigned Ethertype)          */
    unsigned char       mmv;                /* Management Message Version               */
    unsigned short      mmtype;             /* Management Message Type                  */
    unsigned short      fmi;                /* Fragmentation Management Info            */
} __attribute__ ((__packed__)) MME_vlan_t;

/**
 * list of errors returned by libmme functions
 */
typedef enum {
    MME_SUCCESS = 0,
    /** context not initialized */
    MME_ERROR_NOT_INIT,
    /** not enough available space */
    MME_ERROR_SPACE,
    /** not enough available data */
    MME_ERROR_ENOUGH,
    /** timeout on waiting on response */
    MME_ERROR_TIMEOUT,
    /** socket send/receive error */
    MME_ERROR_TXRX,
    /** general error */
    MME_ERROR_GEN
} mme_error_t;

/**
 * status of MME context for initialization
 */
typedef enum {
    MME_STATUS_INIT = 0,
    MME_STATUS_OK = 0xabcdefab,
} mme_status_t;

/** MME transaction type */
typedef enum {
    /** send a .REQ and wait for a .CNF */
    MME_SEND_REQ_CNF = 0,
    /** send a .CNF only */
    MME_SEND_CNF,
    /** send a .IND and wait for a .RSP */
    MME_SEND_IND_RSP,
    /** send a .IND only */
    MME_SEND_IND
} mme_send_type_t;

/**
 * Context structure of an MME message
 * \struct mme_ctx_t
 */

typedef struct {
    /** context current status */
    mme_status_t status;
    /** management message type */
    unsigned short mmtype;
    /** buffer  where to store MME data */
    unsigned char *buffer;
    /** total length of buffer */
    unsigned int length;
    /** start of MME payload */
    unsigned int head;
    /** end of MME payload */
    unsigned int tail;
} mme_ctx_t;

/**
 * Callback use give the received MME after a mme_listen()
 *
 * \param  ctx context containing the received packet
 * \param  iface the network interface where packet has been received
 * \param  source source MAC address of received packet
 * \return error type (MME_SUCCESS if success)
 */
typedef mme_error_t (*mme_listen_cb_t) (mme_ctx_t *ctx, char *iface, unsigned char *source);

/* function prototypes */
mme_error_t mme_init (mme_ctx_t *ctx, const mmtype_t mmtype, unsigned char *buffer, const unsigned int length);
mme_error_t mme_get_length (mme_ctx_t *ctx, unsigned int *length);
mme_error_t mme_get_free_space (mme_ctx_t *ctx, unsigned int *length);
mme_error_t mme_push (mme_ctx_t *ctx, const void *data, unsigned int length, unsigned int *result_length);
mme_error_t mme_put (mme_ctx_t *ctx, const void *data, unsigned int length, unsigned int *result_length);
mme_error_t mme_pull (mme_ctx_t *ctx, void *data, unsigned int length, unsigned int *result_length);
mme_error_t mme_pop (mme_ctx_t *ctx, void *data, unsigned int length, unsigned int *result_length);
int         mme_header_prepare (MME_t *mh, mme_ctx_t *ctx, unsigned char *src_mac, unsigned char *dest);
int         mme_prepare (MME_t *mh, mme_ctx_t *ctx, int *fo, int index, unsigned char *pkt);
mme_error_t mme_send (mme_ctx_t *ctx, mme_send_type_t type, char *iface, unsigned char *dest, mme_ctx_t *confirm_ctx);
mme_error_t mme_listen (mme_ctx_t *ctx, char *iface, unsigned char *source, mme_listen_cb_t listen_cb, unsigned int tout);

#endif /* LIBMME_H */