}
@Override
- public void channelActive(ChannelHandlerContext ctx) {
- Device device = ctx.channel().attr(keyDevice).get();
- mDevicePool.addDevice(device);
- device.onConnected();
- // Authenticated device connected
- // Actual channel active should decided after authentication.
- CoapSignaling signaling = (CoapSignaling) MessageBuilder
- .createSignaling(SignalingMethod.CSM);
- signaling.setCsmMaxMessageSize(4294967295L);
- ctx.writeAndFlush(signaling);
- }
-
- @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
try {
if (msg instanceof CoapSignaling) {
+ if (mCsmMap.get(ctx) == null) {
+ // In the server, the CSM message is sent to the device
+ // once
+ CoapSignaling inicialCsm = (CoapSignaling) MessageBuilder
+ .createSignaling(SignalingMethod.CSM);
+ inicialCsm.setCsmMaxMessageSize(4294967295L);
+ ctx.writeAndFlush(inicialCsm);
+ }
CoapSignaling signaling = (CoapSignaling) msg;
switch (signaling.getSignalingMethod()) {
case CSM:
}
public void setCsmServerName(String serverName) {
- addOption(1, serverName.getBytes(StandardCharsets.UTF_8));
+ if (serverName != null && !serverName.isEmpty()) {
+ addOption(1, serverName.getBytes(StandardCharsets.UTF_8));
+ }
}
public void setCsmMaxMessageSize(long maxMessageSize) {
- ByteBuffer buf = ByteBuffer.wrap(new byte[4]);
- max_message_size = buf.putInt(0, (int) maxMessageSize).array();
+ if (maxMessageSize != 0) {
+ ByteBuffer buf = ByteBuffer.wrap(new byte[4]);
+ max_message_size = buf.putInt(0, (int) maxMessageSize).array();
+ }
}
public void setCsmBlockWiseTransfer(boolean blockWiseTransferOption) {
public String getCsmServerName() {
if (server_name == null)
- return "";
+ return new String();
return new String(server_name, Charset.forName("UTF-8"));
}
}
private static final long unsignedIntToLong(byte[] b) {
- long value = 0;
- for (byte data : b) {
- value <<= 8;
- value += data & 0xFF;
+ long value = 0L;
+ if (b != null) {
+ for (byte data : b) {
+ value <<= 8;
+ value += data & 0xFF;
+ }
}
return value;
}