Initial commit

This commit is contained in:
PhatPhuckDave
2024-07-22 19:58:07 +02:00
commit cd8322cc5a
11 changed files with 354 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
jstester/node_modules

BIN
SMPP_v3_4_Issue1_2.pdf Normal file

Binary file not shown.

BIN
SMPP_v5.pdf Normal file

Binary file not shown.

5
go.mod Normal file
View File

@@ -0,0 +1,5 @@
module smpp-tester
go 1.22.4
require github.com/yuin/gopher-lua v1.1.1

2
go.sum Normal file
View File

@@ -0,0 +1,2 @@
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=

5
jstester/package.json Normal file
View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"smpp": "0.6.0-rc.4"
}
}

53
jstester/pnpm-lock.yaml generated Normal file
View File

@@ -0,0 +1,53 @@
lockfileVersion: '9.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
dependencies:
smpp:
specifier: 0.6.0-rc.4
version: 0.6.0-rc.4
packages:
findhit-proxywrap@0.3.13:
resolution: {integrity: sha512-gI1KV7yCuMHtveiWbQUJZheNOukScz+15MTtrH/MK5RJ77JjYeJ1DegUfkBnlPvDx5NhZESl48zE/MwpWZ1LXQ==}
engines: {node: '>= 0.8'}
iconv-lite@0.6.3:
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
engines: {node: '>=0.10.0'}
lodash@4.17.21:
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
safer-buffer@2.1.2:
resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
smpp@0.6.0-rc.4:
resolution: {integrity: sha512-WDa0XBRQkkJJPcKRtoC9C0cnzhopFIK9/zFcWBOy3sD4xZr3i/Dt3yX+XRparKzpp9QkqRr2/8EYt8JNGxu85w==}
engines: {node: '>=4'}
snapshots:
findhit-proxywrap@0.3.13:
dependencies:
lodash: 4.17.21
iconv-lite@0.6.3:
dependencies:
safer-buffer: 2.1.2
lodash@4.17.21: {}
safer-buffer@2.1.2: {}
smpp@0.6.0-rc.4:
dependencies:
findhit-proxywrap: 0.3.13
iconv-lite: 0.6.3
safer-buffer: 2.1.2

64
jstester/smppCenter.js Normal file
View File

@@ -0,0 +1,64 @@
const smpp = require("smpp");
const PORT = 2775;
let messageIdIterator = Math.floor(Math.random() * 1_000_000);
console.log(`Using iterator: ${messageIdIterator}`);
const server = smpp.createServer(
{
debug: false,
},
function (session) {
session.on("error", function (err) {
console.error(err);
});
session.on("bind_transceiver", function (pdu) {
console.log("Client connected");
session.send(pdu.response());
});
session.on("enquire_link", function (pdu) {
session.send(pdu.response());
});
session.on("submit_sm", async function (pdu) {
console.log(new Date().toISOString() + " Incoming submit_sm");
console.log(pdu);
let response = pdu.response();
response.message_id = (messageIdIterator++).toString(16);
session.send(response);
let drMessage = "";
let date = new Date()
.toISOString()
.replace(/T/, "")
.replace(/\..+/, "")
.replace(/-/g, "")
.replace(/:/g, "")
.substring(2, 12);
drMessage += "id:" + response.message_id + " ";
drMessage += "sub:001 ";
drMessage += "dlvrd:001 ";
drMessage += "submit date:" + date + " ";
drMessage += "done date:" + date + " ";
drMessage += "stat:DELIVRD ";
drMessage += "err:000 ";
drMessage += "text:";
setTimeout(() => {
console.log(new Date().toISOString() + " Sending DR");
const DRPdu = {
source_addr: pdu.source_addr,
destination_addr: pdu.destination_addr,
short_message: drMessage,
esm_class: 4,
};
console.log(DRPdu);
session.deliver_sm(DRPdu);
}, 2 * 60 * 1000);
});
}
);
server.listen(PORT);
console.log("Server started");

43
jstester/smppClient.js Normal file
View File

@@ -0,0 +1,43 @@
const smpp = require("smpp");
let message_id = 0;
const session = smpp.connect(
{
url: "smpp://0.0.0.0:6001",
auto_enquire_link_period: 10000,
debug: true,
},
function () {
session.bind_transceiver(
{
system_id: "test",
password: "test",
},
function (pdu) {
if (pdu.command_status === 0) {
// Successfully bound
console.log("sending shit");
session.submit_sm(
{
source_addr: "smpp_test_1",
destination_addr: "123123123123",
short_message: "Hello!",
data_coding: 0xc0,
},
function (pdu) {
if (pdu.command_status === 0) {
console.log(pdu.message_id);
message_id = pdu.message_id;
}
}
);
}
}
);
}
);
session.on("deliver_sm", function (pdu) {
console.log("Got deliver_sm");
session.send(pdu.response());
});

