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