This commit was manufactured by cvs2svn to create branch 'uc'.
[gnokii.git] / include / data / rlp-common.h
1 /*
2
3   $Id$
4
5   G N O K I I
6
7   A Linux/Unix toolset and driver for Nokia mobile phones.
8
9   Released under the terms of the GNU GPL, see file COPYING for more details.
10
11   The development of RLP protocol is sponsored by SuSE CR, s.r.o. (Pavel use
12   the SIM card from SuSE for testing purposes).
13
14   Header file for RLP protocol.
15
16 */
17
18 #ifndef __data_rlp_common_h
19 #define __data_rlp_common_h
20
21 #ifndef __misc_h
22   #include "misc.h"
23 #endif
24
25 /* Global variables */
26
27 /* Defines */
28
29 /* Data types */
30
31 /* Typedef for frame type - they are the same for RLP version 0, 1 and 2. */
32
33 typedef enum {
34   RLPFT_X, /* Unknown. */
35   RLPFT_U, /* Unnumbered frame. */
36   RLPFT_S, /* Supervisory frame. */
37   RLPFT_IS /* Information plus Supervisory (I+S) frame. */
38 } RLP_FrameType;
39
40 /* Define the various Unnumbered frame types. Numbering is bit reversed
41    relative to ETSI GSM 04.22 for easy parsing. */
42
43 typedef enum {
44   RLPU_SABM  = 0x07, /* Set Asynchronous Balanced Mode. */
45   RLPU_UA    = 0x0c, /* Unnumbered Acknowledge. */
46   RLPU_DISC  = 0x08, /* Disconnect. */
47   RLPU_DM    = 0x03, /* Disconnected Mode. */
48   RLPU_NULL  = 0x0f, /* Null information. */
49   RLPU_UI    = 0x00, /* Unnumbered Information. */
50   RLPU_XID   = 0x17, /* Exchange Identification. */
51   RLPU_TEST  = 0x1c, /* Test. */
52   RLPU_REMAP = 0x11  /* Remap. */
53 } RLP_UFrameType;
54
55 /* Define supervisory frame field. */
56
57 typedef enum {
58   RLPS_RR   = 0x00, /* Receive Ready. */
59   RLPS_REJ  = 0x02, /* Reject. */
60   RLPS_RNR  = 0x01, /* Receive Not Ready. */
61   RLPS_SREJ = 0x03  /* Selective Reject. */
62 } RLP_SFrameField;
63
64 /* Used for CurrentFrameType. */
65
66 typedef enum {
67   RLPFT_U_SABM = 0x00,
68   RLPFT_U_UA,
69   RLPFT_U_DISC,
70   RLPFT_U_DM,
71   RLPFT_U_NULL,
72   RLPFT_U_UI,
73   RLPFT_U_XID,
74   RLPFT_U_TEST,
75   RLPFT_U_REMAP,
76   RLPFT_S_RR,
77   RLPFT_S_REJ,
78   RLPFT_S_RNR,
79   RLPFT_S_SREJ,
80   RLPFT_SI_RR,
81   RLPFT_SI_REJ,
82   RLPFT_SI_RNR,
83   RLPFT_SI_SREJ,
84   RLPFT_BAD
85 } RLP_FrameTypes;
86
87 /* Frame definition for TCH/F9.6 frame. */
88
89 typedef struct {
90   u8 Header[2];
91   u8 Data[25];    
92   u8 FCS[3];
93 } RLP_F96Frame;   
94
95 /* Header data "split up" for TCH/F9.6 frame. */
96
97 typedef struct {
98   u8            Ns;   /* Send sequence number. */
99   u8            Nr;   /* Receive sequence number. */
100   u8            M;    /* Unumbered frame type. */
101   u8            S;    /* Status. */
102   bool          PF;   /* Poll/Final. */
103   bool          CR;   /* Command/Response. */
104   RLP_FrameType Type; /* Frame type. */
105 } RLP_F96Header;
106
107
108 /* RLP User requests */
109
110 typedef struct {
111   bool Conn_Req;
112   bool Attach_Req;
113   bool Conn_Req_Neg;
114   bool Reset_Resp;
115   bool Disc_Req;
116 } RLP_UserRequestStore;
117
118 typedef enum {
119   Conn_Req,
120   Attach_Req,
121   Conn_Req_Neg,
122   Reset_Resp,
123   Disc_Req
124 } RLP_UserRequests;
125
126 typedef enum {
127   Conn_Ind,
128   Conn_Conf,
129   Disc_Ind,
130   Reset_Ind,
131   Data,         /* FIXME: This should really be called RLP_Data, otherwise it hogs name "Data"! */
132   StatusChange,
133   GetData
134 } RLP_UserInds;
135
136 /* RLP (main) states. See GSM specification 04.22 Annex A, Section A.1.1. */
137
138 typedef enum {
139   RLP_S0, /* ADM and Detached */
140   RLP_S1, /* ADM and Attached */
141   RLP_S2, /* Pending Connect Request */
142   RLP_S3, /* Pending Connect Indication */
143   RLP_S4, /* ABM and Connection Established */
144   RLP_S5, /* Disconnect Initiated */
145   RLP_S6, /* Pending Reset Request */
146   RLP_S7, /* Pending Reset Indication */
147   RLP_S8  /* Error */
148 } RLP_State;
149
150 /* RLP specification defines several states in which variables can be. */
151
152 typedef enum {
153   _idle=0,
154   _send,
155   _wait,
156   _rcvd,
157   _ackn,
158   _rej,
159   _srej
160 } RLP_StateVariable;
161
162
163 /* RLP Data */
164
165 typedef struct { 
166   u8 Data[25];
167   RLP_StateVariable State;
168 } RLP_Data;
169
170
171
172 /* Prototypes for functions. */
173
174 void RLP_DisplayF96Frame(RLP_F96Frame *frame);
175 void RLP_DecodeF96Header(RLP_F96Frame *frame, RLP_F96Header *header);
176 void RLP_DisplayXID(u8 *frame);
177 void RLP_Initialise(bool (*rlp_send_function)(RLP_F96Frame *frame, bool out_dtx), int (*rlp_passup)(RLP_UserInds ind, u8 *buffer, int length));
178 void RLP_Init_link_vars(void);
179 void RLP_SetUserRequest(RLP_UserRequests type, bool value);
180 void RLP_Send(char *buffer, int length);
181
182 #endif  /* __data_rlp_common_h */