Commit 85992be5 authored by garciay's avatar garciay
Browse files

Add its_aid port information in GeoNetworkingReq

Add Commsignia support
parent 11296813
...@@ -353,7 +353,6 @@ public class SecurityHelper { ...@@ -353,7 +353,6 @@ public class SecurityHelper {
if ( if (
(p_headerfields[signerInfoTypeIndex] != 0x24) && // CAM (p_headerfields[signerInfoTypeIndex] != 0x24) && // CAM
(p_headerfields[signerInfoTypeIndex] != 0x25) && // DENM (p_headerfields[signerInfoTypeIndex] != 0x25) && // DENM
// TODO Add MAPEM/SPATEM, IVIM & SREM/SSEM
(p_headerfields[signerInfoTypeIndex] != p_itsAidOther) (p_headerfields[signerInfoTypeIndex] != p_itsAidOther)
) { ) {
if (p_enforceSecurityCheck) { if (p_enforceSecurityCheck) {
...@@ -365,9 +364,23 @@ public class SecurityHelper { ...@@ -365,9 +364,23 @@ public class SecurityHelper {
//TERFactory.getInstance().logDebug("SecurityHelper.checkHeaderfields: ItsAid=" + p_headerfields[signerInfoTypeIndex]); //TERFactory.getInstance().logDebug("SecurityHelper.checkHeaderfields: ItsAid=" + p_headerfields[signerInfoTypeIndex]);
lowerInfo.put(SecurityHelper.SEC_ITS_AID, ByteHelper.intToByteArray(p_headerfields[signerInfoTypeIndex], Integer.SIZE / Byte.SIZE)); lowerInfo.put(SecurityHelper.SEC_ITS_AID, ByteHelper.intToByteArray(p_headerfields[signerInfoTypeIndex], Integer.SIZE / Byte.SIZE));
signerInfoTypeIndex += 1; signerInfoTypeIndex += 1;
} else { } else { // FIXME To be refined
// FIXME to be continued signerInfoTypeIndex += 1;
if (
(p_headerfields[signerInfoTypeIndex] != 0x89) && // SPATEM
(p_headerfields[signerInfoTypeIndex] != 0x8a) && // MAPEM
(p_headerfields[signerInfoTypeIndex] != 0x8b) && // IVIM
(p_headerfields[signerInfoTypeIndex] != 0x8c) // SREM/SSEM
) {
if (p_enforceSecurityCheck) {
// Drop it
//TERFactory.getInstance().logError("SecurityHelper.checkHeaderfields: Drop packet - Unknown ItsAid value");
return false;
}
}
//TERFactory.getInstance().logDebug("SecurityHelper.checkHeaderfields: ItsAid=" + p_headerfields[signerInfoTypeIndex]);
lowerInfo.put(SecurityHelper.SEC_ITS_AID, ByteHelper.intToByteArray(p_headerfields[signerInfoTypeIndex], Integer.SIZE / Byte.SIZE));
signerInfoTypeIndex += 1;
} }
} }
} }
......
package org.etsi.its.adapter.layers;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import java.util.concurrent.TimeoutException;
import org.etsi.adapter.TERFactory;
import org.etsi.common.ByteHelper;
import org.etsi.its.adapter.IManagementLayers;
import com.commsignia.v2x.client.ITSApplication;
import com.commsignia.v2x.client.ITSEventAdapter;
import com.commsignia.v2x.client.MessageSet;
import com.commsignia.v2x.client.exception.ClientException;
import com.commsignia.v2x.client.model.BTPType;
import com.commsignia.v2x.client.model.GNNotification;
import com.commsignia.v2x.client.model.GeonetSendData;
import com.commsignia.v2x.client.model.InjectData;
import com.commsignia.v2x.client.model.InjectData.Builder;
import com.commsignia.v2x.client.model.InjectData.Type;
import com.commsignia.v2x.client.model.WsmpNotification;
import com.commsignia.v2x.client.model.WsmpSendData;
import com.commsignia.v2x.client.model.dev.DeviceId;
import com.commsignia.v2x.client.model.dev.DeviceInfoResponse;
import com.commsignia.v2x.client.model.dev.FacilityModule;
import rx.Observable;
import rx.Scheduler;
import rx.Scheduler.Worker;
public class CommsigniaLayer extends Layer {
/**
* Well-known Ethernet broadcast address
*/
public static byte[] MAC_BROADCAST = new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF};
/**
* Parameter name for Link-Layer destination
*/
public static final String LINK_LAYER_DESTINATION = "LinkLayerDestination";
/**
* Constructor
* @param management Layer management instance
* @param lowerStack Lower protocol stack
*/
public CommsigniaLayer(IManagementLayers management, Stack<String> lowerStack) {
super(management, lowerStack);
int its_aid = 5;
String targetHost = "172.17.15.38";
int targetPort = 7942;
MessageSet defaultMessageSet = MessageSet.C;
itsApplication = new ITSApplication(its_aid, targetHost, targetPort, defaultMessageSet);
try {
itsApplication.connect(1000);
itsApplication.registerBlocking();
DeviceInfoResponse deviceInfoResponse = itsApplication.requestDeviceInfoBlocking();
System.out.println(deviceInfoResponse);
itsApplication.setFacilityModuleStatus(FacilityModule.BSM, false);
itsApplication.setFacilityModuleStatus(FacilityModule.CAM, false);
itsApplication.addEventListener(new ITSEventAdapter() {
@Override
public void onGnNotification(GNNotification notification) {
ByteBuffer buffer = ByteBuffer.wrap(notification.getData());
System.out.printf("GN GBC receive. GN address: %s Sequence number: %d RSSI: %d dBm\n",
notification.getGNAddress(),
buffer.getInt(),
notification.getRssi()
);
}
});
itsApplication. gnBindBlocking(BTPType.NONE, 65535);
} catch (TimeoutException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.layers.Layer#register(org.etsi.its.adapter.layers.Layer)
*/
@Override
public void register(Layer upperLayer) {
if(registeredUpperLayer == null) {
super.register(upperLayer);
try {
Method getEthernetType = registeredUpperLayer.getClass().getMethod("getEthernetType", (Class<?>[])null);
if (getEthernetType != null) {
upperLayerFrameType = (Short) getEthernetType.invoke(registeredUpperLayer, (Object[]) null);
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
localMacAddress = management.getLinkLayerAddress();
}
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.layers.Layer#send(byte[], java.util.Map)
*/
@Override
public boolean send(byte[] message, Map<String, Object> params) {
TERFactory.getInstance().logDebug(">>> CommsigniaLayer.send: " + ByteHelper.byteArrayToString(message));
byte[] dst = (byte[])params.get(LINK_LAYER_DESTINATION);
if(dst == null) {
dst = MAC_BROADCAST;
}
byte[] packet = ByteHelper.concat(
dst,
localMacAddress,
ByteHelper.intToByteArray(upperLayerFrameType, 2),
message
);
try {
String dstAddress = String.format(
"%02x:%02x:%02x:%02x:%02x:%02x",
dst[0],
dst[1],
dst[2],
dst[3],
dst[4],
dst[5]);
String srcAddress = String.format(
"%02x:%02x:%02x:%02x:%02x:%02x",
localMacAddress[0],
localMacAddress[1],
localMacAddress[2],
localMacAddress[3],
localMacAddress[4],
localMacAddress[5]);
Builder build = new InjectData.Builder();
build
.withDstAddress(dstAddress)
.withSrcAddress(srcAddress)
.withType(Type.GNP)
.withInterfaceID(2)
.withData(message);
InjectData injectData = build.build();
TERFactory.getInstance().logDebug("CommsigniaLayer.send: " + ByteHelper.byteArrayToString(injectData.getData()));
itsApplication.sendOnRadioBlocking(injectData);
TERFactory.getInstance().logDebug("<<< GnLayer.send: " + ByteHelper.byteArrayToString(packet));
return super.send(packet, params);
} catch (ClientException e) {
e.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.layers.Layer#unregister(org.etsi.its.adapter.layers.Layer)
*/
@Override
public void unregister(Layer upperLayer) {
if (itsApplication != null) {
try {
itsApplication.gnCloseBlocking(BTPType.NONE, 65535);
itsApplication.deregisterBlocking();
} catch (ClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
itsApplication.shutdown();
itsApplication = null;
}
}
/**
* Local Ethernet address
*/
private byte[] localMacAddress;
/**
* Upper layer's frame type
*/
private short upperLayerFrameType;
private ITSApplication itsApplication = null;
}
...@@ -20,7 +20,7 @@ import org.etsi.its.adapter.PcapMultiplexer; ...@@ -20,7 +20,7 @@ import org.etsi.its.adapter.PcapMultiplexer;
* Implementation of Ethernet layer using jpcap (background thread) * Implementation of Ethernet layer using jpcap (background thread)
*/ */
public class EthernetLayer extends Layer { public class EthernetLayer extends Layer {
/** /**
* Well-known Ethernet broadcast address * Well-known Ethernet broadcast address
*/ */
......
...@@ -296,7 +296,7 @@ public class GnLayer extends Layer implements Runnable, IEthernetSpecific { ...@@ -296,7 +296,7 @@ public class GnLayer extends Layer implements Runnable, IEthernetSpecific {
if (!management.isSecuredModeSet()) { // Secure mode disabled if (!management.isSecuredModeSet()) { // Secure mode disabled
toBeSent = ByteHelper.concat(basicHdr, commonHdr, extHdr, message); toBeSent = ByteHelper.concat(basicHdr, commonHdr, extHdr, message);
} else { } else {
toBeSent = createSecuredMessage(basicHdr, commonHdr, extHdr, message); toBeSent = createSecuredMessage(basicHdr, commonHdr, extHdr, message, params);
} }
//TERFactory.getInstance().logDebug("<<< GnLayer.send: " + ByteHelper.byteArrayToString(toBeSent)); //TERFactory.getInstance().logDebug("<<< GnLayer.send: " + ByteHelper.byteArrayToString(toBeSent));
...@@ -645,7 +645,7 @@ public class GnLayer extends Layer implements Runnable, IEthernetSpecific { ...@@ -645,7 +645,7 @@ public class GnLayer extends Layer implements Runnable, IEthernetSpecific {
return ByteHelper.concat(tsb, depv); return ByteHelper.concat(tsb, depv);
} }
private byte[] createSecuredMessage(final byte[] basicHdr, final byte[] commonHdr, final byte[] extHdr, final byte[] message) { private byte[] createSecuredMessage(final byte[] basicHdr, final byte[] commonHdr, final byte[] extHdr, final byte[] message, Map<String, Object> params) {
//TERFactory.getInstance().logDebug(">>> GnLayer.createSecuredMessage"); //TERFactory.getInstance().logDebug(">>> GnLayer.createSecuredMessage");
// SecuredMessage payload length // SecuredMessage payload length
...@@ -669,60 +669,73 @@ public class GnLayer extends Layer implements Runnable, IEthernetSpecific { ...@@ -669,60 +669,73 @@ public class GnLayer extends Layer implements Runnable, IEthernetSpecific {
generationTime // Time64 value generationTime // Time64 value
) )
); );
if ((commonHdr[0] & 0xF0) == 0x01) { // Next header = Btp-A int its_aid = -1;
switch ((int) params.get(BtpLayer.BTP_DSTPORT)) {
case 2001: // CAM
its_aid = 36;
break;
case 2002: // DENM
its_aid = 37;
break;
case 2003: // MAPEM
its_aid = 137;
break;
case 2004: // SPATEM
its_aid = 138;
break;
case 2006: // IVIM
its_aid = 140;
break;
case 2007: // SREM/SSEM
// No break;
case 2008:
its_aid = 140;
break;
} // End of 'switch' statement
if (its_aid == 36) { // CAM
headersField = ByteHelper.concat( headersField = ByteHelper.concat(
headersField, headersField,
new byte[] { new byte[] {
(byte)0x05, // its-aid (byte)0x05, // its-aid
(byte)0x24 // 36 = CAM (byte)its_aid // 36 = CAM
} }
); );
} else if ((commonHdr[0] & 0xF0) == 0x02) { // Next header = Btp-B } else if (its_aid == 37) { // DENM
headersField = ByteHelper.concat( headersField = ByteHelper.concat(
headersField, headersField,
new byte[] { new byte[] {
(byte)0x03 // GenerationLocation (byte)0x03 // GenerationLocation
}, },
management.getLatitude(), // Latitude management.getLatitude(), // Latitude
management.getLongitude(), // Longitude management.getLongitude(), // Longitude
new byte[] { (byte)0x00, (byte)0x00 }, // Elevation new byte[] { (byte)0x00, (byte)0x00 }, // Elevation
new byte[] { new byte[] {
(byte)0x05, // its-aid (byte)0x05, // its-aid
(byte)0x25 // 37 = DENM (byte)its_aid // 37 = DENM
} }
); );
} else { // Add Its-Aid for Other profile } else { // Add Its-Aid for Other profile
int itsAid = management.getItsAidOther();
byte[] b; byte[] b;
if (itsAid < 128) { if (its_aid < 128) {
b = new byte[] { (byte)itsAid }; b = new byte[] { (byte)its_aid };
} else if (itsAid < Short.MAX_VALUE) {
b = ByteHelper.intToByteArray(itsAid, Short.SIZE / Byte.SIZE);
b = ByteHelper.concat(
SecurityHelper.getInstance().size2tls(b.length),
b
);
} else { } else {
b = ByteHelper.intToByteArray(itsAid, Integer.SIZE / Integer.SIZE); b = SecurityHelper.getInstance().size2tls(its_aid);
b = ByteHelper.concat(
SecurityHelper.getInstance().size2tls(b.length),
b
);
} }
headersField = ByteHelper.concat( headersField = ByteHelper.concat(
headersField, headersField,
new byte[] { new byte[] {
(byte)0x03 // GenerationLocation (byte)0x03 // GenerationLocation
}, },
management.getLatitude(), // Latitude management.getLatitude(), // Latitude
management.getLongitude(), // Longitude management.getLongitude(), // Longitude
new byte[] { (byte)0x00, (byte)0x00 }, // Elevation new byte[] { (byte)0x00, (byte)0x00 }, // Elevation
new byte[] { new byte[] {
(byte)0x05 // Its-aid (byte)0x05 // Its-aid
}, },
b b // Other profile
); );
} }
byte[] payloadLengthTls = SecurityHelper.getInstance().size2tls(payloadLength);
byte[] toBeSignedData = ByteHelper.concat( byte[] toBeSignedData = ByteHelper.concat(
new byte[] { // SecuredMessage version new byte[] { // SecuredMessage version
(byte)0x02 // version (byte)0x02 // version
...@@ -731,8 +744,8 @@ public class GnLayer extends Layer implements Runnable, IEthernetSpecific { ...@@ -731,8 +744,8 @@ public class GnLayer extends Layer implements Runnable, IEthernetSpecific {
headersField, // HeaderFields headersField, // HeaderFields
new byte[] { // SecuredMessage Payloads new byte[] { // SecuredMessage Payloads
(byte)0x01, // Secured payload type: signed (1) (byte)0x01, // Secured payload type: signed (1)
(byte)payloadLength, // Data payload length
}, },
payloadLengthTls, // Data payload length
commonHdr, commonHdr,
extHdr, extHdr,
message, // End of SecuredMessage Payloads message, // End of SecuredMessage Payloads
......
...@@ -24,104 +24,104 @@ public abstract class Layer { ...@@ -24,104 +24,104 @@ public abstract class Layer {
public static final String RECEPTION_TIMESTAMP = "ReceptionTimestamp"; public static final String RECEPTION_TIMESTAMP = "ReceptionTimestamp";
/** /**
* Constructor * Constructor
* @param management Layer management instance * @param management Layer management instance
* @param lowerStack Lower protocol stack * @param lowerStack Lower protocol stack
*/ */
public Layer(IManagementLayers management, Stack<String> lowerStack) { public Layer(IManagementLayers management, Stack<String> lowerStack) {
this.management = management; this.management = management;
this.lowerStack = lowerStack; this.lowerStack = lowerStack;
this.initialized = false; this.initialized = false;
} }
/** /**
* Initialises lower stack * Initialises lower stack
*/ */
protected void initialize() { protected void initialize() {
if(!initialized && lowerStack != null && !lowerStack.isEmpty()) { if(!initialized && lowerStack != null && !lowerStack.isEmpty()) {
lowerLayerName = lowerStack.pop(); lowerLayerName = lowerStack.pop();
lowerLayer = LayerFactory.getInstance().createLayer(management, lowerLayerName, lowerStack); lowerLayer = LayerFactory.getInstance().createLayer(management, lowerLayerName, lowerStack);
lowerLayer.register(this); lowerLayer.register(this);
} }
initialized = true; initialized = true;
} }
/** /**
* Transmits a message to registered lower layer after encapsulation * Transmits a message to registered lower layer after encapsulation
* @param message Encoded message to be sent * @param message Encoded message to be sent
* @param params Layer parameters for sending message * @param params Layer parameters for sending message
* @return true if send operation is successful, false otherwise * @return true if send operation is successful, false otherwise
*/ */
public boolean send(byte[] message, Map<String, Object> params) { public boolean send(byte[] message, Map<String, Object> params) {
if(lowerLayer != null) { if(lowerLayer != null) {
return lowerLayer.send(message, params); return lowerLayer.send(message, params);
} }
return true; return true;
} }
/** /**
* Callback method invoked by registered lower layer upon message reception from lower stack * Callback method invoked by registered lower layer upon message reception from lower stack
* @param message Message received from lower layer * @param message Message received from lower layer
* @param lowerInfo Additional information transmitted by lower layers * @param lowerInfo Additional information transmitted by lower layers
* @param receptionTime Message reception time * @param receptionTime Message reception time
*/ */
public void receive(byte[] message, Map<String, Object> lowerInfo) { public void receive(byte[] message, Map<String, Object> lowerInfo) {
if(registeredUpperLayer != null) { if(registeredUpperLayer != null) {
registeredUpperLayer.receive(message, lowerInfo); registeredUpperLayer.receive(message, lowerInfo);
} }
} }
/** /**
* Registers an upper layer. * Registers an upper layer.
* This method will also cause current layer to initialise its lower stack * This method will also cause current layer to initialise its lower stack
* Messages received from lower layer will now be transmitted to upper layer, if necessary * Messages received from lower layer will now be transmitted to upper layer, if necessary
* @param upperLayer Instance of the upper layer * @param upperLayer Instance of the upper layer
*/ */
public void register(Layer upperLayer) { public void register(Layer upperLayer) {
registeredUpperLayer = upperLayer; registeredUpperLayer = upperLayer;
initialize(); initialize();
} }
/** /**
* Unregisters upper layer. * Unregisters upper layer.
* This method will also cause current layer to unregister from its lower layer * This method will also cause current layer to unregister from its lower layer
* @param upperLayer * @param upperLayer
*/ */
public void unregister(Layer upperLayer) { public void unregister(Layer upperLayer) {
registeredUpperLayer = null; registeredUpperLayer = null;
if(lowerLayer != null) { if(lowerLayer != null) {
lowerLayer.unregister(this); lowerLayer.unregister(this);
} }
} }
/** /**
* Name of the lower layer * Name of the lower layer
*/ */
protected String lowerLayerName; protected String lowerLayerName;