Skip to content

Commit

Permalink
#1399 Resolves device ID parsing issue for Motorola ARS Device Regist…
Browse files Browse the repository at this point in the history
…ration. (#1400)

Co-authored-by: Dennis Sheirer <[email protected]>
  • Loading branch information
DSheirer and Dennis Sheirer authored Jan 6, 2023
1 parent e4a85a4 commit 8ce8aad
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 63 deletions.
77 changes: 59 additions & 18 deletions src/main/java/io/github/dsheirer/bits/BinaryMessage.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2023 Dennis Sheirer
*
* * ******************************************************************************
* * Copyright (C) 2014-2019 Dennis Sheirer
* *
* * 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
* * 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 free software: you can redistribute it and/or modify
* 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/>
* ****************************************************************************
*/
package io.github.dsheirer.bits;

import io.github.dsheirer.edac.CRC;
import java.util.BitSet;
import org.apache.commons.lang3.Validate;
import org.apache.commons.math3.util.FastMath;

import java.util.BitSet;

public class BinaryMessage extends BitSet
{
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -1038,6 +1034,51 @@ public static BinaryMessage load(String message)
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.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* ******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2018 Dennis Sheirer
* *****************************************************************************
* Copyright (C) 2014-2023 Dennis Sheirer
*
* 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
Expand All @@ -15,7 +14,7 @@
*
* 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.module.decode.ip.ars;
Expand All @@ -25,11 +24,10 @@
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.ARSUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Automatic Registration Service - Device Registration
Expand Down Expand Up @@ -176,7 +174,7 @@ private void parsePayload()

pointer += 8;

if(deviceIdentifierSize > 0)
if(deviceIdentifierSize > 0 && deviceIdentifierSize < 8)
{
StringBuilder sb = new StringBuilder();

Expand All @@ -186,21 +184,13 @@ private void parsePayload()
pointer += 8;
}

try
{
int device = Integer.parseInt(sb.toString());
mDevice = ARSDevice.createFrom(device);
}
catch(Exception e)
{
mLog.error("Error parsing ARS device identifier from value [" + sb.toString() + "]");
}
mDevice = ARSDevice.createFrom(sb.toString());
}

int userIdentifierSize = getMessage().getInt(BYTE_VALUE, pointer);
pointer += 8;

if(userIdentifierSize > 0)
if(userIdentifierSize > 0 && userIdentifierSize < 8)
{
StringBuilder sb = new StringBuilder();

Expand All @@ -216,7 +206,7 @@ private void parsePayload()
int passwordSize = getMessage().getInt(BYTE_VALUE, pointer);
pointer += 8;

if(passwordSize > 0)
if(passwordSize > 0 && passwordSize < 8)
{
StringBuilder sb = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* ******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2018 Dennis Sheirer
* *****************************************************************************
* Copyright (C) 2014-2023 Dennis Sheirer
*
* 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
Expand All @@ -15,7 +14,7 @@
*
* 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.module.decode.ip.ars;
Expand All @@ -25,11 +24,10 @@
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.ARSUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UserRegistration extends ARSHeader
{
Expand Down Expand Up @@ -108,7 +106,7 @@ private void parsePayload()

pointer += 8;

if(deviceIdentifierSize > 0)
if(deviceIdentifierSize > 0 && deviceIdentifierSize < 8)
{
StringBuilder sb = new StringBuilder();

Expand All @@ -118,22 +116,13 @@ private void parsePayload()
pointer += 8;
}

try
{
int device = Integer.parseInt(sb.toString());
mDevice = ARSDevice.createFrom(device);
}
catch(Exception e)
{
//Abort processing
return;
}
mDevice = ARSDevice.createFrom(sb.toString());
}

int userIdentifierSize = getMessage().getInt(BYTE_VALUE, pointer);
pointer += 8;

if(userIdentifierSize > 0)
if(userIdentifierSize > 0 && deviceIdentifierSize < 8)
{
StringBuilder sb = new StringBuilder();

Expand All @@ -149,7 +138,7 @@ private void parsePayload()
int passwordSize = getMessage().getInt(BYTE_VALUE, pointer);
pointer += 8;

if(passwordSize > 0)
if(passwordSize > 0 && passwordSize < 8)
{
StringBuilder sb = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
@@ -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
* it under the terms of the GNU General Public License as published by
Expand All @@ -22,20 +22,20 @@
import io.github.dsheirer.identifier.Form;
import io.github.dsheirer.identifier.IdentifierClass;
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;

/**
* Automatic Registration Service - Device Identifier
*/
public class ARSDevice extends IntegerIdentifier
public class ARSDevice extends StringIdentifier
{
/**
* Constructs an instance
* @param value of the device identifier
* @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);
}
Expand All @@ -49,15 +49,15 @@ public Protocol getProtocol()
/**
* 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);
}

/**
* 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);
}
Expand Down

0 comments on commit 8ce8aad

Please sign in to comment.