1 /* -------------------------------------------------------------------- */
2 /* SMS Client, send messages to mobile phones and pagers		*/
3 /*									*/
4 /* vodafone.c								*/
5 /*									*/
6 /*  Copyright (C) 1997,1998,1999,2000 Angelo Masci			*/
7 /*									*/
8 /*  This library is free software; you can redistribute it and/or	*/
9 /*  modify it under the terms of the GNU Library General Public		*/
10 /*  License as published by the Free Software Foundation; either	*/
11 /*  version 2 of the License, or (at your option) any later version.	*/
12 /*									*/
13 /*  This library is distributed in the hope that it will be useful,	*/
14 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of	*/
15 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU	*/
16 /*  Library General Public License for more details.			*/
17 /*									*/
18 /*  You should have received a copy of the GNU Library General Public	*/
19 /*  License along with this library; if not, write to the Free		*/
20 /*  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.	*/
21 /*									*/
22 /*  You can contact the author at this e-mail address:			*/
23 /*									*/
24 /*  angelo@styx.demon.co.uk						*/
25 /*									*/
26 /*  Suggested patch for Australian Telenotes support by 		*/
27 /*     Jeremy Laidman	<JLaidman@AUUG.org.au> 13-Jan-1999		*/
28 /*  									*/
29 /* -------------------------------------------------------------------- */
30 /* $Id$
31    -------------------------------------------------------------------- */
32 
33 #include <stdio.h>
34 #include <string.h>
35 
36 #include "common/common.h"
37 #include "logfile/logfile.h"
38 #include "driver.h"
39 #include "error.h"
40 #include "comms/comms.h"
41 #include "resource/resource.h"
42 
43 /* -------------------------------------------------------------------- */
44 
45 #if 0
46 static char ACK1[] = "WELCOME TO THE VODAFONE PC TEXT MESSAGING SERVICE.\r\n";
47 #else
48 static char ACK1[] = "WELCOME TO THE VODAFONE";
49 #endif
50 
51 static char ACK2[] = "FOLLOWED BY RETURN, (OR RETURN TO QUIT).\r\n"
52 	             "\r\n"
53 	             ">";
54 
55 static char ACK3[] = "FOLLOWED BY RETURN.\r\n"
56 		     "\r\n"
57 		     ">";
58 
59 static char ACK4[] = "MESSAGE ACCEPTED.\r\n";
60 
61 /* -------------------------------------------------------------------- */
62 
63 static struct vodafone_env
64 {
65 	DRIVER_DEFAULT_ENV def;
66 
67 	/* Place any extended driver	*/
68 	/* variables here 		*/
69 
70 } driver_env;
71 
72 /* -------------------------------------------------------------------- */
73 
74 static 	RESOURCE resource_list[] =
75 	{
76 		{ RESOURCE_STRING,  "SMS_comms_params", 	0, 1, NULL, 0,  "7E1",      0, 	  &(driver_env.def.comms_params)  	 },
77 		{ RESOURCE_STRING,  "SMS_centre_number", 	0, 1, NULL, 0,  NULL,       0, 	  &(driver_env.def.centre_number)  	 },
78 		{ RESOURCE_NUMERIC, "SMS_baud", 		0, 1, NULL, 0,  NULL,       1200, &(driver_env.def.baud)  		 },
79 		{ RESOURCE_NUMERIC, "SMS_deliver_timeout", 	0, 0, NULL, 0,  NULL,       30,   &(driver_env.def.deliver_timeout)  	 },
80 		{ RESOURCE_NUMERIC, "SMS_timeout", 		0, 0, NULL, 0,  NULL,       10,   &(driver_env.def.timeout)  		 },
81 		{ RESOURCE_NUMERIC, "SMS_write_timeout", 	0, 0, NULL, 0,  NULL,       10,   &(driver_env.def.write_timeout)  	 },
82 		{ RESOURCE_NUMERIC, "SMS_max_deliver", 		0, 0, NULL, 0,  NULL,       1,    &(driver_env.def.max_deliver)  	 },
83 		{ RESOURCE_NULL,     NULL, 			0, 1, NULL, 0,  NULL,       0, 	  NULL  				 }
84 	};
85 
86 
87 /* -------------------------------------------------------------------- */
88 
89 #define DELIVERTIMEOUT 		(driver_env.def.deliver_timeout)
90 #define TIMEOUT 		(driver_env.def.timeout)
91 #define WRITETIMEOUT 		(driver_env.def.write_timeout)
92 
93 /* -------------------------------------------------------------------- */
94 
95 #define FD			(driver_env.def.fd)
96 
97 /* -------------------------------------------------------------------- */
98 
99 static int VODAFONE_login(void);
100 static int VODAFONE_sendmessage(char *msisdn, char *message);
101 static void VODAFONE_hangup(void);
102 static int VODAFONE_send_disconnect(void);
103 
104 /* -------------------------------------------------------------------- */
105 /* -------------------------------------------------------------------- */
VODAFONE_login(void)106 static int VODAFONE_login(void)
107 {
108 	char buf[MAX_RESPONSE_BUFSIZE];
109 
110 	if (expstr(FD, buf, ACK1, MAX_RESPONSE_BUFSIZE, TIMEOUT) == 0)
111 	{
112 		lprintf(LOG_STANDARD, "Vodafone Service Login\n");
113 	}
114 	else
115 	{
116 		lprintf(LOG_STANDARD, "No Vodafone Service Response\n");
117 
118 		VODAFONE_hangup();
119 		return EVODAFONE_NORESPONSE;
120 	}
121 
122 	return 0;
123 }
124 
125 
126 /* -------------------------------------------------------------------- */
127 /* -------------------------------------------------------------------- */
VODAFONE_sendmessage(char * msisdn,char * message)128 static int VODAFONE_sendmessage(char *msisdn, char *message)
129 {
130 	char buf[MAX_RESPONSE_BUFSIZE];
131 
132 
133 	if (expstr(FD, buf, ACK2, MAX_RESPONSE_BUFSIZE, TIMEOUT) == 0)
134 	{
135 		lprintf(LOG_STANDARD, "Received Number Request\n");
136 	}
137 	else
138 	{
139 		lprintf(LOG_STANDARD, "No Number Request\n");
140 
141 		VODAFONE_hangup();
142 		return EVODAFONE_NONUMBER;
143 	}
144 
145 
146 	twrite(FD, msisdn, strlen(msisdn), WRITETIMEOUT);
147 	twrite(FD, "\r\n", strlen("\r\n"), WRITETIMEOUT);
148 
149 
150 	if (expstr(FD, buf, ACK3, MAX_RESPONSE_BUFSIZE, TIMEOUT) == 0)
151 	{
152 		lprintf(LOG_STANDARD, "Received Message Request\n");
153 	}
154 	else
155 	{
156 		lprintf(LOG_STANDARD, "No Message Request\n");
157 
158 		VODAFONE_hangup();
159 		return EVODAFONE_NOMESSAGE;
160 	}
161 
162 	twrite(FD, message, strlen(message), WRITETIMEOUT);
163 	twrite(FD, "\r\n", strlen("\r\n"), WRITETIMEOUT);
164 
165 	if (expstr(FD, buf, ACK4, MAX_RESPONSE_BUFSIZE, DELIVERTIMEOUT) == 0)
166 	{
167 		lprintf(LOG_STANDARD, "Received Message Delivery Response\n");
168 	}
169 	else
170 	{
171 		lprintf(LOG_STANDARD, "No Message Delivery Response\n");
172 
173 		VODAFONE_hangup();
174 		return EVODAFONE_NODELIVERY;
175 	}
176 
177 	return 0;
178 }
179 
180 /* -------------------------------------------------------------------- */
181 /* -------------------------------------------------------------------- */
VODAFONE_send_disconnect(void)182 static int VODAFONE_send_disconnect(void)
183 {
184 	twrite(FD, "\r\n", strlen("\r\n"), WRITETIMEOUT);
185 	return 0;
186 }
187 
188 /* -------------------------------------------------------------------- */
189 /* -------------------------------------------------------------------- */
VODAFONE_hangup(void)190 static void VODAFONE_hangup(void)
191 {	default_hangup((DRIVER_DEFAULT_ENV *)(&driver_env));
192 }
193 
194 /* -------------------------------------------------------------------- */
195 /* -------------------------------------------------------------------- */
196 DEVICE_ENTRY vodafone_device = {
197 
198 	"VODAFONE",
199 	"1.1",
200 	resource_list,
201 	(DRIVER_DEFAULT_ENV *)(&driver_env),
202 
203 	default_init,
204 	default_main,
205 	default_validate_numeric_id,
206 	default_dial,
207 	default_hangup,
208 	VODAFONE_send_disconnect,
209 	default_single_deliver,
210 	VODAFONE_sendmessage,
211 	VODAFONE_login
212 };
213 
214 
215