First version, development moved to 5110-connected machine
[gnokii.git] / common / data / rlp-common.c
index 9c46e0d..509faa7 100644 (file)
@@ -16,6 +16,8 @@
 
 */
 
+#include "config.h"
+
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 
 /* Our state machine which handles all of nine possible states of RLP
    machine. */
-void MAIN_STATE_MACHINE(RLP_F96Frame *frame, RLP_F96Header *header);
+static void MAIN_STATE_MACHINE(RLP_F96Frame *frame, RLP_F96Header *header);
 
 /* This is the type we are just handling. */
-RLP_FrameTypes CurrentFrameType;
+static RLP_FrameTypes CurrentFrameType;
 
 /* Current state of RLP state machine. */
-RLP_State      CurrentState=RLP_S0; /* We start at ADM and Detached */
+static RLP_State      CurrentState=RLP_S0; /* We start at ADM and Detached */
 
 /* Next state of RLP state machine. */
-RLP_State      NextState;
+static RLP_State      NextState;
 
 /* Pointer to Send function that sends frame to phone. */
-bool      (*RLPSendFunction)(RLP_F96Frame *frame, bool out_dtx);
+static bool      (*RLPSendFunction)(RLP_F96Frame *frame, bool out_dtx);
 
 /* Pointer to Passup function which returns data/inds */
-int      (*RLP_Passup)(RLP_UserInds ind, u8 *buffer, int length);
+static int      (*RLP_Passup)(RLP_UserInds ind, u8 *buffer, int length);
 
 
 /* State variables - see GSM 04.22, Annex A, section A.1.2 */
 
-RLP_StateVariable UA_State;
-RLP_StateVariable UI_State;
-RLP_StateVariable Ackn_State;
-RLP_StateVariable Poll_State;
-RLP_StateVariable Poll_xchg;
-RLP_StateVariable SABM_State;
-RLP_StateVariable DISC_State;
-RLP_StateVariable DM_State;  /* FIXME - not handled */
-RLP_StateVariable XI_R_State;
-RLP_StateVariable XID_C_State;
-RLP_StateVariable XID_R_State;
-RLP_StateVariable TEST_R_State;
-
-u8 VR=0;
-u8 VA=0;
-u8 VS=0;
-u8 VD=0;
-u8 DISC_Count;
-
-u8 DTX_VR;
-RLP_FrameTypes DTX_SF;
+static RLP_StateVariable UA_State;
+/*
+static RLP_StateVariable UI_State;
+*/
+static RLP_StateVariable Ackn_State;
+static RLP_StateVariable Poll_State;
+static RLP_StateVariable Poll_xchg;
+static RLP_StateVariable SABM_State;
+static RLP_StateVariable DISC_State;
+static RLP_StateVariable DM_State;  /* FIXME - not handled */
+/*
+static RLP_StateVariable XID_C_State;
+*/
+static RLP_StateVariable XID_R_State;
+/*
+static RLP_StateVariable TEST_R_State;
+*/
+
+static u8 VR=0;
+static u8 VA=0;
+static u8 VS=0;
+static u8 VD=0;
+static u8 DISC_Count;
+
+static u8 DTX_VR;
+static RLP_FrameTypes DTX_SF;
 
 #define RLP_M 62
 
-RLP_Data R[RLP_M];
-RLP_Data S[RLP_M];
+static RLP_Data R[RLP_M];
+static RLP_Data S[RLP_M];
 
-RLP_StateVariable SABM_State;
-int SABM_Count;
+static RLP_StateVariable SABM_State;
+static int SABM_Count;
 
-RLP_UserRequestStore UserRequests;
+static RLP_UserRequestStore UserRequests;
 
-u8 Poll_Count=0;
+static u8 Poll_Count=0;
 
 /* For now timing is done based on a frame reception rate of 20ms */
 /* Serge has measured it as 18.4ms */
