diff --git a/udpserver.cpp b/udpserver.cpp index bf93fdf..119de2c 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -66,7 +66,7 @@ udpServer::~udpServer() { client->idleTimer->stop(); delete client->idleTimer; - delete& client; // Not sure how safe this is? + //delete& client; // Not sure how safe this is? } foreach(CLIENT* client, civClients) { @@ -74,7 +74,7 @@ udpServer::~udpServer() delete client->idleTimer; client->pingTimer->stop(); delete client->pingTimer; - delete& client; // Not sure how safe this is? + //delete& client; // Not sure how safe this is? } foreach(CLIENT* client, audioClients) { @@ -82,7 +82,7 @@ udpServer::~udpServer() delete client->idleTimer; client->pingTimer->stop(); delete client->pingTimer; - delete& client; // Not sure how safe this is? + //delete& client; // Not sure how safe this is? } } @@ -112,8 +112,8 @@ void udpServer::controlReceived() current->myId = controlId; current->remoteId = qFromLittleEndian(r.mid(8, 4)); current->socket = udpControl; - current->innerPingSeq = (quint32)rand(); - current->pingSeq = 1; + current->innerPingSeq = (quint16)rand(); + current->pingSeq = (quint8)rand() << 8 | (quint8)rand(); current->pingTimer = new QTimer(); current->idleTimer = new QTimer(); connect(current->pingTimer, &QTimer::timeout, this, std::bind(&udpServer::sendPing, this, current, (quint16)0x00, false)); @@ -225,9 +225,9 @@ void udpServer::controlReceived() // Generate login response current->clientName = parseNullTerminatedString(r, 0x60); current->authInnerSeq = qFromLittleEndian(r.mid(0x17, 2)); - current->tokenRx = qFromLittleEndian(r.mid(0x1a, 2)); current->authSeq = qFromLittleEndian(r.mid(0x06, 2)); - current->tokenTx = (quint16)rand(); + current->tokenRx = qFromLittleEndian(r.mid(0x1a, 2)); + current->tokenTx = (quint32)(quint8)rand() | (quint8)rand() << 8 | (quint8) rand << 16 | (quint16)rand() << 24; if (userOk) { sendLoginResponse(current, true); @@ -251,6 +251,8 @@ void udpServer::civReceived() while (udpCiv->hasPendingDatagrams()) { QNetworkDatagram datagram = udpCiv->receiveDatagram(); QByteArray r = datagram.data(); + qDebug() << "CIV Data from :" << datagram.senderAddress().toString() << ":" << QString::number(datagram.senderPort()); + } } @@ -259,6 +261,7 @@ void udpServer::audioReceived() while (udpAudio->hasPendingDatagrams()) { QNetworkDatagram datagram = udpAudio->receiveDatagram(); QByteArray r = datagram.data(); + qDebug() << "Audio Data from :" << datagram.senderAddress().toString() << ":" << QString::number(datagram.senderPort()); } } @@ -290,22 +293,22 @@ void udpServer::sendPing(CLIENT* c, quint16 seq, bool reply) //qDebug() << c->ipAddress.toString() << ": Sending Ping"; quint32 pingSeq = 0; - quint16 sendSeq = seq; if (reply) { pingSeq = c->rxPingSeq; } else { - pingSeq = (quint32)((quint16)rand() << 16) | c->innerPingSeq; - sendSeq = c->pingSeq; + pingSeq = (quint32)((quint8)(rand() & 0xff)) | (quint16)c->innerPingSeq << 8 | (quint8)0x06 << 24; + seq = c->pingSeq; } // First byte of pings "from" server is 0x00 NOT packet length! // - const quint8 p[] = { 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,static_cast(sendSeq & 0xff),static_cast(sendSeq >>8 & 0xff), + const quint8 p[] = { 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,static_cast(seq & 0xff),static_cast(seq >>8 & 0xff), static_cast(c->myId & 0xff), static_cast(c->myId >>8 & 0xff), static_cast(c->myId >>16 & 0xff), static_cast(c->myId >>24 & 0xff), static_cast(c->remoteId & 0xff), static_cast(c->remoteId >> 8 & 0xff), static_cast(c->remoteId >> 16 & 0xff), static_cast(c->remoteId >>24 & 0xff), static_cast(reply), static_cast(pingSeq & 0xff), static_cast(pingSeq >> 8 & 0xff), static_cast(pingSeq >> 16 & 0xff), static_cast(pingSeq >>24 & 0xff) }; + c->innerPingSeq++; c->socket->writeDatagram(QByteArray::fromRawData((const char*)p, sizeof(p)), c->ipAddress, c->port); return; @@ -313,11 +316,13 @@ void udpServer::sendPing(CLIENT* c, quint16 seq, bool reply) void udpServer::sendIdle(CLIENT* c, quint16 seq) { + if (seq == 0x00) { seq = c->txSeq; c->txSeq++; } + const quint8 p[] = { 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,static_cast(seq & 0xff),static_cast(seq >>8 & 0xff), static_cast(c->myId & 0xff), static_cast(c->myId >> 8 & 0xff), static_cast(c->myId >>16 & 0xff), static_cast(c->myId >>24 & 0xff), @@ -335,7 +340,10 @@ void udpServer::sendLoginResponse(CLIENT* c,bool allowed) static_cast(c->myId & 0xff), static_cast(c->myId >> 8 & 0xff), static_cast(c->myId >> 16 & 0xff), static_cast(c->myId >> 24 & 0xff), static_cast(c->remoteId & 0xff), static_cast(c->remoteId >> 8 & 0xff), static_cast(c->remoteId >> 16 & 0xff), static_cast(c->remoteId >> 24 & 0xff), /*0x10*/ 0x00, 0x00, 0x00, 0x50, 0x02, 0x00, 0x00, - static_cast(c->authInnerSeq & 0xff), static_cast(c->authInnerSeq >> 8 & 0xff), 0x00, static_cast(c->tokenRx >> 0 & 0xff), static_cast(c->tokenRx >> 8 & 0xff), 0x00, 0x00, static_cast(c->tokenTx & 0xff), static_cast(c->tokenTx >> 8 & 0xff), + static_cast(c->authInnerSeq & 0xff), static_cast(c->authInnerSeq >> 8 & 0xff), 0x00, + static_cast(c->tokenRx >> 0 & 0xff), static_cast(c->tokenRx >> 8 & 0xff), + static_cast(c->tokenTx & 0xff), static_cast(c->tokenTx >> 8 & 0xff), + static_cast(c->tokenTx >> 16 & 0xff), static_cast(c->tokenTx >> 24 & 0xff), /*0x20*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*0x30*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*0x40*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -365,7 +373,10 @@ void udpServer::sendCapabilities(CLIENT* c) static_cast(c->myId & 0xff), static_cast(c->myId >> 8 & 0xff), static_cast(c->myId >> 16 & 0xff), static_cast(c->myId >>24 & 0xff), static_cast(c->remoteId & 0xff), static_cast(c->remoteId >> 8 & 0xff), static_cast(c->remoteId >> 16 & 0xff), static_cast(c->remoteId >>24 & 0xff), /*0x10*/ 0x00, 0x00, 0x00, 0x98, 0x02, 0x02, 0x00, - static_cast(c->authInnerSeq & 0xff), static_cast(c->authInnerSeq >>8 & 0xff), 0x00, static_cast(c->tokenRx & 0xff), static_cast(c->tokenRx >>8 & 0xff), 0x00, 0x00, static_cast(c->tokenTx & 0xff), static_cast(c->tokenTx >> 8 & 0xff), + static_cast(c->authInnerSeq & 0xff), static_cast(c->authInnerSeq >> 8 & 0xff), 0x00, + static_cast(c->tokenRx >> 0 & 0xff), static_cast(c->tokenRx >> 8 & 0xff), + static_cast(c->tokenTx & 0xff), static_cast(c->tokenTx >> 8 & 0xff), + static_cast(c->tokenTx >> 16 & 0xff), static_cast(c->tokenTx >> 24 & 0xff), /*0x20*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*0x30*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*0x40*/ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x80, 0x00, 0x00, 0x90, 0xc7, 0x00, @@ -380,10 +391,11 @@ void udpServer::sendCapabilities(CLIENT* c) // 0x90-0xa8 contains lots of seemingly random data, radio info? //memcpy(p + 0x4d, QByteArrayLiteral("\x08\x7a\x55").constData(), 3); // IC7851 - //p[0x94] = (char)0x8e; // IC-7851 + //p[0x94] = (char)0x8e; // IC-7851 C-IV address + memcpy(p + 0x4d, QByteArrayLiteral("\x0b\xe7\x64").constData(), 3); // IC9700 - p[0x94] = (char)0xa2; // IC-9700 - + p[0x94] = (char)0xa2; // IC-9700 C-IV address + memcpy(p + 0x52, QByteArrayLiteral("IC-9700").constData(), 7); memcpy(p + 0x72, QByteArrayLiteral("ICOM_VAUDIO").constData(), 11); @@ -401,7 +413,10 @@ void udpServer::sendConnectionInfo(CLIENT* c) static_cast(c->myId & 0xff), static_cast(c->myId >> 8 & 0xff), static_cast(c->myId >>16 & 0xff), static_cast(c->myId >> 24 & 0xff), static_cast(c->remoteId & 0xff), static_cast(c->remoteId >> 8 & 0xff), static_cast(c->remoteId >> 16 & 0xff), static_cast(c->remoteId >>24 & 0xff), /*0x10*/ 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, - static_cast(c->authInnerSeq & 0xff), static_cast(c->authInnerSeq >>8 & 0xff), 0x00, static_cast(c->tokenRx & 0xff), static_cast(c->tokenRx >>8 & 0xff), 0x00, 0x00, static_cast(c->tokenTx & 0xff), static_cast(c->tokenTx >> 8 & 0xff), + static_cast(c->authInnerSeq & 0xff), static_cast(c->authInnerSeq >> 8 & 0xff), 0x00, + static_cast(c->tokenRx >> 0 & 0xff), static_cast(c->tokenRx >> 8 & 0xff), + static_cast(c->tokenTx & 0xff), static_cast(c->tokenTx >> 8 & 0xff), + static_cast(c->tokenTx >> 16 & 0xff), static_cast(c->tokenTx >> 24 & 0xff), /*0x20*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x80, 0x00, 0x00, 0x90, 0xc7, 0x08, 0x7a, 0x55, /*0x30*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*0x40*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -412,7 +427,8 @@ void udpServer::sendConnectionInfo(CLIENT* c) }; // 0x1a-0x1f is authid (random number? - memcpy(p + 0x40, QByteArrayLiteral("IC-7851").constData(), 7); + //memcpy(p + 0x40, QByteArrayLiteral("IC-7851").constData(), 7); + memcpy(p + 0x40, QByteArrayLiteral("IC-9700").constData(), 7); c->authInnerSeq++; c->txSeq++; @@ -423,16 +439,15 @@ void udpServer::sendConnectionInfo(CLIENT* c) void udpServer::sendTokenRenewal(CLIENT* c, quint16 seq) { - if (seq == 0x00) - { - seq = c->authInnerSeq; - } qDebug() << c->ipAddress.toString() << ": Sending Token renwal"; quint8 p[] = { 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, static_cast(c->txSeq & 0xff), static_cast(c->txSeq >> 8 & 0xff), static_cast(c->myId & 0xff), static_cast(c->myId >> 8 & 0xff), static_cast(c->myId >> 16 & 0xff), static_cast(c->myId >> 24 & 0xff), static_cast(c->remoteId & 0xff), static_cast(c->remoteId >> 8 & 0xff), static_cast(c->remoteId >> 16 & 0xff), static_cast(c->remoteId >> 24 & 0xff), /*0x10*/ 0x00, 0x00, 0x00, 0x30, 0x02, 0x05, 0x00, - static_cast(seq & 0xff), static_cast(seq >> 8 & 0xff), 0x00, static_cast(c->tokenRx >> 0 & 0xff), static_cast(c->tokenRx >> 8 & 0xff), 0x00, 0x00, static_cast(c->tokenTx & 0xff), static_cast(c->tokenTx >> 8 & 0xff), + static_cast(c->authInnerSeq & 0xff), static_cast(c->authInnerSeq >> 8 & 0xff), 0x00, + static_cast(c->tokenRx >> 0 & 0xff), static_cast(c->tokenRx >> 8 & 0xff), + static_cast(c->tokenTx & 0xff), static_cast(c->tokenTx >> 8 & 0xff), + static_cast(c->tokenTx >> 16 & 0xff), static_cast(c->tokenTx >> 24 & 0xff), /*0x20*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*0x30*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/udpserver.h b/udpserver.h index 3bc0125..5b22e1f 100644 --- a/udpserver.h +++ b/udpserver.h @@ -49,10 +49,10 @@ private: quint32 rxPingSeq; // 32bit as has other info quint16 authInnerSeq; quint16 authSeq; - quint32 innerPingSeq; + quint16 innerPingSeq; quint16 innerSeq; quint16 tokenRx; - quint16 tokenTx; + quint32 tokenTx; QUdpSocket* socket; QTimer* pingTimer; diff --git a/udpserversetup.cpp b/udpserversetup.cpp index 785d55c..5ae61f5 100644 --- a/udpserversetup.cpp +++ b/udpserversetup.cpp @@ -31,7 +31,6 @@ void udpServerSetup::receiveServerConfig(SERVERCONFIG conf) { if (ui->usersTable->rowCount() <= row) { ui->usersTable->insertRow(ui->usersTable->rowCount()); - ui->usersTable->setHorizontalHeaderItem(ui->usersTable->rowCount() - 1, new QTableWidgetItem("User " + QString::number(row + 1))); } ui->usersTable->setItem(row, 0, new QTableWidgetItem(user.username)); ui->usersTable->setItem(row, 1, new QTableWidgetItem(user.password)); @@ -42,6 +41,8 @@ void udpServerSetup::receiveServerConfig(SERVERCONFIG conf) { ui->usersTable->removeRow(count); } + ui->usersTable->insertRow(ui->usersTable->rowCount()); + //ui->usersTable->setHorizontalHeaderItem(ui->usersTable->rowCount() - 1, new QTableWidgetItem("User " + QString::number(row + 1))); } @@ -58,12 +59,29 @@ void udpServerSetup::accept() for (int row = 0; row < ui->usersTable->model()->rowCount(); row++) { - SERVERUSER user; - user.username = ui->usersTable->item(row, 0)->text(); - user.password = ui->usersTable->item(row, 1)->text(); - config.users.append(user); + if (ui->usersTable->item(row, 0) != NULL && ui->usersTable->item(row, 1) != NULL) + { + SERVERUSER user; + user.username = ui->usersTable->item(row, 0)->text(); + user.password = ui->usersTable->item(row, 1)->text(); + config.users.append(user); + + } + else { + ui->usersTable->removeRow(row); + } } emit serverConfig(config,true); this->hide(); } + + +void udpServerSetup::on_usersTable_cellClicked(int row, int col) +{ + qDebug() << "Clicked on " << row << "," << col; + if (row == ui->usersTable->model()->rowCount() - 1 && ui->usersTable->item(row, 0) != NULL && ui->usersTable->item(row, 1) != NULL) { + ui->usersTable->insertRow(ui->usersTable->rowCount()); + } + +} \ No newline at end of file diff --git a/udpserversetup.h b/udpserversetup.h index 0c10361..b144761 100644 --- a/udpserversetup.h +++ b/udpserversetup.h @@ -32,6 +32,9 @@ public: explicit udpServerSetup(QWidget* parent = 0); ~udpServerSetup(); +private slots: + void on_usersTable_cellClicked(int row, int col); + public slots: void receiveServerConfig(SERVERCONFIG conf); diff --git a/udpserversetup.ui b/udpserversetup.ui index 5fcf2e4..a293138 100644 --- a/udpserversetup.ui +++ b/udpserversetup.ui @@ -7,7 +7,7 @@ 0 0 368 - 262 + 341 @@ -143,7 +143,7 @@ - + 0 0 @@ -193,56 +193,6 @@ false - - - User 1 - - - - - User 2 - - - - - User 3 - - - - - User 4 - - - - - User 5 - - - - - User 6 - - - - - User 7 - - - - - User 8 - - - - - User 9 - - - - - User 10 - - Username @@ -260,19 +210,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - -