[qca-nss-clients] support NSS NL library

Changes for supporting NSS NL Library

Change-Id: I4cca0c93e5048bde5d3b1f96cd65205e3ad916a2
Signed-off-by: Samarjeet Banerjee <banerjee@codeaurora.org>
diff --git a/netlink/include/nss_nl_if.h b/netlink/include/nss_nl_if.h
index d812133..7f4f14d 100755
--- a/netlink/include/nss_nl_if.h
+++ b/netlink/include/nss_nl_if.h
@@ -27,6 +27,9 @@
 
 #define NSS_NL_VER ((NSS_NL_VER_MAJOR << NSS_NL_VER_SHIFT) | NSS_NL_VER_MINOR)
 
+#include "nss_nlcmn_if.h"
+#include "nss_nlipv4_if.h"
+
 #endif /* __NSS_NL_IF_H */
 
 
diff --git a/netlink/include/nss_nlcmn_if.h b/netlink/include/nss_nlcmn_if.h
index 2c89629..c36595b 100755
--- a/netlink/include/nss_nlcmn_if.h
+++ b/netlink/include/nss_nlcmn_if.h
@@ -21,47 +21,39 @@
 #ifndef __NSS_NLCMN_IF_H
 #define __NSS_NLCMN_IF_H
 
+#define NSS_NLCMN_CB_MAX_SZ 64 /* bytes */
+
 /**
  * @brief Common message header for each NSS netlink message
  */
 struct nss_nlcmn {
-	uint32_t version;	/**< message version */
+	uint32_t version;			/**< message version */
 
-	uint32_t pid;		/**< process ID for the message */
-	uint32_t sock_data;	/**< socket specific info, used by kernel */
-	uint32_t user_data;	/**< user specific data */
-	uint32_t user_cb;	/**< user specific callback */
+	uint32_t pid;				/**< process ID for the message */
+	uint32_t sock_data;			/**< socket specific info, used by kernel */
 
-	uint16_t cmd_len;	/**< command len */
-	uint16_t cmd_type;	/**< command type */
+	uint16_t cmd_len;			/**< command len */
+	uint8_t cmd_type;			/**< command type */
+	uint8_t res;				/**< reserve for future use */
+
+	int32_t cb_owner;			/**< CB identifier */
+	uint8_t cb_data[NSS_NLCMN_CB_MAX_SZ]; 	/**< user context buffer */
 };
 
 /**
  * @brief messages senders must use this to initialize command
  *
  * @param cm[IN] common message
- * @param cmd[IN] command for the family
  * @param len[IN] command length
+ * @param cmd[IN] command for the family
  */
-static inline void nss_nlcmn_init_cmd(struct nss_nlcmn *cm, uint16_t cmd, uint16_t len)
+static inline void nss_nlcmn_init_cmd(struct nss_nlcmn *cm, uint16_t len, uint8_t cmd)
 {
 	cm->cmd_type = cmd;
 	cm->cmd_len = len;
 }
 
 /**
- * @brief messages senders must use this to initialize the user fields
- *
- * @param cm[IN] common message
- * @param user_data[IN] user specific data stored per command
- * @param user_cb[IN] user specific callback per command
- */
-static inline void nss_nlcmn_init_user(struct nss_nlcmn *cm, uint32_t user_data, uint32_t user_cb)
-{
-	cm->user_data = user_data;
-	cm->user_cb = user_cb;
-}
-/**
  * @brief check the version number of the incoming message
  *
  * @param cm[IN] common message header
@@ -70,7 +62,7 @@
  */
 static inline bool nss_nlcmn_chk_ver(struct nss_nlcmn *cm, uint32_t ver)
 {
-	return (cm->version == ver);
+	return cm->version == ver;
 }
 
 /**
@@ -85,6 +77,18 @@
 }
 
 /**
+ * @brief get the version number from common message header
+ *
+ * @param cm[IN] common message header
+ *
+ * @return version
+ */
+static inline uint32_t nss_nlcmn_get_ver(struct nss_nlcmn *cm)
+{
+	return cm->version;
+}
+
+/**
  * @brief get the NSS Family command type
  *
  * @param cm[IN] common message
@@ -99,9 +103,9 @@
 /**
  * @brief get the NSS Family command len
  *
- * @param cm[IN] command message
+ * @param cm[IN] common message
  *
- * @return command type
+ * @return command len
  */
 static inline uint16_t nss_nlcmn_get_len(struct nss_nlcmn *cm)
 {
@@ -109,28 +113,46 @@
 }
 
 /**
- * @brief get the user data for the command
+ * @brief get the callback data
  *
- * @param cm[IN] command message
+ * @param cm[IN] common message
+ * @param cb_owner[IN] callback owner ID
  *
- * @return user data
+ * @return callback data or NULL if the owner doesn't match
  */