@@ -96,28 +103,28 @@ u8 Poll_Count=0;
 /* To set, timer is loaded with RLP_Timeout1_Limit/RLP_T_Scaling. */
 /* Each received frame (including NULLS / errors) any >0 timer is decrease */
 
-int T;
-int T_RCVS[RLP_M];
+static int T;
+static int T_RCVS[RLP_M];
 
-bool UA_FBit=true;
-bool Ackn_FBit=false;
-bool DM_FBit=false;  /* FIXME - not handled */
-bool RRReady=false;
-bool LRReady=true;   /* FIXME - not handled (as if we couldn't keep up with 9600bps :-) */
-bool DISC_PBit=false;
+static bool UA_FBit=true;
+static bool Ackn_FBit=false;
+static bool DM_FBit=false;  /* FIXME - not handled */
+static bool RRReady=false;
+static bool LRReady=true;   /* FIXME - not handled (as if we couldn't keep up with 9600bps :-) */
+static bool DISC_PBit=false;
 
-u8 LastStatus=0xff;   /* Last Status byte */
+static u8 LastStatus=0xff;   /* Last Status byte */
 
 
 /* RLP Parameters. FIXME: Reset these - e.g. when entering state 0 */
 
-u8 RLP_SEND_WS = RLP_M-1;
-u8 RLP_RCV_WS = RLP_M-1;
-u8 RLP_Timeout1_Limit = 55;
-u8 RLP_N2 = 15; /* Maximum number of retransmisions. GSM spec says 6 here, but
-                   Nokia will XID this. */
-u8 RLP_T2=0;
-u8 RLP_VersionNumber=0;
+static u8 RLP_SEND_WS = RLP_M-1;
+static u8 RLP_RCV_WS = RLP_M-1;
+static u8 RLP_Timeout1_Limit = 55;
+static u8 RLP_N2 = 15; /* Maximum number of retransmisions. GSM spec says 6 here, but
+                          Nokia will XID this. */
+static u8 RLP_T2=0;
+static u8 RLP_VersionNumber=0;
 
 
 
