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