Make esme struct shared

This helps to merge similar code from smpp_mirror and smpp_* in follow-up patches.

Related: OS#5568
Change-Id: I8f7ac2c00d16660925dd0b03aa1a0973edf9eb70
changes/46/28846/22
Maxim Suraev 4 months ago
parent be768ac302
commit 366a340ee1
  1. 4
      include/osmocom/msc/gsm_data.h
  2. 16
      include/osmocom/smpp/smpp.h
  3. 35
      include/osmocom/smpp/smpp_smsc.h
  4. 16
      src/libsmpputil/smpp_msc.c
  5. 179
      src/libsmpputil/smpp_smsc.c
  6. 8
      src/libsmpputil/smpp_vty.c
  7. 10
      src/utils/Makefile.am
  8. 34
      src/utils/smpp_mirror.c
  9. 4
      tests/stubs.c

@ -268,7 +268,7 @@ struct gsm_network {
struct sms_queue_config *sms_queue_cfg;
};
struct osmo_esme;
struct smpp_esme;
enum gsm_sms_source_id {
SMS_SOURCE_UNKNOWN = 0,
@ -297,7 +297,7 @@ struct gsm_sms {
} gsm411;
struct {
struct osmo_esme *esme;
struct smpp_esme *esme;
uint32_t sequence_nr;
int transaction_mode;
char msg_id[16];

@ -11,6 +11,21 @@ enum esme_read_state {
READ_ST_IN_MSG = 1,
};
/* struct representing SMPP's External Short Messaging Entity */
struct esme {
uint32_t own_seq_nr;
struct osmo_wqueue wqueue;
enum esme_read_state read_state;
uint32_t read_len;
uint32_t read_idx;
struct msgb *read_msg;
uint8_t smpp_version;
char system_id[SMPP_SYS_ID_LEN + 1];
char password[SMPP_SYS_ID_LEN + 1];
};
#define LOGPESME(ESME, LEVEL, FMT, ARGS...) \
LOGP(DSMPP, LEVEL, "[%s] " FMT, (ESME)->system_id, ##ARGS)
@ -32,6 +47,7 @@ enum esme_read_state {
(resp)->command_status = ESME_ROK; \
(resp)->sequence_number = (req)->sequence_number; }
struct esme *esme_alloc(void *ctx);
uint32_t smpp_msgb_cmdid(struct msgb *msg);
int smpp_openbsc_alloc_init(void *ctx);
int smpp_openbsc_start(struct gsm_network *net);

@ -26,33 +26,24 @@ struct osmo_smpp_addr {
char addr[21+1];
};
struct osmo_esme {
/* struct wrapping ESME struct with additional SMSC-specific things like ACL, command list etc */
struct smpp_esme {
struct llist_head list;
struct smsc *smsc;
struct esme *esme;
struct osmo_smpp_acl *acl;
int use;
struct llist_head smpp_cmd_list;
uint32_t own_seq_nr;
struct osmo_wqueue wqueue;
enum esme_read_state read_state;
uint32_t read_len;
uint32_t read_idx;
struct msgb *read_msg;
uint8_t smpp_version;
char system_id[SMPP_SYS_ID_LEN+1];
uint8_t bind_flags;
};
struct osmo_smpp_acl {
struct llist_head list;
struct smsc *smsc;
struct osmo_esme *esme;
struct smpp_esme *esme;
char *description;
char system_id[SMPP_SYS_ID_LEN+1];
char passwd[SMPP_PASSWD_LEN+1];
@ -89,11 +80,11 @@ struct osmo_smpp_cmd {
struct osmo_timer_list response_timer;
};
struct osmo_smpp_cmd *smpp_cmd_find_by_seqnum(struct osmo_esme *esme,
struct osmo_smpp_cmd *smpp_cmd_find_by_seqnum(struct smpp_esme *esme,
uint32_t sequence_number);
void smpp_cmd_ack(struct osmo_smpp_cmd *cmd);
void smpp_cmd_err(struct osmo_smpp_cmd *cmd, uint32_t status);
void smpp_cmd_flush_pending(struct osmo_esme *esme);
void smpp_cmd_flush_pending(struct smpp_esme *esme);
struct smsc {
struct osmo_fd listen_ofd;
@ -118,25 +109,25 @@ int smpp_smsc_start(struct smsc *smsc, const char *bind_addr, uint16_t port);
int smpp_smsc_restart(struct smsc *smsc, const char *bind_addr, uint16_t port);
void smpp_smsc_stop(struct smsc *smsc);
void smpp_esme_get(struct osmo_esme *esme);
void smpp_esme_put(struct osmo_esme *esme);
void smpp_esme_get(struct smpp_esme *esme);
void smpp_esme_put(struct smpp_esme *esme);
int smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest, struct osmo_esme **emse);
int smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest, struct smpp_esme **emse);
struct osmo_smpp_acl *smpp_acl_alloc(struct smsc *smsc, const char *sys_id);
struct osmo_smpp_acl *smpp_acl_by_system_id(struct smsc *smsc,
const char *sys_id);
void smpp_acl_delete(struct osmo_smpp_acl *acl);
int smpp_tx_submit_r(struct osmo_esme *esme, uint32_t sequence_nr,
int smpp_tx_submit_r(struct smpp_esme *esme, uint32_t sequence_nr,
uint32_t command_status, char *msg_id);
int smpp_tx_alert(struct osmo_esme *esme, uint8_t ton, uint8_t npi,
int smpp_tx_alert(struct smpp_esme *esme, uint8_t ton, uint8_t npi,
const char *addr, uint8_t avail_status);
int smpp_tx_deliver(struct osmo_esme *esme, struct deliver_sm_t *deliver);
int smpp_tx_deliver(struct smpp_esme *esme, struct deliver_sm_t *deliver);
int handle_smpp_submit(struct osmo_esme *esme, struct submit_sm_t *submit,
int handle_smpp_submit(struct smpp_esme *esme, struct submit_sm_t *submit,
struct submit_sm_resp_t *submit_r);
int smpp_route_pfx_add(struct osmo_smpp_acl *acl,

@ -278,7 +278,7 @@ static int submit_to_sms(struct gsm_sms **psms, struct gsm_network *net,
}
/*! \brief handle incoming libsmpp34 ssubmit_sm_t from remote ESME */
int handle_smpp_submit(struct osmo_esme *esme, struct submit_sm_t *submit,
int handle_smpp_submit(struct smpp_esme *esme, struct submit_sm_t *submit,
struct submit_sm_resp_t *submit_r)
{
struct gsm_sms *sms;
@ -329,7 +329,7 @@ int handle_smpp_submit(struct osmo_esme *esme, struct submit_sm_t *submit,
static void alert_all_esme(struct smsc *smsc, struct vlr_subscr *vsub,
uint8_t smpp_avail_status)
{
struct osmo_esme *esme;
struct smpp_esme *esme;
llist_for_each_entry(esme, &smsc->esme_list, list) {
/* we currently send an alert notification to each ESME that is
@ -341,7 +341,7 @@ static void alert_all_esme(struct smsc *smsc, struct vlr_subscr *vsub,
continue;
}
if (esme->acl && !esme->acl->alert_notifications) {
LOGPESME(esme, LOGL_DEBUG, "is not set to receive Alert Notifications\n");
LOGPESME(esme->esme, LOGL_DEBUG, "is not set to receive Alert Notifications\n");
continue;
}
if (esme->acl && esme->acl->deliver_src_imsi) {
@ -585,7 +585,7 @@ static void smpp_cmd_free(struct osmo_smpp_cmd *cmd)
talloc_free(cmd);
}
void smpp_cmd_flush_pending(struct osmo_esme *esme)
void smpp_cmd_flush_pending(struct smpp_esme *esme)
{
struct osmo_smpp_cmd *cmd, *next;
@ -653,7 +653,7 @@ static void smpp_deliver_sm_cb(void *data)
smpp_cmd_err(data, ESME_RSYSERR);
}
static int smpp_cmd_enqueue(struct osmo_esme *esme,
static int smpp_cmd_enqueue(struct smpp_esme *esme,
struct vlr_subscr *vsub, struct gsm_sms *sms,
uint32_t sequence_number)
{
@ -682,7 +682,7 @@ static int smpp_cmd_enqueue(struct osmo_esme *esme,
return 0;
}
struct osmo_smpp_cmd *smpp_cmd_find_by_seqnum(struct osmo_esme *esme,
struct osmo_smpp_cmd *smpp_cmd_find_by_seqnum(struct smpp_esme *esme,
uint32_t sequence_nr)
{
struct osmo_smpp_cmd *cmd;
@ -694,7 +694,7 @@ struct osmo_smpp_cmd *smpp_cmd_find_by_seqnum(struct osmo_esme *esme,
return NULL;
}
static int deliver_to_esme(struct osmo_esme *esme, struct gsm_sms *sms,
static int deliver_to_esme(struct smpp_esme *esme, struct gsm_sms *sms,
struct msc_a *msc_a)
{
struct deliver_sm_t deliver;
@ -802,7 +802,7 @@ bool smpp_route_smpp_first()
int smpp_try_deliver(struct gsm_sms *sms, struct msc_a *msc_a)
{
struct osmo_esme *esme;
struct smpp_esme *esme;
struct osmo_smpp_addr dst;
int rc;

@ -159,12 +159,12 @@ void smpp_acl_delete(struct osmo_smpp_acl *acl)
/* kill any active ESMEs */
if (acl->esme) {
struct osmo_esme *esme = acl->esme;
struct esme *esme = acl->esme->esme;
osmo_fd_unregister(&esme->wqueue.bfd);
close(esme->wqueue.bfd.fd);
esme->wqueue.bfd.fd = -1;
esme->acl = NULL;
smpp_esme_put(esme);
acl->esme = NULL;
smpp_esme_put(acl->esme);
}
/* delete all routes for this ACL */
@ -231,17 +231,17 @@ int smpp_route_pfx_del(struct osmo_smpp_acl *acl,
/*! \brief increaes the use/reference count */
void smpp_esme_get(struct osmo_esme *esme)
void smpp_esme_get(struct smpp_esme *esme)
{
esme->use++;
}
static void esme_destroy(struct osmo_esme *esme)
static void esme_destroy(struct smpp_esme *esme)
{
osmo_wqueue_clear(&esme->wqueue);
if (esme->wqueue.bfd.fd >= 0) {
osmo_fd_unregister(&esme->wqueue.bfd);
close(esme->wqueue.bfd.fd);
osmo_wqueue_clear(&esme->esme->wqueue);
if (esme->esme->wqueue.bfd.fd >= 0) {
osmo_fd_unregister(&esme->esme->wqueue.bfd);
close(esme->esme->wqueue.bfd.fd);
}
smpp_cmd_flush_pending(esme);
llist_del(&esme->list);
@ -250,7 +250,7 @@ static void esme_destroy(struct osmo_esme *esme)
talloc_free(esme);
}
static uint32_t esme_inc_seq_nr(struct osmo_esme *esme)
static uint32_t esme_inc_seq_nr(struct esme *esme)
{
esme->own_seq_nr++;
if (esme->own_seq_nr > 0x7fffffff)
@ -260,7 +260,7 @@ static uint32_t esme_inc_seq_nr(struct osmo_esme *esme)
}
/*! \brief decrease the use/reference count, free if it is 0 */
void smpp_esme_put(struct osmo_esme *esme)
void smpp_esme_put(struct smpp_esme *esme)
{
esme->use--;
if (esme->use <= 0)
@ -268,7 +268,7 @@ void smpp_esme_put(struct osmo_esme *esme)
}
/*! \brief try to find a SMPP route (ESME) for given destination */
int smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest, struct osmo_esme **pesme)
int smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest, struct smpp_esme **pesme)
{
struct osmo_smpp_route *r;
struct osmo_smpp_acl *acl = NULL;
@ -308,14 +308,14 @@ int smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest, struc
}
if (acl && acl->esme) {
struct osmo_esme *esme;
struct smpp_esme *esme;
DEBUGP(DSMPP, "ACL even has ESME, we can route to it!\n");
esme = acl->esme;
if (esme->bind_flags & ESME_BIND_RX) {
*pesme = esme;
return 0;
} else
LOGPESME(esme, LOGL_NOTICE, "is matching route, but not bound for Rx, discarding MO SMS\n");
LOGPESME(esme->esme, LOGL_NOTICE, "is matching route, but not bound for Rx, discarding MO SMS\n");
}
*pesme = NULL;
@ -326,7 +326,7 @@ int smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest, struc
}
/*! \brief pack a libsmpp34 data strcutrure and send it to the ESME */
static int pack_and_send(struct osmo_esme *esme, uint32_t type, void *ptr)
static int pack_and_send(struct esme *esme, uint32_t type, void *ptr)
{
struct msgb *msg;
int rc, rlen;
@ -357,7 +357,7 @@ static int pack_and_send(struct osmo_esme *esme, uint32_t type, void *ptr)
}
/*! \brief transmit a generic NACK to a remote ESME */
static int smpp_tx_gen_nack(struct osmo_esme *esme, uint32_t seq, uint32_t status)
static int smpp_tx_gen_nack(struct esme *esme, uint32_t seq, uint32_t status)
{
struct generic_nack_t nack;
char buf[SMALL_BUFF];
@ -380,7 +380,7 @@ static inline uint32_t smpp_msgb_seq(struct msgb *msg)
}
/*! \brief handle an incoming SMPP generic NACK */
static int smpp_handle_gen_nack(struct osmo_esme *esme, struct msgb *msg)
static int smpp_handle_gen_nack(struct esme *esme, struct msgb *msg)
{
struct generic_nack_t nack;
char buf[SMALL_BUFF];
@ -398,7 +398,7 @@ static int smpp_handle_gen_nack(struct osmo_esme *esme, struct msgb *msg)
return 0;
}
static int _process_bind(struct osmo_esme *esme, uint8_t if_version,
static int _process_bind(struct smpp_esme *esme, uint8_t if_version,
uint32_t bind_flags, const char *sys_id,
const char *passwd)
{
@ -411,9 +411,9 @@ static int _process_bind(struct osmo_esme *esme, uint8_t if_version,
return ESME_RALYBND;
esme->smpp_version = if_version;
snprintf(esme->system_id, sizeof(esme->system_id), "%s", sys_id);
snprintf(esme->esme->system_id, sizeof(esme->esme->system_id), "%s", sys_id);
acl = smpp_acl_by_system_id(esme->smsc, esme->system_id);
acl = smpp_acl_by_system_id(esme->smsc, esme->esme->system_id);
if (!esme->smsc->accept_all) {
if (!acl) {
/* This system is unknown */
@ -437,7 +437,7 @@ static int _process_bind(struct osmo_esme *esme, uint8_t if_version,
/*! \brief handle an incoming SMPP BIND RECEIVER */
static int smpp_handle_bind_rx(struct osmo_esme *esme, struct msgb *msg)
static int smpp_handle_bind_rx(struct smpp_esme *esme, struct msgb *msg)
{
struct bind_receiver_t bind;
struct bind_receiver_resp_t bind_r;
@ -446,7 +446,7 @@ static int smpp_handle_bind_rx(struct osmo_esme *esme, struct msgb *msg)
SMPP34_UNPACK(rc, BIND_RECEIVER, &bind, msgb_data(msg),
msgb_length(msg));
if (rc < 0) {
LOGPESMERR(esme, "in smpp34_unpack()\n");
LOGPESMERR(esme->esme, "in smpp34_unpack()\n");
return rc;
}
@ -459,11 +459,11 @@ static int smpp_handle_bind_rx(struct osmo_esme *esme, struct msgb *msg)
(const char *)bind.system_id, (const char *)bind.password);
bind_r.command_status = rc;
return PACK_AND_SEND(esme, &bind_r);
return PACK_AND_SEND(esme->esme, &bind_r);
}
/*! \brief handle an incoming SMPP BIND TRANSMITTER */
static int smpp_handle_bind_tx(struct osmo_esme *esme, struct msgb *msg)
static int smpp_handle_bind_tx(struct smpp_esme *esme, struct msgb *msg)
{
struct bind_transmitter_t bind;
struct bind_transmitter_resp_t bind_r;
@ -473,7 +473,7 @@ static int smpp_handle_bind_tx(struct osmo_esme *esme, struct msgb *msg)
SMPP34_UNPACK(rc, BIND_TRANSMITTER, &bind, msgb_data(msg),
msgb_length(msg));
if (rc < 0) {
LOGPESMERR(esme, "in smpp34_unpack()\n");
LOGPESMERR(esme->esme, "in smpp34_unpack()\n");
return rc;
}
@ -495,13 +495,13 @@ static int smpp_handle_bind_tx(struct osmo_esme *esme, struct msgb *msg)
tlv.value.val16 = esme->smpp_version;
build_tlv(&bind_r.tlv, &tlv);
rc = PACK_AND_SEND(esme, &bind_r);
rc = PACK_AND_SEND(esme->esme, &bind_r);
destroy_tlv(bind_r.tlv);
return rc;
}
/*! \brief handle an incoming SMPP BIND TRANSCEIVER */
static int smpp_handle_bind_trx(struct osmo_esme *esme, struct msgb *msg)
static int smpp_handle_bind_trx(struct smpp_esme *esme, struct msgb *msg)
{
struct bind_transceiver_t bind;
struct bind_transceiver_resp_t bind_r;
@ -510,7 +510,7 @@ static int smpp_handle_bind_trx(struct osmo_esme *esme, struct msgb *msg)
SMPP34_UNPACK(rc, BIND_TRANSCEIVER, &bind, msgb_data(msg),
msgb_length(msg));
if (rc < 0) {
LOGPESMERR(esme, "in smpp34_unpack()\n");
LOGPESMERR(esme->esme, "in smpp34_unpack()\n");
return rc;
}
@ -523,11 +523,11 @@ static int smpp_handle_bind_trx(struct osmo_esme *esme, struct msgb *msg)
(const char *)bind.system_id, (const char *)bind.password);
bind_r.command_status = rc;
return PACK_AND_SEND(esme, &bind_r);
return PACK_AND_SEND(esme->esme, &bind_r);
}
/*! \brief handle an incoming SMPP UNBIND */
static int smpp_handle_unbind(struct osmo_esme *esme, struct msgb *msg)
static int smpp_handle_unbind(struct smpp_esme *esme, struct msgb *msg)
{
struct unbind_t unbind;
struct unbind_resp_t unbind_r;
@ -536,13 +536,13 @@ static int smpp_handle_unbind(struct osmo_esme *esme, struct msgb *msg)
SMPP34_UNPACK(rc, UNBIND, &unbind, msgb_data(msg),
msgb_length(msg));
if (rc < 0) {
LOGPESMERR(esme, "in smpp34_unpack()\n");
LOGPESMERR(esme->esme, "in smpp34_unpack()\n");
return rc;
}
INIT_RESP(UNBIND_RESP, &unbind_r, &unbind);
LOGPESME(esme, LOGL_INFO, "Rx UNBIND\n");
LOGPESME(esme->esme, LOGL_INFO, "Rx UNBIND\n");
if (esme->bind_flags == 0) {
unbind_r.command_status = ESME_RINVBNDSTS;
@ -551,11 +551,11 @@ static int smpp_handle_unbind(struct osmo_esme *esme, struct msgb *msg)
esme->bind_flags = 0;
err:
return PACK_AND_SEND(esme, &unbind_r);
return PACK_AND_SEND(esme->esme, &unbind_r);
}
/*! \brief handle an incoming SMPP ENQUIRE LINK */
static int smpp_handle_enq_link(struct osmo_esme *esme, struct msgb *msg)
static int smpp_handle_enq_link(struct smpp_esme *esme, struct msgb *msg)
{
struct enquire_link_t enq;
struct enquire_link_resp_t enq_r;
@ -564,21 +564,21 @@ static int smpp_handle_enq_link(struct osmo_esme *esme, struct msgb *msg)
SMPP34_UNPACK(rc, ENQUIRE_LINK, &enq, msgb_data(msg),
msgb_length(msg));
if (rc < 0) {
LOGPESMERR(esme, "in smpp34_unpack()\n");
LOGPESMERR(esme->esme, "in smpp34_unpack()\n");
return rc;
}
LOGPESME(esme, LOGL_DEBUG, "Rx Enquire Link\n");
LOGPESME(esme->esme, LOGL_DEBUG, "Rx Enquire Link\n");
INIT_RESP(ENQUIRE_LINK_RESP, &enq_r, &enq);
LOGPESME(esme, LOGL_DEBUG, "Tx Enquire Link Response\n");
LOGPESME(esme->esme, LOGL_DEBUG, "Tx Enquire Link Response\n");
return PACK_AND_SEND(esme, &enq_r);
return PACK_AND_SEND(esme->esme, &enq_r);
}
/*! \brief send a SUBMIT-SM RESPONSE to a remote ESME */
int smpp_tx_submit_r(struct osmo_esme *esme, uint32_t sequence_nr,
int smpp_tx_submit_r(struct smpp_esme *esme, uint32_t sequence_nr,
uint32_t command_status, char *msg_id)
{
struct submit_sm_resp_t submit_r;
@ -590,7 +590,7 @@ int smpp_tx_submit_r(struct osmo_esme *esme, uint32_t sequence_nr,
submit_r.sequence_number= sequence_nr;
snprintf((char *) submit_r.message_id, sizeof(submit_r.message_id), "%s", msg_id);
return PACK_AND_SEND(esme, &submit_r);
return PACK_AND_SEND(esme->esme, &submit_r);
}
static const struct value_string smpp_avail_strs[] = {
@ -601,7 +601,7 @@ static const struct value_string smpp_avail_strs[] = {
};
/*! \brief send an ALERT_NOTIFICATION to a remote ESME */
int smpp_tx_alert(struct osmo_esme *esme, uint8_t ton, uint8_t npi,
int smpp_tx_alert(struct smpp_esme *esme, uint8_t ton, uint8_t npi,
const char *addr, uint8_t avail_status)
{
struct alert_notification_t alert;
@ -612,7 +612,7 @@ int smpp_tx_alert(struct osmo_esme *esme, uint8_t ton, uint8_t npi,
alert.command_length = 0;
alert.command_id = ALERT_NOTIFICATION;
alert.command_status = ESME_ROK;
alert.sequence_number = esme_inc_seq_nr(esme);
alert.sequence_number = esme_inc_seq_nr(esme->esme);
alert.source_addr_ton = ton;
alert.source_addr_npi = npi;
snprintf((char *)alert.source_addr, sizeof(alert.source_addr), "%s", addr);
@ -622,28 +622,28 @@ int smpp_tx_alert(struct osmo_esme *esme, uint8_t ton, uint8_t npi,
tlv.value.val08 = avail_status;
build_tlv(&alert.tlv, &tlv);
LOGPESME(esme, LOGL_DEBUG, "Tx ALERT_NOTIFICATION (%s/%u/%u): %s\n",
LOGPESME(esme->esme, LOGL_DEBUG, "Tx ALERT_NOTIFICATION (%s/%u/%u): %s\n",
alert.source_addr, alert.source_addr_ton,
alert.source_addr_npi,
get_value_string(smpp_avail_strs, avail_status));
rc = PACK_AND_SEND(esme, &alert);
rc = PACK_AND_SEND(esme->esme, &alert);
destroy_tlv(alert.tlv);
return rc;
}
/* \brief send a DELIVER-SM message to given ESME */
int smpp_tx_deliver(struct osmo_esme *esme, struct deliver_sm_t *deliver)
int smpp_tx_deliver(struct smpp_esme *esme, struct deliver_sm_t *deliver)
{
deliver->sequence_number = esme_inc_seq_nr(esme);
deliver->sequence_number = esme_inc_seq_nr(esme->esme);
LOGPESME(esme, LOGL_DEBUG, "Tx DELIVER-SM (from %s)\n", deliver->source_addr);
LOGPESME(esme->esme, LOGL_DEBUG, "Tx DELIVER-SM (from %s)\n", deliver->source_addr);
return PACK_AND_SEND(esme, deliver);
return PACK_AND_SEND(esme->esme, deliver);
}
/*! \brief handle an incoming SMPP DELIVER-SM RESPONSE */
static int smpp_handle_deliver_resp(struct osmo_esme *esme, struct msgb *msg)
static int smpp_handle_deliver_resp(struct smpp_esme *esme, struct msgb *msg)
{
struct deliver_sm_resp_t deliver_r;
struct osmo_smpp_cmd *cmd;
@ -653,13 +653,13 @@ static int smpp_handle_deliver_resp(struct osmo_esme *esme, struct msgb *msg)
SMPP34_UNPACK(rc, DELIVER_SM_RESP, &deliver_r, msgb_data(msg),
msgb_length(msg));
if (rc < 0) {
LOGPESMERR(esme, "in smpp34_unpack()\n");
LOGPESMERR(esme->esme, "in smpp34_unpack()\n");
return rc;
}
cmd = smpp_cmd_find_by_seqnum(esme, deliver_r.sequence_number);
if (!cmd) {
LOGPESME(esme, LOGL_ERROR, "Rx DELIVER-SM RESP !? (%s)\n",
LOGPESME(esme->esme, LOGL_ERROR, "Rx DELIVER-SM RESP !? (%s)\n",
get_value_string(smpp_status_strs, deliver_r.command_status));
return -1;
}
@ -669,14 +669,14 @@ static int smpp_handle_deliver_resp(struct osmo_esme *esme, struct msgb *msg)
else
smpp_cmd_err(cmd, deliver_r.command_status);
LOGPESME(esme, LOGL_INFO, "Rx DELIVER-SM RESP (%s)\n",
LOGPESME(esme->esme, LOGL_INFO, "Rx DELIVER-SM RESP (%s)\n",
get_value_string(smpp_status_strs, deliver_r.command_status));
return 0;
}
/*! \brief handle an incoming SMPP SUBMIT-SM */
static int smpp_handle_submit(struct osmo_esme *esme, struct msgb *msg)
static int smpp_handle_submit(struct smpp_esme *esme, struct msgb *msg)
{
struct submit_sm_t submit;
struct submit_sm_resp_t submit_r;
@ -686,7 +686,7 @@ static int smpp_handle_submit(struct osmo_esme *esme, struct msgb *msg)
SMPP34_UNPACK(rc, SUBMIT_SM, &submit, msgb_data(msg),
msgb_length(msg));
if (rc < 0) {
LOGPESMERR(esme, "in smpp34_unpack()\n");
LOGPESMERR(esme->esme, "in smpp34_unpack()\n");
return rc;
}
@ -694,32 +694,32 @@ static int smpp_handle_submit(struct osmo_esme *esme, struct msgb *msg)
if (!(esme->bind_flags & ESME_BIND_TX)) {
submit_r.command_status = ESME_RINVBNDSTS;
return PACK_AND_SEND(esme, &submit_r);
return PACK_AND_SEND(esme->esme, &submit_r);
}
LOGPESME(esme, LOGL_INFO, "Rx SUBMIT-SM (%s/%u/%u)\n",
LOGPESME(esme->esme, LOGL_INFO, "Rx SUBMIT-SM (%s/%u/%u)\n",
submit.destination_addr, submit.dest_addr_ton, submit.dest_addr_npi);
INIT_RESP(SUBMIT_SM_RESP, &submit_r, &submit);
rc = handle_smpp_submit(esme, &submit, &submit_r);
if (rc == 0)
return PACK_AND_SEND(esme, &submit_r);
return PACK_AND_SEND(esme->esme, &submit_r);
return rc;
}
/*! \brief one complete SMPP PDU from the ESME has been received */
static int smpp_pdu_rx(struct osmo_esme *esme, struct msgb *msg __uses)
static int smpp_pdu_rx(struct smpp_esme *esme, struct msgb *msg __uses)
{
uint32_t cmd_id = smpp_msgb_cmdid(msg);
int rc = 0;
LOGPESME(esme, LOGL_DEBUG, "smpp_pdu_rx(%s)\n", msgb_hexdump(msg));
LOGPESME(esme->esme, LOGL_DEBUG, "smpp_pdu_rx(%s)\n", msgb_hexdump(msg));
switch (cmd_id) {
case GENERIC_NACK:
rc = smpp_handle_gen_nack(esme, msg);
rc = smpp_handle_gen_nack(esme->esme, msg);
break;
case BIND_RECEIVER:
rc = smpp_handle_bind_rx(esme, msg);
@ -750,11 +750,11 @@ static int smpp_pdu_rx(struct osmo_esme *esme, struct msgb *msg __uses)
case QUERY_SM:
case REPLACE_SM:
case SUBMIT_MULTI:
LOGPESME(esme, LOGL_NOTICE, "Unimplemented PDU Command 0x%08x\n", cmd_id);
LOGPESME(esme->esme, LOGL_NOTICE, "Unimplemented PDU Command 0x%08x\n", cmd_id);
break;
default:
LOGPESME(esme, LOGL_ERROR, "Unknown PDU Command 0x%08x\n", cmd_id);
rc = smpp_tx_gen_nack(esme, smpp_msgb_seq(msg), ESME_RINVCMDID);
LOGPESME(esme->esme, LOGL_ERROR, "Unknown PDU Command 0x%08x\n", cmd_id);
rc = smpp_tx_gen_nack(esme->esme, smpp_msgb_seq(msg), ESME_RINVCMDID);
break;
}
@ -781,7 +781,8 @@ static int smpp_pdu_rx(struct osmo_esme *esme, struct msgb *msg __uses)
/* !\brief call-back when per-ESME TCP socket has some data to be read */
static int esme_link_read_cb(struct osmo_fd *ofd)
{
struct osmo_esme *esme = ofd->data;
struct smpp_esme *e = ofd->data;
struct esme *esme = e->esme;
uint32_t len;
uint8_t *lenptr = (uint8_t *) &len;
uint8_t *cur;
@ -828,7 +829,7 @@ static int esme_link_read_cb(struct osmo_fd *ofd)
msgb_put(msg, rc);
if (esme->read_idx >= esme->read_len) {
rc = smpp_pdu_rx(esme, esme->read_msg);
rc = smpp_pdu_rx(e, esme->read_msg);
msgb_free(esme->read_msg);
esme->read_msg = NULL;
esme->read_idx = 0;
@ -844,9 +845,9 @@ dead_socket:
osmo_fd_unregister(&esme->wqueue.bfd);
close(esme->wqueue.bfd.fd);
esme->wqueue.bfd.fd = -1;
if (esme->acl)
esme->acl->esme = NULL;
smpp_esme_put(esme);
if (e->acl)
e->acl->esme = NULL;
smpp_esme_put(e);
return -EBADF;
}
@ -854,51 +855,67 @@ dead_socket:
/* call-back of write queue once it wishes to write a message to the socket */
static int esme_link_write_cb(struct osmo_fd *ofd, struct msgb *msg)
{
struct osmo_esme *esme = ofd->data;
struct smpp_esme *esme = ofd->data;
int rc;
rc = write(ofd->fd, msgb_data(msg), msgb_length(msg));
if (rc == 0) {
osmo_fd_unregister(&esme->wqueue.bfd);
close(esme->wqueue.bfd.fd);
esme->wqueue.bfd.fd = -1;
osmo_fd_unregister(&esme->esme->wqueue.bfd);
close(esme->esme->wqueue.bfd.fd);
esme->esme->wqueue.bfd.fd = -1;
if (esme->acl)
esme->acl->esme = NULL;
smpp_esme_put(esme);
} else if (rc < msgb_length(msg)) {
LOGPESME(esme, LOGL_ERROR, "Short write\n");
LOGPESME(esme->esme, LOGL_ERROR, "Short write\n");
return -1;
}
return 0;
}
struct esme *esme_alloc(void *ctx)
{
struct esme *e = talloc_zero(ctx, struct esme);
if (!e)
return NULL;
e->own_seq_nr = rand();
esme_inc_seq_nr(e);
osmo_wqueue_init(&e->wqueue, 10);
return e;
}
/* callback for already-accepted new TCP socket */
static int link_accept_cb(struct smsc *smsc, int fd,
struct sockaddr_storage *s, socklen_t s_len)
{
struct osmo_esme *esme = talloc_zero(smsc, struct osmo_esme);
struct smpp_esme *esme = talloc_zero(smsc, struct smpp_esme);
if (!esme) {
close(fd);
return -ENOMEM;
}
esme->esme = esme_alloc(esme);
if (!esme->esme) {
close(fd);
return -ENOMEM;
}
INIT_LLIST_HEAD(&esme->smpp_cmd_list);
smpp_esme_get(esme);
esme->own_seq_nr = rand();
esme_inc_seq_nr(esme);
esme->smsc = smsc;
osmo_wqueue_init(&esme->wqueue, 10);
osmo_fd_setup(&esme->wqueue.bfd, fd, OSMO_FD_READ, osmo_wqueue_bfd_cb, esme, 0);
osmo_fd_setup(&esme->esme->wqueue.bfd, fd, OSMO_FD_READ, osmo_wqueue_bfd_cb, esme, 0);
if (osmo_fd_register(&esme->wqueue.bfd) != 0) {
if (osmo_fd_register(&esme->esme->wqueue.bfd) != 0) {
close(fd);
talloc_free(esme);
return -EIO;
}
esme->wqueue.read_cb = esme_link_read_cb;
esme->wqueue.write_cb = esme_link_write_cb;
esme->esme->wqueue.read_cb = esme_link_read_cb;
esme->esme->wqueue.write_cb = esme_link_write_cb;
llist_add_tail(&esme->list, &smsc->esme_list);

@ -522,12 +522,12 @@ DEFUN(cfg_esme_no_alert_notif, cfg_esme_no_alert_notif_cmd,
}
static void dump_one_esme(struct vty *vty, struct osmo_esme *esme)
static void dump_one_esme(struct vty *vty, struct smpp_esme *esme)
{
vty_out(vty, "ESME System ID: %s, Password: %s, SMPP Version %02x%s",
esme->system_id, esme->acl ? esme->acl->passwd : "",
esme->esme->system_id, esme->acl ? esme->acl->passwd : "",
esme->smpp_version, VTY_NEWLINE);
vty_out(vty, " Connection %s%s", osmo_sock_get_name(tall_vty_ctx, esme->wqueue.bfd.fd), VTY_NEWLINE);
vty_out(vty, " Connection %s%s", osmo_sock_get_name(tall_vty_ctx, esme->esme->wqueue.bfd.fd), VTY_NEWLINE);
if (esme->smsc->def_route == esme->acl)
vty_out(vty, " Is current default route%s", VTY_NEWLINE);
}
@ -537,7 +537,7 @@ DEFUN(show_esme, show_esme_cmd,
SHOW_STR "SMPP Interface\n" "SMPP External SMS Entity\n")
{
struct smsc *smsc = smsc_from_vty(vty);
struct osmo_esme *esme;
struct smpp_esme *esme;
llist_for_each_entry(esme, &smsc->esme_list, list)
dump_one_esme(vty, esme);

@ -41,9 +41,19 @@ smpp_mirror_CFLAGS = \
smpp_mirror_LDADD = \
$(top_builddir)/src/libsmpputil/libsmpputil.a \
$(top_builddir)/src/libmsc/libmsc.a \
$(top_builddir)/src/libvlr/libvlr.a \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \
$(LIBOSMOVTY_LIBS) \
$(LIBOSMONETIF_LIBS) \
$(LIBSMPP34_LIBS) \
$(LIBOSMORANAP_LIBS) \
$(LIBASN1C_LIBS) \
$(LIBOSMOSIGTRAN_LIBS) \
$(LIBOSMOMGCPCLIENT_LIBS) \
$(LIBOSMOGSUPCLIENT_LIBS) \
$(LIBSQLITE3_LIBS) \
-lsctp \
$(NULL)
endif

@ -21,21 +21,6 @@
#include <osmocom/msc/debug.h>
#include <osmocom/smpp/smpp.h>
/* FIXME: merge with smpp_smsc.c */
struct esme {
uint32_t own_seq_nr;
struct osmo_wqueue wqueue;
enum esme_read_state read_state;
uint32_t read_len;
uint32_t read_idx;
struct msgb *read_msg;
uint8_t smpp_version;
char system_id[SMPP_SYS_ID_LEN+1];
char password[SMPP_SYS_ID_LEN+1];
};
/* FIXME: merge with smpp_smsc.c */
static uint32_t esme_inc_seq_nr(struct esme *esme)
@ -292,9 +277,6 @@ static int smpp_esme_init(struct esme *esme, const char *host, uint16_t port)
if (port == 0)
port = 2775;
esme->own_seq_nr = rand();
esme_inc_seq_nr(esme);
osmo_wqueue_init(&esme->wqueue, 10);
esme->wqueue.bfd.data = esme;
esme->wqueue.read_cb = esme_read_cb;
esme->wqueue.write_cb = esme_write_cb;
@ -322,7 +304,7 @@ const struct log_info log_info = {
int main(int argc, char **argv)
{
struct esme esme;
struct esme *esme;
char *host = "localhost";
int port = 0;
int rc;
@ -330,20 +312,22 @@ int main(int argc, char **argv)
msgb_talloc_ctx_init(ctx, 0);
memset(&esme, 0, sizeof(esme));
osmo_init_logging2(ctx, &log_info);
snprintf((char *) esme.system_id, sizeof(esme.system_id), "mirror");
snprintf((char *) esme.password, sizeof(esme.password), "mirror");
esme.smpp_version = 0x34;
esme = esme_alloc(ctx);
if (!esme)
exit(2);
snprintf((char *) esme->system_id, sizeof(esme->system_id), "mirror");
snprintf((char *) esme->password, sizeof(esme->password), "mirror");
esme->smpp_version = 0x34;
if (argc >= 2)
host = argv[1];
if (argc >= 3)
port = atoi(argv[2]);
rc = smpp_esme_init(&esme, host, port);
rc = smpp_esme_init(esme, host, port);
if (rc < 0)
exit(1);

@ -46,8 +46,8 @@ int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void
struct gsm_sms;
struct msc_a;
struct gsm_trans;
struct osmo_esme;
struct smpp_esme;
bool smpp_route_smpp_first() { return false; }
void smpp_esme_put(struct osmo_esme *esme) { return; }
void smpp_esme_put(struct smpp_esme *esme) { return; }
int smpp_try_deliver(struct gsm_sms *sms, struct msc_a *msc_a) { return 0; }
int sms_route_mt_sms(struct gsm_trans *trans, struct gsm_sms *gsms) { return 0; }

Loading…
Cancel
Save