Rev

Rev 2511 | Details | Compare with Previous | Last modification | View Log | SVN | Bug Tracker

Rev Author Line No. Line
2465 garciay 1
package org.etsi.its.adapter.ports;
2
 
3
import java.util.HashMap;
4
import java.util.Map;
5
 
2497 garciay 6
import org.etsi.adapter.TERFactory;
2465 garciay 7
import org.etsi.common.ByteHelper;
8
import org.etsi.its.adapter.SecurityHelper;
9
import org.etsi.its.adapter.layers.BtpLayer;
10
import org.etsi.its.adapter.layers.GnLayer;
11
 
12
public class SremSsemPort extends ProtocolPort {
13
 
14
    /**
15
     * Constructor
16
     * @param   portName        Name of the port
17
     * @param   componentName   Name of the component owning this port instance
18
     * @param   lowerStackDesc  Description of the port's lower stack in the form "Layer/Layer/Layer/..."
19
     * @param  linkLayerAddress    Link-layer address to be used by this port as source address (null if not applicable)
20
     */
21
    public SremSsemPort(String portName, String componentName, String lowerStackDesc, String linkLayerAddress) {
22
        super(portName, componentName, lowerStackDesc, linkLayerAddress);
23
    }
24
 
25
    /* (non-Javadoc)
26
     * @see org.etsi.its.adapter.ports.ProtocolPort#receive(byte[], java.util.Map)
27
     */
28
    @Override
29
    public void receive(byte[] message, Map<String, Object> lowerInfo) {
2497 garciay 30
//      TERFactory.getInstance().logDebug(">>> SremSsemPort.receive: " + ByteHelper.byteArrayToString(message));
2465 garciay 31
 
2497 garciay 32
        if ((message[1] != 0x09) && (message[1] != 0x0A)) { // Check that received packet has SREM/SSEM message id - See ETSI TS 102 894
33
            TERFactory.getInstance().logDebug("SremSsemPort.receive: drop packet " + ByteHelper.byteArrayToString(message));
34
            return; // Drop it
35
        }
36
 
37
        // Encode with SREM/SSEM indication header
2465 garciay 38
        byte[] msgInd = ByteHelper.concat(
39
            message,
40
            new byte[] { (Byte) lowerInfo.get(GnLayer.GN_NEXTHEADER) },
41
            ByteHelper.intToByteArray((Integer) lowerInfo.get(GnLayer.GN_TYPE), 1),
42
            ByteHelper.intToByteArray((Integer) lowerInfo.get(GnLayer.GN_SUBTYPE), 1),
43
            ByteHelper.intToByteArray((Integer) lowerInfo.get(GnLayer.GN_LIFETIME), Integer.SIZE / Byte.SIZE),
44
            ByteHelper.intToByteArray((Integer) lowerInfo.get(GnLayer.GN_TRAFFICCLASS), 1),
45
            (byte[]) lowerInfo.get(BtpLayer.BTP_DSTPORT),
46
            (byte[]) lowerInfo.get(BtpLayer.BTP_DSTPORTINFO)
47
        );
48
        // Add security info to pass to the ATS
49
        if (lowerInfo.get(SecurityHelper.SEC_SSP) == null) {
2511 garciay 50
            byte[] buf = new byte[32];
2465 garciay 51
            msgInd = ByteHelper.concat(msgInd, buf);
52
        } else {
53
            msgInd = ByteHelper.concat(msgInd, (byte[])lowerInfo.get(SecurityHelper.SEC_SSP));
54
        }
55
        if (lowerInfo.get(SecurityHelper.SEC_ITS_AID) == null) { // It shall not be possible to have SSP absent and ATS_AID present but...
56
            msgInd = ByteHelper.concat(msgInd, new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 });
57
 
58
        } else {
59
            msgInd = ByteHelper.concat(msgInd, (byte[])lowerInfo.get(SecurityHelper.SEC_ITS_AID));
60
        }
61
        super.receive(msgInd, lowerInfo);
62
    }
63
 
64
    /* (non-Javadoc)
65
     * @see org.etsi.its.adapter.ports.IPort#send(byte[])
66
     */
67
    @Override
68
    public boolean send(byte[] message) {
69
 
70
        HashMap<String, Object> params = new HashMap<String, Object>();
71
        params.put(BtpLayer.BTP_TYPE, BtpLayer.TYPE_B);
72
        if (message[1] == 0x9) { // SREM, see ITS-Container
73
            params.put(BtpLayer.BTP_DSTPORT, 2007);
74
        } else if (message[1] == 0xa) { // SSEM, see ITS-Container
75
            params.put(BtpLayer.BTP_DSTPORT, 2008);
76
        } else {
77
            params.put(BtpLayer.BTP_DSTPORT, 0);
78
        }
79
        params.put(BtpLayer.BTP_SRCPORT, 0);
80
        params.put(GnLayer.GN_TYPE, GnLayer.HT_TSB);
81
        params.put(GnLayer.GN_SUBTYPE, GnLayer.HST_MULTIHOP);
82
        params.put(GnLayer.GN_LATITUDE, ByteHelper.byteArrayToLong(management.getLatitude()));
83
        params.put(GnLayer.GN_LONGITUDE, ByteHelper.byteArrayToLong(management.getLongitude()));
84
        params.put(GnLayer.GN_NEXTHEADER, "BTP-B");
85
        return send(message, params);
86
    }
87
} // End of class MapSpatPort
88