1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2014 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  *    if any, must include the following acknowledgment:
22  *       "This product includes software developed by the
23  *        Kannel Group (http://www.kannel.org/)."
24  *    Alternately, this acknowledgment may appear in the software itself,
25  *    if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  *    endorse or promote products derived from this software without
29  *    prior written permission. For written permission, please
30  *    contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  *    nor may "Kannel" appear in their name, without prior written
34  *    permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group.  For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  * smsc_p.h - private interface to SMS center subsystem
59  *
60  * Lars Wirzenius
61  *
62  * New API by Kalle Marjola 1999
63  */
64 
65 #ifndef SMSC_P_H
66 #define SMSC_P_H
67 
68 
69 #include <stddef.h>
70 #include <stdio.h>
71 #include <signal.h>
72 #include <time.h>
73 
74 #include "smsc.h"
75 
76 /*
77  * List of SMS center types that we support.
78  */
79 enum {
80 	SMSC_TYPE_DELETED,
81 	SMSC_TYPE_CIMD,
82 	SMSC_TYPE_EMI_X25,
83 	SMSC_TYPE_SEMA_X28,
84 	SMSC_TYPE_OIS,
85 };
86 
87 /*
88  * The implementation of the SMSCenter object.
89  */
90 #define DIAL_PREFIX_MAX_LEN 1024
91 struct SMSCenter {
92 
93 	int type;
94 	int transport;
95 
96 	char name[1024];
97 	int id;
98 
99         /* Routing prefixes (based on phone number) */
100 	char *preferred_prefix;
101 	char *allowed_prefix;
102 	char *denied_prefix;
103 
104 
105 	/* Alternative charset */
106         long alt_charset;
107 
108 	/* For locking/unlocking. */
109 	Mutex *mutex;
110 
111         /* for dying */
112         volatile sig_atomic_t killed;
113 
114 	/* General IO device */
115 	int socket;
116 
117 	/* Maximum minutes idle time before ping is sent. 0 for no pings. */
118 	int keepalive;
119 
120 	/* TCP/IP */
121 	char *hostname;
122 	int port;
123         int receive_port; /* if used, with EMI 2.0/OIS 4.5 */
124 
125 	/* PSTN/ISDN */
126 	char *phonenum;
127 	char *serialdevice;
128 
129 	/* X.31 */
130 	char *x31_phonenum;
131 	char *x31_serialdevice;
132 
133 	/* Unix pipes */
134 	char *pipe_command;
135 
136 	/* CIMD */
137 	char *cimd_hostname;
138 	int cimd_port;
139 	char *cimd_username;
140 	char *cimd_password;
141 	time_t cimd_last_spoke;
142 	int cimd_config_bits;
143 
144 	/* EMI_X25 */
145 	int emi_fd;
146 	FILE *emi_fp;
147 	char *emi_phonenum;
148 	char *emi_serialdevice;
149 	char *emi_hostname;
150 	int  emi_port;
151 	char *emi_username;
152 	char *emi_password;
153 	int emi_current_msg_number;
154 	time_t emi_last_spoke;
155 	int emi_backup_fd;
156         int emi_backup_port;		/* different one! rename! */
157         char *emi_backup_allow_ip;
158         int emi_our_port;		/* port to bind us when connecting smsc */
159         int emi_secondary_fd;
160 
161         /* SEMA SMS2000 OIS 4.5 X28 */
162 
163         char * sema_smscnua;
164         char * sema_homenua;
165         char * sema_serialdevice;
166         struct sema_msglist *sema_mt, *sema_mo;
167         int sema_fd;
168 
169         /* SEMA SMS2000 OIS 5.0 (TCP/IP to X.25 router) */
170 
171         time_t ois_alive;
172         time_t ois_alive2;
173         void *ois_received_mo;
174         int ois_ack_debt;
175         int ois_flags;
176         int ois_listening_socket;
177         int ois_socket;
178         char *ois_buffer;
179         size_t ois_bufsize;
180         size_t ois_buflen;
181         Octstr *sender_prefix;
182 
183 	/* For buffering input. */
184 	char *buffer;
185 	size_t bufsize;
186 	size_t buflen;
187 };
188 
189 
190 /*
191  * Operations on an SMSCenter object.
192  */
193 SMSCenter *smscenter_construct(void);
194 void smscenter_destruct(SMSCenter *smsc);
195 int smscenter_read_into_buffer(SMSCenter *);
196 void smscenter_remove_from_buffer(SMSCenter *smsc, size_t n);
197 
198 /* Send an SMS message via an SMS center. Return -1 for error,
199    0 for OK. */
200 int smscenter_submit_msg(SMSCenter *smsc, Msg *msg);
201 
202 
203 /* Receive an SMS message from an SMS center. Return -1 for error,
204    0 end of messages (other end closed their end of the connection),
205    or 1 for a message was received. If a message was received, a
206    pointer to it is returned via `*msg'. Note that this operation
207    blocks until there is a message. */
208 int smscenter_receive_msg(SMSCenter *smsc, Msg **msg);
209 
210 
211 /* Is there an SMS message pending from an SMS center? Return -1 for
212    error, 0 for no, 1 for yes. This operation won't block, but may
213    not be instantaneous, if it has to read a few characters to see
214    if there is a message. Use smscenter_receive_smsmessage to actually receive
215    the message. */
216 int smscenter_pending_smsmessage(SMSCenter *smsc);
217 
218 
219 /*
220  * Interface to Nokia SMS centers using CIMD.
221  */
222 SMSCenter *cimd_open(char *hostname, int port, char *username, char *password);
223 int cimd_reopen(SMSCenter *smsc);
224 int cimd_close(SMSCenter *smsc);
225 int cimd_pending_smsmessage(SMSCenter *smsc);
226 int cimd_submit_msg(SMSCenter *smsc, Msg *msg);
227 int cimd_receive_msg(SMSCenter *smsc, Msg **msg);
228 
229 /*
230  * Interface to CMG SMS centers using EMI_X25.
231  */
232 SMSCenter *emi_open(char *phonenum, char *serialdevice, char *username, char *password);
233 int emi_reopen(SMSCenter *smsc);
234 int emi_close(SMSCenter *smsc);
235 SMSCenter *emi_open_ip(char *hostname, int port, char *username,
236 		       char *password, int receive_port, char *allow_ip, int our_port);
237 int emi_reopen_ip(SMSCenter *smsc);
238 int emi_close_ip(SMSCenter *smsc);
239 int emi_pending_smsmessage(SMSCenter *smsc);
240 int emi_submit_msg(SMSCenter *smsc, Msg *msg);
241 int emi_receive_msg(SMSCenter *smsc, Msg **msg);
242 
243 /*
244  * Interface to Sema SMS centers using SM2000
245  */
246 SMSCenter *sema_open(char *smscnua,  char *homenua, char* serialdevice,
247 		     int waitreport);
248 int sema_reopen(SMSCenter *smsc);
249 int sema_close(SMSCenter *smsc);
250 int sema_pending_smsmessage(SMSCenter *smsc);
251 int sema_submit_msg(SMSCenter *smsc, Msg *msg);
252 int sema_receive_msg(SMSCenter *smsc, Msg **msg);
253 
254 /*
255  * Interface to Sema SMS centers using OIS 5.0.
256  * Interface to Sema SMS centers using SM2000
257  */
258 SMSCenter *ois_open(int receiveport, const char *hostname, int port,
259 		    int debug_level);
260 int ois_reopen(SMSCenter *smsc);
261 int ois_close(SMSCenter *smsc);
262 int ois_pending_smsmessage(SMSCenter *smsc);
263 int ois_submit_msg(SMSCenter *smsc, const Msg *msg);
264 int ois_receive_msg(SMSCenter *smsc, Msg **msg);
265 void ois_delete_queue(SMSCenter *smsc);
266 
267 #endif
268