mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-14 17:47:32 -05:00
Co-authored-by: Dennis Sheirer <dsheirer@github.com>
This commit is contained in:
@@ -1,32 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* * ******************************************************************************
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* * Copyright (C) 2014-2019 Dennis Sheirer
|
* it under the terms of the GNU General Public License as published by
|
||||||
* *
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* * This program is free software: you can redistribute it and/or modify
|
* (at your option) any later version.
|
||||||
* * it under the terms of the GNU General Public License as published by
|
|
||||||
* * the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* * (at your option) any later version.
|
|
||||||
* *
|
|
||||||
* * This program is distributed in the hope that it will be useful,
|
|
||||||
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* * GNU General Public License for more details.
|
|
||||||
* *
|
|
||||||
* * You should have received a copy of the GNU General Public License
|
|
||||||
* * along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
* * *****************************************************************************
|
|
||||||
*
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
* ****************************************************************************
|
||||||
*/
|
*/
|
||||||
package io.github.dsheirer.bits;
|
package io.github.dsheirer.bits;
|
||||||
|
|
||||||
import io.github.dsheirer.edac.CRC;
|
import io.github.dsheirer.edac.CRC;
|
||||||
|
import java.util.BitSet;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
import org.apache.commons.math3.util.FastMath;
|
import org.apache.commons.math3.util.FastMath;
|
||||||
|
|
||||||
import java.util.BitSet;
|
|
||||||
|
|
||||||
public class BinaryMessage extends BitSet
|
public class BinaryMessage extends BitSet
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@@ -1038,6 +1034,51 @@ public class BinaryMessage extends BitSet
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the hexadecimal text into a binary message
|
||||||
|
* @param hex text to load from
|
||||||
|
* @return loaded binary message
|
||||||
|
*/
|
||||||
|
public static BinaryMessage loadHex(String hex)
|
||||||
|
{
|
||||||
|
if(!hex.matches("[0-9A-F]*"))
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Message must contain only 0-9 and A-F hexadecimal characters");
|
||||||
|
}
|
||||||
|
|
||||||
|
int length = hex.length() / 2;
|
||||||
|
|
||||||
|
if(length * 2 < hex.length())
|
||||||
|
{
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
|
||||||
|
BinaryMessage buffer = new BinaryMessage(length * 8);
|
||||||
|
|
||||||
|
int bufferOffset = 0;
|
||||||
|
for(int x = 0; x < hex.length(); x += 2)
|
||||||
|
{
|
||||||
|
int endIndex = x + 2;
|
||||||
|
if(endIndex > hex.length())
|
||||||
|
{
|
||||||
|
endIndex--;
|
||||||
|
}
|
||||||
|
|
||||||
|
String rawHex = hex.substring(x, endIndex);
|
||||||
|
|
||||||
|
if(rawHex.length() == 1)
|
||||||
|
{
|
||||||
|
rawHex = rawHex + "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
int value = Integer.parseInt(rawHex, 16);
|
||||||
|
buffer.setByte(bufferOffset, (byte)(value & 0xFF));
|
||||||
|
bufferOffset += 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Left rotates the bits between start and end indices, number of places.
|
* Left rotates the bits between start and end indices, number of places.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* ******************************************************************************
|
* *****************************************************************************
|
||||||
* sdrtrunk
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
* Copyright (C) 2014-2018 Dennis Sheirer
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -15,7 +14,7 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
* *****************************************************************************
|
* ****************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.github.dsheirer.module.decode.ip.ars;
|
package io.github.dsheirer.module.decode.ip.ars;
|
||||||
@@ -25,11 +24,10 @@ import io.github.dsheirer.identifier.Identifier;
|
|||||||
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSDevice;
|
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSDevice;
|
||||||
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSPassword;
|
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSPassword;
|
||||||
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSUser;
|
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSUser;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatic Registration Service - Device Registration
|
* Automatic Registration Service - Device Registration
|
||||||
@@ -176,7 +174,7 @@ public class DeviceRegistration extends ARSHeader
|
|||||||
|
|
||||||
pointer += 8;
|
pointer += 8;
|
||||||
|
|
||||||
if(deviceIdentifierSize > 0)
|
if(deviceIdentifierSize > 0 && deviceIdentifierSize < 8)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
@@ -186,21 +184,13 @@ public class DeviceRegistration extends ARSHeader
|
|||||||
pointer += 8;
|
pointer += 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
mDevice = ARSDevice.createFrom(sb.toString());
|
||||||
{
|
|
||||||
int device = Integer.parseInt(sb.toString());
|
|
||||||
mDevice = ARSDevice.createFrom(device);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
mLog.error("Error parsing ARS device identifier from value [" + sb.toString() + "]");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int userIdentifierSize = getMessage().getInt(BYTE_VALUE, pointer);
|
int userIdentifierSize = getMessage().getInt(BYTE_VALUE, pointer);
|
||||||
pointer += 8;
|
pointer += 8;
|
||||||
|
|
||||||
if(userIdentifierSize > 0)
|
if(userIdentifierSize > 0 && userIdentifierSize < 8)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
@@ -216,7 +206,7 @@ public class DeviceRegistration extends ARSHeader
|
|||||||
int passwordSize = getMessage().getInt(BYTE_VALUE, pointer);
|
int passwordSize = getMessage().getInt(BYTE_VALUE, pointer);
|
||||||
pointer += 8;
|
pointer += 8;
|
||||||
|
|
||||||
if(passwordSize > 0)
|
if(passwordSize > 0 && passwordSize < 8)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* ******************************************************************************
|
* *****************************************************************************
|
||||||
* sdrtrunk
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
* Copyright (C) 2014-2018 Dennis Sheirer
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -15,7 +14,7 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
* *****************************************************************************
|
* ****************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.github.dsheirer.module.decode.ip.ars;
|
package io.github.dsheirer.module.decode.ip.ars;
|
||||||
@@ -25,11 +24,10 @@ import io.github.dsheirer.identifier.Identifier;
|
|||||||
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSDevice;
|
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSDevice;
|
||||||
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSPassword;
|
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSPassword;
|
||||||
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSUser;
|
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSUser;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class UserRegistration extends ARSHeader
|
public class UserRegistration extends ARSHeader
|
||||||
{
|
{
|
||||||
@@ -108,7 +106,7 @@ public class UserRegistration extends ARSHeader
|
|||||||
|
|
||||||
pointer += 8;
|
pointer += 8;
|
||||||
|
|
||||||
if(deviceIdentifierSize > 0)
|
if(deviceIdentifierSize > 0 && deviceIdentifierSize < 8)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
@@ -118,22 +116,13 @@ public class UserRegistration extends ARSHeader
|
|||||||
pointer += 8;
|
pointer += 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
mDevice = ARSDevice.createFrom(sb.toString());
|
||||||
{
|
|
||||||
int device = Integer.parseInt(sb.toString());
|
|
||||||
mDevice = ARSDevice.createFrom(device);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
//Abort processing
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int userIdentifierSize = getMessage().getInt(BYTE_VALUE, pointer);
|
int userIdentifierSize = getMessage().getInt(BYTE_VALUE, pointer);
|
||||||
pointer += 8;
|
pointer += 8;
|
||||||
|
|
||||||
if(userIdentifierSize > 0)
|
if(userIdentifierSize > 0 && deviceIdentifierSize < 8)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
@@ -149,7 +138,7 @@ public class UserRegistration extends ARSHeader
|
|||||||
int passwordSize = getMessage().getInt(BYTE_VALUE, pointer);
|
int passwordSize = getMessage().getInt(BYTE_VALUE, pointer);
|
||||||
pointer += 8;
|
pointer += 8;
|
||||||
|
|
||||||
if(passwordSize > 0)
|
if(passwordSize > 0 && passwordSize < 8)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* *****************************************************************************
|
* *****************************************************************************
|
||||||
* Copyright (C) 2014-2020 Dennis Sheirer
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,20 +22,20 @@ package io.github.dsheirer.module.decode.ip.ars.identifier;
|
|||||||
import io.github.dsheirer.identifier.Form;
|
import io.github.dsheirer.identifier.Form;
|
||||||
import io.github.dsheirer.identifier.IdentifierClass;
|
import io.github.dsheirer.identifier.IdentifierClass;
|
||||||
import io.github.dsheirer.identifier.Role;
|
import io.github.dsheirer.identifier.Role;
|
||||||
import io.github.dsheirer.identifier.integer.IntegerIdentifier;
|
import io.github.dsheirer.identifier.string.StringIdentifier;
|
||||||
import io.github.dsheirer.protocol.Protocol;
|
import io.github.dsheirer.protocol.Protocol;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatic Registration Service - Device Identifier
|
* Automatic Registration Service - Device Identifier
|
||||||
*/
|
*/
|
||||||
public class ARSDevice extends IntegerIdentifier
|
public class ARSDevice extends StringIdentifier
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructs an instance
|
* Constructs an instance
|
||||||
* @param value of the device identifier
|
* @param value of the device identifier
|
||||||
* @param role of the device (TO/FROM)
|
* @param role of the device (TO/FROM)
|
||||||
*/
|
*/
|
||||||
public ARSDevice(int value, Role role)
|
public ARSDevice(String value, Role role)
|
||||||
{
|
{
|
||||||
super(value, IdentifierClass.USER, Form.ARS_DEVICE, role);
|
super(value, IdentifierClass.USER, Form.ARS_DEVICE, role);
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ public class ARSDevice extends IntegerIdentifier
|
|||||||
/**
|
/**
|
||||||
* Creates an ARS device with a FROM role
|
* Creates an ARS device with a FROM role
|
||||||
*/
|
*/
|
||||||
public static ARSDevice createFrom(int value)
|
public static ARSDevice createFrom(String value)
|
||||||
{
|
{
|
||||||
return new ARSDevice(value, Role.FROM);
|
return new ARSDevice(value, Role.FROM);
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ public class ARSDevice extends IntegerIdentifier
|
|||||||
/**
|
/**
|
||||||
* Creates an ARS device with a TO role
|
* Creates an ARS device with a TO role
|
||||||
*/
|
*/
|
||||||
public static ARSDevice createTo(int value)
|
public static ARSDevice createTo(String value)
|
||||||
{
|
{
|
||||||
return new ARSDevice(value, Role.TO);
|
return new ARSDevice(value, Role.TO);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user