-static inline uint32_t nss_nlcmn_get_user_data(struct nss_nlcmn *cm)
+static inline void *nss_nlcmn_get_cb_data(struct nss_nlcmn *cm, int32_t cb_owner)
 {
-	return cm->user_data;
+	/*
+	 * if owner doesn't match then the caller is not the owner
+	 */
+	if (cm->cb_owner != cb_owner) {
+		return NULL;
+	}
+
+	return cm->cb_data;
 }
 
 /**
- * @brief get the user callback for the command
+ * @brief set the callback data ownership
  *
- * @param cm[IN] command message
- *
- * @return user callback
+ * @param cm[IN] common message
+ * @param cb_owner[IN] callback owner ID
  */
-static inline uint32_t nss_nlcmn_get_user_cb(struct nss_nlcmn *cm)
+static inline void nss_nlcmn_set_cb_owner(struct nss_nlcmn *cm, int32_t cb_owner)
 {
-	return cm->user_cb;
+	cm->cb_owner = cb_owner;
 }
+
+/**
+ * @brief clear the CB ownership (ID) after use
+ *
+ * @param cm[IN] common message
+ */
+static inline void nss_nlcmn_clr_cb_owner(struct nss_nlcmn *cm)
+{
+	nss_nlcmn_set_cb_owner(cm, -1);
+}
+
 #endif /* __NSS_NLCMN_IF_H */
 
 
diff --git a/netlink/include/nss_nlcrypto_if.h b/netlink/include/nss_nlcrypto_if.h
index c76d7c1..7f4646e 100755
--- a/netlink/include/nss_nlcrypto_if.h
+++ b/netlink/include/nss_nlcrypto_if.h
@@ -101,7 +101,7 @@
 static inline void nss_nlcrypto_rule_init(struct nss_nlcrypto_rule *rule, enum nss_nlcrypto_cmd type)
 {
 	nss_nlcmn_set_ver(&rule->cm, NSS_NL_VER);
-	nss_nlcmn_init_cmd(&rule->cm, type, sizeof(struct nss_nlcrypto_rule));
+	nss_nlcmn_init_cmd(&rule->cm, sizeof(struct nss_nlcrypto_rule), type);
 }
 
 #endif /* __NSS_NLCRPTO_IF_H */
diff --git a/netlink/include/nss_nlipsec_if.h b/netlink/include/nss_nlipsec_if.h
index 12dec65..5713b82 100644
--- a/netlink/include/nss_nlipsec_if.h
+++ b/netlink/include/nss_nlipsec_if.h
@@ -67,7 +67,7 @@
 static inline void nss_nlipsec_rule_init(struct nss_nlipsec_rule *rule, enum nss_nlipsec_cmd type)
 {
 	nss_nlcmn_set_ver(&rule->cm, NSS_NL_VER);
-	nss_nlcmn_init_cmd(&rule->cm, type, sizeof(struct nss_nlipsec_rule));
+	nss_nlcmn_init_cmd(&rule->cm, sizeof(struct nss_nlipsec_rule), type);
 }
 
 /**@}*/
diff --git a/netlink/include/nss_nlipv4_if.h b/netlink/include/nss_nlipv4_if.h
index a51883e..6a67054 100755
--- a/netlink/include/nss_nlipv4_if.h
+++ b/netlink/include/nss_nlipv4_if.h
@@ -28,6 +28,10 @@
  * IPv4 forwarding Family
  */
 #define NSS_NLIPV4_FAMILY "nss_nlipv4"
+#define NSS_NLIPV4_MCAST_GRP "nss_nlipv4_mcast"
+
+#define NSS_NLIPV4_ARPHRD_IPSEC_TUNNEL_TYPE 0x31
+#define NSS_NLIPV4_VLAN_ID_NOT_CONFIGURED 0xFFF
 
 /**
  * @brief IPv4 rule
@@ -50,7 +54,7 @@
 static inline void nss_nlipv4_rule_init(struct nss_nlipv4_rule *rule, enum nss_ipv4_message_types type)
 {
 	nss_nlcmn_set_ver(&rule->cm, NSS_NL_VER);
-	nss_nlcmn_init_cmd(&rule->cm, type, sizeof(struct nss_nlipv4_rule));
+	nss_nlcmn_init_cmd(&rule->cm, sizeof(struct nss_nlipv4_rule), type);
 }
 
 #endif /* __NSS_NLIPV4_IF_H */
diff --git a/netlink/nss_nlipv4.c b/netlink/nss_nlipv4.c
index 6e883a2..b9e1f47 100755
--- a/netlink/nss_nlipv4.c
+++ b/netlink/nss_nlipv4.c
@@ -50,10 +50,6 @@
 #include "nss_nlcmn_if.h"
 #include "nss_nlipv4_if.h"
 
-
-#define NSS_NLIPV4_ARPHRD_IPSEC_TUNNEL_TYPE 0x31
-#define NSS_NLIPV4_VLAN_ID_NOT_CONFIGURED 0xFFF
-
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
 #define DST_NEIGH_LOOKUP(dst, ip_addr) dst_neigh_lookup(dst, ip_addr)
 #else
@@ -93,7 +89,7 @@
  * multicast group for sending message status & events
  */
 static struct genl_multicast_group nss_nlipv4_mcgrp = {
-	.name = NSS_NLIPV4_FAMILY,
+	.name = NSS_NLIPV4_MCAST_GRP,
 };
 
 /*