7 A Linux/Unix toolset and driver for Nokia mobile phones.
9 Released under the terms of the GNU GPL, see file COPYING for more details.
11 This file provides routines to handle processing of data when connected in
12 fax or data mode. Converts data from/to GSM phone to virtual modem
19 #define __data_datapump_c
30 #include <sys/types.h>
39 #include "gsm-common.h"
41 #include "data/at-emulator.h"
42 #include "data/virtmodem.h"
43 #include "data/datapump.h"
44 #include "data/rlp-common.h"
46 /* Global variables */
47 extern bool CommandMode;
50 extern int PtyRDFD; /* File descriptor for reading and writing to/from */
51 extern int PtyWRFD; /* pty interface - only different in debug mode. */
53 static bool connected;
55 static int DP_CallBack(RLP_UserInds ind, u8 *buffer, int length);
57 bool DP_Initialise(int read_fd, int write_fd)
61 RLP_Initialise(GSM->SendRLPFrame, DP_CallBack);
62 RLP_SetUserRequest(Attach_Req,true);
69 static int DP_CallBack(RLP_UserInds ind, u8 *buffer, int length)
75 if (CommandMode==false) write(PtyWRFD, buffer, length);
78 if (CommandMode==false) ATEM_ModemResult(MR_CARRIER);
79 RLP_SetUserRequest(Conn_Req,true);
84 if (CommandMode==false) ATEM_ModemResult(MR_CONNECT);
88 if (CommandMode==false) ATEM_ModemResult(MR_NOCARRIER);
90 /* Set the call passup back to the at emulator */
91 GSM->DialData(NULL,-1,&ATEM_CallPassup);
95 RLP_SetUserRequest(Reset_Resp,true);
99 struct timeval timeout;
102 FD_SET(PtyRDFD,&readfds);
106 if (select(PtyRDFD+1,&readfds,NULL/*writefds*/,NULL/*exceptfds*/,&timeout)) {
108 /* Check if the program has closed */
109 /* Return to command mode */
110 /* Note that the call will still be in progress, */
111 /* as with a normal modem (I think) */
113 if (!FD_ISSET(PtyRDFD,&readfds)) {
115 /* Set the call passup back to the at emulator */
116 GSM->DialData(NULL,-1,&ATEM_CallPassup);
120 temp = read(PtyRDFD, buffer, length);
122 if (temp<0) return 0; /* FIXME - what do we do now? */
124 /* This will only check +++ and the beginning of a read */
125 /* But there should be a pause before it anyway */
127 if (buffer[0]=='+') {
130 if (buffer[1]=='+') pluscount++;
133 if (buffer[2]=='+') pluscount++;
135 if (temp>3) pluscount=0;
142 /* Set the call passup back to the at emulator */
143 GSM->DialData(NULL,-1,&ATEM_CallPassup);
144 ATEM_ModemResult(MR_OK);
159 void DP_CallPassup(char c)
163 if (CommandMode==false) ATEM_ModemResult(MR_CARRIER);
164 RLP_SetUserRequest(Conn_Req,true);
169 /* Set the call passup back to the at emulator */
170 GSM->DialData(NULL,-1,&ATEM_CallPassup);
171 ATEM_ModemResult(MR_NOCARRIER);
172 RLP_SetUserRequest(Disc_Req, true);