19
lua/lua.go Normal file
View File

@@ -0,0 +1,19 @@
package main
import (
"log"
"github.com/yuin/gopher-lua"
)
func init() {
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
}
func main() {
l := lua.NewState()
defer l.Close()
l.DoString(`i = 1; print(i)`)
l.DoString(`i = i + 1; print(i)`)
l.DoString(`print(i)`)
}

162
main.go Normal file
View File

@@ -0,0 +1,162 @@
package main
import (
"bytes"
"encoding/binary"
"log"
"net"
"sync"
)
func init() {
log.SetFlags(log.Lmicroseconds)
}
// Function to create a submit_sm PDU
func createSubmitSMPDU() []byte {
// Example values for the submit_sm PDU fields
serviceType := "CMT"
sourceAddrTON := byte(0x01)
sourceAddrNPI := byte(0x01)
sourceAddr := "12345"
destAddrTON := byte(0x01)
destAddrNPI := byte(0x01)
destinationAddr := "67890"
esmClass := byte(0x00)
protocolID := byte(0x00)
priorityFlag := byte(0x00)
scheduleDeliveryTime := ""
validityPeriod := ""
registeredDelivery := byte(0x01)
replaceIfPresentFlag := byte(0x00)
dataCoding := byte(0x00)
smDefaultMsgID := byte(0x00)
shortMessage := "Hello, SMPP!"
// Calculate the length of the PDU
headerLength := 16
bodyLength := 1 + len(serviceType) + 1 + 1 + len(sourceAddr) + 1 + 1 + len(destinationAddr) + 1 + 1 + len(scheduleDeliveryTime) + 1 + len(validityPeriod) + 1 + 1 + 1 + 1 + 1 + len(shortMessage)
totalLength := headerLength + bodyLength
log.Printf("Total length: %d", totalLength)
// Create a buffer to hold the PDU
var buffer bytes.Buffer
// Command Length
binary.Write(&buffer, binary.BigEndian, uint32(totalLength))
// Command ID (submit_sm)
binary.Write(&buffer, binary.BigEndian, uint32(0x00000004))
// Command Status (0x00000000 for ESME_ROK)
binary.Write(&buffer, binary.BigEndian, uint32(0x00000000))
// Sequence Number (example value)
binary.Write(&buffer, binary.BigEndian, uint32(0x00000001))
// Service Type
buffer.WriteString(serviceType)
buffer.WriteByte(0x00)
// Source Address TON
buffer.WriteByte(sourceAddrTON)
// Source Address NPI
buffer.WriteByte(sourceAddrNPI)
// Source Address
buffer.WriteString(sourceAddr)
buffer.WriteByte(0x00)
// Destination Address TON
buffer.WriteByte(destAddrTON)
// Destination Address NPI
buffer.WriteByte(destAddrNPI)
// Destination Address
buffer.WriteString(destinationAddr)
buffer.WriteByte(0x00)
// ESM Class
buffer.WriteByte(esmClass)
// Protocol ID
buffer.WriteByte(protocolID)
// Priority Flag
buffer.WriteByte(priorityFlag)
// Schedule Delivery Time
buffer.WriteString(scheduleDeliveryTime)
buffer.WriteByte(0x00)
// Validity Period
buffer.WriteString(validityPeriod)
buffer.WriteByte(0x00)
// Registered Delivery
buffer.WriteByte(registeredDelivery)
// Replace If Present Flag
buffer.WriteByte(replaceIfPresentFlag)
// Data Coding
buffer.WriteByte(dataCoding)
// SM Default Message ID
buffer.WriteByte(smDefaultMsgID)
// Short Message Length
buffer.WriteByte(byte(len(shortMessage)))
// Short Message
buffer.WriteString(shortMessage)
// Return the PDU as a byte slice
return buffer.Bytes()
}
func main() {
// addr := ":2775"
// listener, err := net.Listen("tcp", addr)
// if err != nil {
// log.Fatalf("Failed to start SMPP server: %v", err)
// }
// defer listener.Close()
// log.Printf("SMPP server started on %s", addr)
// go func() {
// for {
// conn, err := listener.Accept()
// if err != nil {
// log.Printf("Failed to accept connection: %v", err)
// continue
// }
// go handleConnection(conn)
// }
// }()
wg := &sync.WaitGroup{}
wg.Add(1)
conn, err := net.Dial("tcp", "localhost:2775")
if err != nil {
log.Printf("Failed to connect to SMPP server: %+v", err)
return
}
log.Printf("Connected to SMPP server")
defer conn.Close()
go func() {
conn.Write(createSubmitSMPDU())
data, err := conn.Read(make([]byte, 1024))
if err != nil {
log.Printf("Failed to read from connection: %+v", err)
return
}
log.Printf("Received data: %#v", data)
}()
wg.Wait()
}