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