Merge "nci_packets: Bitfield order is corrected and LCM commands added"
diff --git a/src/nci_packets.pdl b/src/nci_packets.pdl
index 2df63a4..3b1aac7 100644
--- a/src/nci_packets.pdl
+++ b/src/nci_packets.pdl
@@ -12,7 +12,7 @@
   NOTIFICATION = 3,
 }
 
-enum GroupAndOpcode : 12 {
+enum Opcode : 8 {
   CORE_RESET = 0x0,
   CORE_INIT = 0x1,
   CORE_SET_CONFIG = 0x2,
@@ -74,17 +74,18 @@
 }
 
 packet Nci {
-  mt : NciMsgType,
+  gid : 4,
   pbf : PacketBoundaryFlag,
-  op : GroupAndOpcode,
+  mt : NciMsgType,
+  op : Opcode,
   _size_(_payload_) : 8,
   _payload_,
 }
 
 packet Data {
-  _fixed_ =  0x0 : 3,
-  pbf : PacketBoundaryFlag,
   conn_id : 4,
+  pbf : PacketBoundaryFlag,
+  _fixed_ =  0x0 : 3,
   cr : 8,
   _size_(_payload_) : 8,
   _payload_,
@@ -315,3 +316,90 @@
   _count_(params) : 8,
   params : ConfigParams[],
 }
+
+enum RfProtocols : 8 {
+  PROTOCOL_UNDETERMINED = 0x00,
+  PROTOCOL_T1T = 0x01,
+  PROTOCOL_T2T = 0x02,
+  PROTOCOL_T3T = 0x03,
+  PROTOCOL_ISO_DEP = 0x04,
+  PROTOCOL_NFC_DEP = 0x05,
+  PROTOCOL_T5T = 0x06,
+  PROTOCOL_NDEF = 0x07,
+}
+
+enum NfceeProtocols : 8 {
+  APDU = 0x00,
+  RFU = 0x01,
+  T3CS = 0x02,
+  TRANSPARENT = 0x04,
+}
+
+enum DestTypes : 8 {
+  RFU = 0x00,
+  NFCC_LPBK = 0x01,
+  REMOTE = 0x02,
+  NFCEE = 0x03,
+}
+
+enum DestParamTypes : 8 {
+  RF_DISC = 0x00,
+  NFCEE = 0x01,
+}
+
+struct RfDiscType {
+  id : 8,
+  proto: RfProtocols,
+}
+
+struct NfceeType {
+  id : 8,
+  proto : NfceeProtocols,
+}
+
+struct DestParams {
+  ptype : DestParamTypes,
+  _size_(valdsp) : 8,
+  valdsp : 8[],
+}
+
+packet ConnCreateCommand : Nci (mt = COMMAND, op = CORE_CONN_CREATE) {
+  dt : DestTypes,
+  _count_(destparams) : 8,
+  destparams : DestParams[],
+}
+
+packet ConnCreateResponse : Nci (mt = RESPONSE, op = CORE_CONN_CREATE) {
+  status : Status,
+  mpps : 8,
+  ncreds : 8,
+  conn_id : 8,
+}
+
+packet ConnCloseCommand : Nci (mt = COMMAND, op = CORE_CONN_CLOSE) {
+  conn_id : 8,
+}
+
+packet ConnCloseResponse : Nci (mt = RESPONSE, op = CORE_CONN_CLOSE) {
+  status : Status,
+}
+
+struct CreditsPerConn {
+  conn_id : 8,
+  ncredits : 8,
+}
+
+packet ConnCreditsNotification : Nci (mt = NOTIFICATION, op = CORE_CONN_CREDITS) {
+  _count_(conns) : 8,
+  conns : CreditsPerConn[],
+}
+
+packet GenericError : Nci (mt = NOTIFICATION, op = CORE_GENERIC_ERROR) {
+  status : Status,
+}
+
+packet InterfaceError : Nci (mt = NOTIFICATION, op = CORE_INTERFACE_ERROR) {
+  status : Status,
+  conn_id : 8,
+}
+
diff --git a/src/rust/rootcanal/main.rs b/src/rust/rootcanal/main.rs
index 6e4ffb5..252a118 100644
--- a/src/rust/rootcanal/main.rs
+++ b/src/rust/rootcanal/main.rs
@@ -12,7 +12,6 @@
 };
 use nfc_packets::nci::{InitResponseBuilder, NfccFeatures, RfInterface};
 use nfc_packets::nci::{NciMsgType, NciPacket, Packet, PacketBoundaryFlag};
-// use num_derive::{FromPrimitive, ToPrimitive};
 use std::convert::TryInto;
 use thiserror::Error;
 use tokio::io;
@@ -92,12 +91,15 @@
     W: AsyncWriteExt + Unpin,
 {
     let pbf = PacketBoundaryFlag::CompleteOrFinal;
+    let gid = 0u8;
     match cmd.specialize() {
         ResetCommand(rst) => {
-            write_nci(out, (ResetResponseBuilder { pbf, status: nci::Status::Ok }).build()).await?;
+            write_nci(out, (ResetResponseBuilder { gid, pbf, status: nci::Status::Ok }).build())
+                .await?;
             write_nci(
                 out,
                 (ResetNotificationBuilder {
+                    gid,
                     pbf,
                     trigger: ResetTrigger::ResetCommand,
                     config_status: if rst.get_reset_type() == ResetType::KeepConfig {
@@ -119,6 +121,7 @@
             write_nci(
                 out,
                 (InitResponseBuilder {
+                    gid,
                     pbf,
                     status: nci::Status::Ok,
                     nfcc_features: NfccFeatures::parse(&nfcc_feat).unwrap(),
diff --git a/src/rust/test/main.rs b/src/rust/test/main.rs
index d2d1e60..5bb4d6f 100644
--- a/src/rust/test/main.rs
+++ b/src/rust/test/main.rs
@@ -38,6 +38,8 @@
 
 async fn send_reset(out: UnboundedSender<NciPacket>) -> Result<()> {
     let pbf = PacketBoundaryFlag::CompleteOrFinal;
-    out.send((ResetCommandBuilder { pbf, reset_type: ResetType::ResetConfig }).build().into())?;
+    out.send(
+        (ResetCommandBuilder { gid: 0, pbf, reset_type: ResetType::ResetConfig }).build().into(),
+    )?;
     Ok(())
 }