#ifndef _SmsGsm_Header
#define _SmsGsm_Header
#include "smslib.h"

struct sms_data_gsm;
typedef struct sms_data_gsm SmsGsm;

struct gsm_message;
typedef struct gsm_message GsmMessage;

/* init->mode flags... */
enum {
	MODE_ZERO		= 0x00,
	MODE_CPIN_OK	= 0x01,
	MODE_CBST_ONE	= 0x02,
	MODE_PDU		= 0x04,
	MODE_8BIT		= 0x08,
	MODE_16BIT		= 0x10,
	MODE_EXTENDED	= 0x20,
	MODE_CNMI_FLUSH = 0x40
};

typedef struct gsm_init {
	char *port,*localphone,*debug_file,*pin,*pin2,*puk,*puk2,*init_string,*sca,*dcs,*cbst;
	int baud,dodebug,mode,min_signal,signal_timeout,crlf;
} GsmInit;

SmsGsm *sms_gsm_init(Sms *sms, GsmInit *init, int *errcode);
void sms_gsm_free(SmsGsm **gsm);

GsmMessage *sms_gsm_wait(SmsGsm *gsm, long timeout_msec, int *errcode);

int sms_gsm_send(SmsGsm *gsm, void *data, char *from, char *to, char *message);

int sms_gsm_recv(SmsGsm *gsm, GsmMessage *msg);
int sms_gsm_accept(SmsGsm *gsm, GsmMessage *msg, int code, char *reason);
int sms_gsm_reject(SmsGsm *gsm, GsmMessage *msg, int code, char *reason);

char *sms_gsm_error(SmsGsm *gsm, int errcode, char *bf, int bfsz);

char *sms_gsm_fromip(SmsGsm *gsm, GsmMessage *msg);
char *sms_gsm_from(SmsGsm *gsm, GsmMessage *msg);
char *sms_gsm_to(SmsGsm *gsm, GsmMessage *msg);
char *sms_gsm_body(SmsGsm *gsm, GsmMessage *msg);

void sms_gsm_msgfree(SmsGsm *gsm, GsmMessage **msg);

#define MODEM_MAX_ERROR 516
#define SMS_GSM_OPEN_ERROR		MODEM_MAX_ERROR+1
#define SMS_GSM_SETUP_ERROR		MODEM_MAX_ERROR+2
#define SMS_GSM_READ_ERROR		MODEM_MAX_ERROR+3
#define SMS_GSM_WRITE_ERROR		MODEM_MAX_ERROR+4
#define SMS_GSM_MISC_ERROR		MODEM_MAX_ERROR+5
#define SMS_GSM_PROTO_ERROR		MODEM_MAX_ERROR+6
#define SMS_GSM_ECHO_ERROR		MODEM_MAX_ERROR+7
#define SMS_GSM_PIN_ERROR		MODEM_MAX_ERROR+8

#ifdef _DEBUG
enum { TEST_SEND, TEST_RECV };
void test_pdu(int mode, char *pdu);
void test_txt(int iscmgl, char *cmgr);
void test_txt_msg(int ucs2, int ext7bit, char *message, int length);
#endif

#endif