@@ -197,7 +204,7 @@ void RLP_SetUserRequest(RLP_UserRequests type, bool value) {
 
 /* Check whether a user event is set */
 
-bool RLP_GetUserRequest(RLP_UserRequests type) {
+static bool RLP_GetUserRequest(RLP_UserRequests type) {
 
        bool result=false, *x;
 
@@ -230,7 +237,7 @@ bool RLP_GetUserRequest(RLP_UserRequests type) {
        return result;
 }
 
-void RLP_SetTimer(int *timer)
+static void RLP_SetTimer(int *timer)
 {
        *timer=(int)(RLP_Timeout1_Limit/RLP_T_Scaling);
 }
@@ -280,7 +287,7 @@ static bool InWindow(u8 val, u8 lower, u8 upper)
        return (val <= upper) || (val >= lower);
 }
 
-void RLP_Init_link_vars(void)
+static void RLP_Init_link_vars(void)
 {
        int i;
   
@@ -305,7 +312,7 @@ void RLP_Init_link_vars(void)
 }
 
 
-void RLP_AddRingBufferDataToSlots(void)
+static void RLP_AddRingBufferDataToSlots(void)
 {
        u8 buffer[24];
        int size;
@@ -329,9 +336,11 @@ void RLP_AddRingBufferDataToSlots(void)
 }
 
 
+#ifndef UCLINUX
+
 /* FIXME: Remove this after finishing. */
 
-void X(RLP_F96Frame *frame) {
+static void X(RLP_F96Frame *frame) {
 
        int i;
 
@@ -340,9 +349,10 @@ void X(RLP_F96Frame *frame) {
    
 }
 
+#endif /* UCLINUX */
 
  
-void ResetAllT_RCVS(void)
+static void ResetAllT_RCVS(void)
 {
 
        int i;
@@ -353,7 +363,7 @@ void ResetAllT_RCVS(void)
 
 /* This function is used for sending RLP frames to the phone. */
 
-void RLP_SendF96Frame(RLP_FrameTypes FrameType,
+static void RLP_SendF96Frame(RLP_FrameTypes FrameType,
                       bool OutCR, bool OutPF,
                       u8 OutNR, u8 OutNS,
                       u8 *OutData, u8 OutDTX)
@@ -594,6 +604,8 @@ void RLP_SendF96Frame(RLP_FrameTypes FrameType,
 
 }
 
+static void RLP_DecodeF96Header(RLP_F96Frame *frame, RLP_F96Header *header);
+
 /* Check_input_PDU in Serge's code. */
 
 void RLP_DisplayF96Frame(RLP_F96Frame *frame)
@@ -930,14 +942,14 @@ void RLP_DisplayF96Frame(RLP_F96Frame *frame)
 
 /* FIXME: real TEST_Handling - we do not handle TEST yet. */
 
-void TEST_Handling() {
+static void TEST_Handling() {
 }
 
 
 
 /* FIXME: better XID_handling - but this will answer a XID command. */
 
-bool XID_Handling (RLP_F96Frame *frame, RLP_F96Header *header) {
+static bool XID_Handling (RLP_F96Frame *frame, RLP_F96Header *header) {
   
        u8 count;
        u8 type;
@@ -1026,7 +1038,7 @@ bool XID_Handling (RLP_F96Frame *frame, RLP_F96Header *header) {
 }
 
 
-bool Send_TXU(RLP_F96Frame *frame, RLP_F96Header *header) {
+static bool Send_TXU(RLP_F96Frame *frame, RLP_F96Header *header) {
 
 #ifdef DEBUG
        //    fprintf(stdout, _("Send_TXU()\n"));
@@ -1070,7 +1082,7 @@ bool Send_TXU(RLP_F96Frame *frame, RLP_F96Header *header) {
 
 /* Deliver data */
 
-void RLP_DeliverAllInSeqIF()
+static void RLP_DeliverAllInSeqIF()
 {
        int i,j;
 
@@ -1098,7 +1110,7 @@ void RLP_DeliverAllInSeqIF()
 
 
 /* Mark any missing information frames between VR and Ns*/
-void RLP_MarkMissingIF(u8 Ns)
+static void RLP_MarkMissingIF(u8 Ns)
 {
        u8 i;
        for (i=VR; i!=Ns; i=Incr(i)) {
@@ -1109,7 +1121,7 @@ void RLP_MarkMissingIF(u8 Ns)
 
 /* Information frame handler */
 
-bool RLP_I_Handler(RLP_F96Frame *frame, RLP_F96Header *header)
+static bool RLP_I_Handler(RLP_F96Frame *frame, RLP_F96Header *header)
 {
 
        if ((header->CR) && (header->PF))
@@ -1142,7 +1154,7 @@ bool RLP_I_Handler(RLP_F96Frame *frame, RLP_F96Header *header)
 
 /* Mark acknowledged send frames */
 
-void RLP_AdvanceVA(u8 Nr)
+static void RLP_AdvanceVA(u8 Nr)
 {
        while (VA!=Nr) {
                S[VA].State=_idle;
@@ -1153,7 +1165,7 @@ void RLP_AdvanceVA(u8 Nr)
 
 /* Decrease VS back down to Nr since these have not been acknowledged */
 
-void RLP_DecreaseVS(u8 Nr)
+static void RLP_DecreaseVS(u8 Nr)
 {
        while (VS!=Nr) {
                VS=Decr(VS);
@@ -1163,7 +1175,7 @@ void RLP_DecreaseVS(u8 Nr)
 
 /* Supervisory frame handling */
 
-void RLP_S_Handler(RLP_F96Frame *frame, RLP_F96Header *header)
+static void RLP_S_Handler(RLP_F96Frame *frame, RLP_F96Header *header)
 {
        u8 i;
 
@@ -1219,7 +1231,7 @@ void RLP_S_Handler(RLP_F96Frame *frame, RLP_F96Header *header)
 
 /* Find the first SREJ frame */
 
-bool RLP_SREJSlot(u8 *x)
+static bool RLP_SREJSlot(u8 *x)
 {
        u8 i;
 
@@ -1235,7 +1247,7 @@ bool RLP_SREJSlot(u8 *x)
 
 /* Check if any SREJ frames need sending, if not send the next in line */
 
-bool RLP_PrepareDataToTransmit(u8 *p)
+static bool RLP_PrepareDataToTransmit(u8 *p)
 {
        u8 i;
 
@@ -1258,7 +1270,7 @@ bool RLP_PrepareDataToTransmit(u8 *p)
 
 /* Send a SREJ command */
 
-void RLP_SendSREJ(u8 x)
+static void RLP_SendSREJ(u8 x)
 {
        u8 k;
   
@@ -1298,7 +1310,7 @@ void RLP_SendSREJ(u8 x)
 
 /* Send a command */
 
-void RLP_Send_XX_Cmd(RLP_FrameTypes type)
+static void RLP_Send_XX_Cmd(RLP_FrameTypes type)
 {
        u8 k;
 
@@ -1336,7 +1348,7 @@ void RLP_Send_XX_Cmd(RLP_FrameTypes type)
 
 /* Send a Response */
 
-void RLP_Send_XX_Resp(RLP_FrameTypes type)
+static void RLP_Send_XX_Resp(RLP_FrameTypes type)
 {
        u8 k;
   
@@ -1362,7 +1374,7 @@ void RLP_Send_XX_Resp(RLP_FrameTypes type)
 
 /* Decide which frame to use and send it - currently only used in state 4 */
 
-void RLP_SendData()
+static void RLP_SendData()
 {
        u8 x;
 
@@ -1382,7 +1394,7 @@ void RLP_SendData()
        else RLP_Send_XX_Cmd(RLPFT_S_RNR);
 }
 
-void MAIN_STATE_MACHINE(RLP_F96Frame *frame, RLP_F96Header *header) {
+static void MAIN_STATE_MACHINE(RLP_F96Frame *frame, RLP_F96Header *header) {
        int i;
 
        switch (CurrentState) {
@@ -1743,7 +1755,6 @@ void MAIN_STATE_MACHINE(RLP_F96Frame *frame, RLP_F96Header *header) {
                        if(SABM_State!=_idle) printf("[SABM_State %d]",SABM_State);
                        if(DISC_State!=_idle) printf("[DISC_State %d]",DISC_State);
                        if(DM_State!=_idle) printf("[DM_State %d]",DM_State);
-                       if(XI_R_State!=_idle) printf("[XI_R_State %d]",XI_R_State);
                        if(XID_C_State!=_idle) printf("[XID_C_State %d]",XID_C_State);
                        if(XID_R_State!=_idle) printf("[XID_R_State %d]",XID_R_State);
                        if(TEST_R_State!=_idle) printf("[TEST_R_State %d]",TEST_R_State);
@@ -1925,7 +1936,9 @@ void MAIN_STATE_MACHINE(RLP_F96Frame *frame, RLP_F96Header *header) {
    exact implementation of section 5.2.2.6, Exchange Identification, XID of
    the GSM specification 04.22. */
 
-void RLP_DisplayXID(u8 *frame) 
+#ifdef RLP_DEBUG
+
+static void RLP_DisplayXID(u8 *frame) 
 {
 
        int count = 25;  /* Sanity check */
@@ -2005,10 +2018,12 @@ void RLP_DisplayXID(u8 *frame)
        return;
 }
 
+#endif /* RLP_DEBUG */
+
 /* Given a pointer to an F9.6 Frame, split data out into component parts of
    header and determine frame type. */
 
-void RLP_DecodeF96Header(RLP_F96Frame *frame, RLP_F96Header *header)
+static void RLP_DecodeF96Header(RLP_F96Frame *frame, RLP_F96Header *header)
 {
 
        /* Poll/Final bit. */