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