blob: 43f8f0175a5f281767c83dd9ffafb6984a109aa8 [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/include/appl/diag/bal_cmd.h sdk-all-6.5.7/include/appl/diag/bal_cmd.h
2--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/include/appl/diag/bal_cmd.h 1970-01-01 02:00:00.000000000 +0200
3+++ sdk-all-6.5.7/include/appl/diag/bal_cmd.h 2017-01-26 11:24:18.251278489 +0200
4@@ -0,0 +1,22 @@
5+/******************************************************************************
6+ *
7+ * Copyright 2016 - Broadcom Corporation
8+ *
9+ ******************************************************************************/
10+
11+#ifndef BAL_CMD_H
12+#define BAL_CMD_H
13+
14+#include <appl/diag/shell.h>
15+
16+static char cmd_bal_usage[] =
17+ "bal [cmd]\n\t"
18+ "Commands:\n\t"
19+ " trap_target <target_ip:port> - Set a remote ip and port to receive local cpu trapped packets\n\t"
20+ " trap_receive <sender_ip:port> - Set a local port to receive remote sender_ip messages \n\t"
21+ "\n\t"
22+ "When called with no parameters, initialize the BAL BCM Api and enter the bal sub-shell.\n";
23+
24+cmd_result_t cmd_bal(int unit, args_t *args);
25+
26+#endif
27diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/include/bcm/rx.h sdk-all-6.5.7/include/bcm/rx.h
28--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/include/bcm/rx.h 2016-12-01 05:15:05.000000000 +0200
29+++ sdk-all-6.5.7/include/bcm/rx.h 2017-01-26 11:30:12.960122166 +0200
30@@ -1789,5 +1789,18 @@
31 bcm_rx_cosq_mapping_t *rx_cosq_mapping);
32
33 #endif /* BCM_HIDE_DISPATCHABLE */
34+
35+/*
36+ * BAL patch to allow RPC register packet receive callback
37+ */
38+typedef void (*dpp_rx_cb_f) (
39+ int unit,
40+ int port,
41+ int reason,
42+ unsigned char *pkt,
43+ int pkt_len);
44+
45+extern
46+void dpp_dft_tx_cb(int unit, int port, int reason, unsigned char *payload, int payload_len);
47
48 #endif /* __BCM_RX_H__ */
49diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Make.config sdk-all-6.5.7/make/Make.config
50--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Make.config 2016-12-01 05:16:16.000000000 +0200
51+++ sdk-all-6.5.7/make/Make.config 2017-01-26 11:34:39.553494599 +0200
52@@ -32,6 +32,13 @@
53 # }
54 endif
55
56+ifeq (${BUILD_ING_AS_LIB},1)
57+CFGFLAGS += -DBUILD_ING_AS_LIB -DNO_CTRL_C
58+endif
59+ifeq (${CONFIG_SWITCH_RPC},y)
60+CFGFLAGS += -DCONFIG_SWITCH_RPC
61+endif
62+
63 #
64 # Set a default target if one is not set. If override-target is set,
65 # then the target will become override-target and a warning is printed
66diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Make.local.bal sdk-all-6.5.7/make/Make.local.bal
67--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Make.local.bal 1970-01-01 02:00:00.000000000 +0200
68+++ sdk-all-6.5.7/make/Make.local.bal 2017-01-26 11:36:43.722735752 +0200
69@@ -0,0 +1,30 @@
70+#FEATURE_LIST := CINT L3 I2C MEM_SCAN EDITLINE TEST BCM_SAL_PROFILE CUSTOMER CHASSIS RCPU ATPTRANS_SOCKET DUNE_UI INTR APIMODE PTP KBP
71+FEATURE_LIST := CINT L3 I2C MEM_SCAN EDITLINE TEST BCM_SAL_PROFILE CHASSIS RCPU ATPTRANS_SOCKET DUNE_UI INTR APIMODE PTP
72+
73+DEBUG_CFLAGS=-Wdeclaration-after-statement
74+
75+BCM_PTL_SPT=1
76+
77+ALL_DPP_CHIPS = 1
78+ALL_DFE_CHIPS = 1
79+
80+# Includes XML library and enables use of "diag pp dump" utility for PP import/export facilities
81+DATAIO_SUPPORT = 1
82+KERN_VER=3.7.10
83+
84+CFGFLAGS += -DSTATIC=static
85+CFGFLAGS += -DBCM_WARM_BOOT_SUPPORT
86+CFGFLAGS += -DBCM_WARM_BOOT_SUPPORT_SW_DUMP
87+CFGFLAGS += -DBCM_EASY_RELOAD_WB_COMPAT_SUPPORT
88+CFGFLAGS += -DBCM_CONTROL_API_TRACKING
89+CFGFLAGS += -D__DUNE_LINUX_BCM_CPU_PCIE__
90+CFGFLAGS += -DPHYS_ADDRS_ARE_64BITS -DSAL_BDE_32BIT_USER_64BIT_KERNEL
91+CFGFLAGS += -D_SIMPLE_MEMORY_ALLOCATION_=0 -DUSE_LINUX_BDE_MMAP=1
92+CFGFLAGS += -DSCACHE_CRC_CHECK
93+
94+CFGFLAGS += -DBROADCOM_SVK
95+
96+#KBP_DEVICE := KBP_ALG
97+
98+VENDOR_LIST=CUSTOMER78 BROADCOM DNX
99+
100diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Makefile.unix-linux sdk-all-6.5.7/make/Makefile.unix-linux
101--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Makefile.unix-linux 2016-12-01 05:16:17.000000000 +0200
102+++ sdk-all-6.5.7/make/Makefile.unix-linux 2017-01-26 13:16:35.035828648 +0200
103@@ -47,7 +47,7 @@
104
105
106 # Linux
107-LIBS= -lnsl -lpthread -lm -lrt
108+LIBS= -lnsl -pthread -lm -lrt
109 CFGFLAGS += -DBCM_PLATFORM_STRING=\"unix-linux\"
110
111 # For GCC 4.2.x, add -Wno-address
112diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Makefile.unix-linux-64 sdk-all-6.5.7/make/Makefile.unix-linux-64
113--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Makefile.unix-linux-64 2016-12-01 05:16:17.000000000 +0200
114+++ sdk-all-6.5.7/make/Makefile.unix-linux-64 2017-01-26 13:17:35.959446054 +0200
115@@ -48,7 +48,7 @@
116 FEATURE_EXCLUDE_LIST = $(sort $(_FEATURE_EXCLUDE_LIST))
117
118 # Linux
119-LIBS= -lnsl -lpthread -lm -lrt
120+LIBS= -lnsl -pthread -lm -lrt
121
122 CFGFLAGS += -DBCM_PLATFORM_STRING=\"unix-linux-64\"
123
124diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Makefile.unix-linux~ sdk-all-6.5.7/make/Makefile.unix-linux~
125--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Makefile.unix-linux~ 1970-01-01 02:00:00.000000000 +0200
126+++ sdk-all-6.5.7/make/Makefile.unix-linux~ 2017-01-26 13:16:34.973829038 +0200
127@@ -0,0 +1,60 @@
128+# $Id: Makefile.unix-linux,v 1.11 Broadcom SDK $
129+# $Copyright: (c) 2016 Broadcom.
130+# Broadcom Proprietary and Confidential. All rights reserved.$
131+#
132+# Build rules for Linux/x86 (Little Endian) with PLI support
133+
134+include ${SDK}/make/Makefile.unix-common
135+
136+# When using GDB on Linux, you may want to use "setenv GDB 1" to disable
137+# editline. For best results put "set environment GDB 1" in your .gdbinit.
138+
139+# Linux-specific Configuration Flags
140+
141+ENDIAN_DEF = -DLE_HOST=1
142+
143+# Notes on AMD Athlon 64-bit
144+#
145+# Compiles on x86_64 default to 32-bit emulation unless 64-bit mode
146+# is specifically requested in Make.local by uncommenting the two defines
147+# for PTRS_ARE_64BITS and LONGS_ARE_64BITS.
148+#
149+# Note that the code base will compile in 64-bit mode, but will not run
150+# correctly because malloc() can return values >32 bits and the PLISIM
151+# protocol only supports 32-bit addresses.
152+
153+ifeq ($(shell uname -m),x86_64)
154+ ifeq (,$(findstring -DPTRS_ARE_64BITS,$(CFGFLAGS)))
155+ CC = ${HCC} -m32
156+ CXX = g++ -m32
157+ else
158+ CC = ${HCC}
159+ CXX = g++
160+ endif
161+endif
162+
163+LD = ld
164+AR = ar
165+ARFLAGS = -rc
166+STRIP = strip
167+RANLIB = ranlib
168+
169+# Filter out features that cannot or should not be supported in Linux
170+ifdef ESW_CHIPS
171+_FEATURE_EXCLUDE_LIST += OOB_RCPU
172+endif
173+FEATURE_EXCLUDE_LIST = $(sort $(_FEATURE_EXCLUDE_LIST))
174+
175+
176+# Linux
177+LIBS= -lnsl -lpthread -lm -lrt
178+CFGFLAGS += -DBCM_PLATFORM_STRING=\"unix-linux\"
179+
180+# For GCC 4.2.x, add -Wno-address
181+GCC_MAJOR_VER = $(shell echo |$(CC) -dM -E -| grep __GNUC__ | cut -d' ' -f3)
182+GCC_MINOR_VER = $(shell echo |$(CC) -dM -E -| grep __GNUC_MINOR__ | cut -d' ' -f3)
183+ifeq (${GCC_MAJOR_VER}, 4)
184+ifeq (${GCC_MINOR_VER}, 2)
185+BCM_EXTRA_CC_CFLAGS = -Wno-address
186+endif
187+endif
188diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Makefile.unix-netbsd sdk-all-6.5.7/make/Makefile.unix-netbsd
189--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Makefile.unix-netbsd 2016-12-01 05:16:17.000000000 +0200
190+++ sdk-all-6.5.7/make/Makefile.unix-netbsd 2017-01-26 13:13:03.884156251 +0200
191@@ -27,7 +27,7 @@
192 FEATURE_EXCLUDE_LIST = $(sort $(_FEATURE_EXCLUDE_LIST))
193
194 # NetBSD
195-LIBS= -lpthread -lm -lsem
196++LIBS= -pthread -lm -lsem
197
198 CFGFLAGS += -DBCM_PLATFORM_STRING=\"unix-netbsd\"
199
200diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Makefile.unix-user sdk-all-6.5.7/make/Makefile.unix-user
201--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/make/Makefile.unix-user 2016-12-01 05:16:17.000000000 +0200
202+++ sdk-all-6.5.7/make/Makefile.unix-user 2017-01-26 13:14:29.289618967 +0200
203@@ -42,7 +42,7 @@
204 OSTYPE = LINUX
205
206 # Linux
207-LIBS= -lnsl -lpthread -lm -lrt
208+LIBS= -lnsl -pthread -lm -lrt
209
210 #
211 # ORIGIN is used to Optionally select different CFLAGS. It is used to import
212diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/appl/diag/bal_cmd.c sdk-all-6.5.7/src/appl/diag/bal_cmd.c
213--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/appl/diag/bal_cmd.c 1970-01-01 02:00:00.000000000 +0200
214+++ sdk-all-6.5.7/src/appl/diag/bal_cmd.c 2017-01-26 11:38:20.574144410 +0200
215@@ -0,0 +1,837 @@
216+/******************************************************************************
217+ *
218+ * Copyright 2015- Broadcom Corporation
219+ * This program is the proprietary software of Broadcom Corporation
220+ * and/or its licensors, and may only be used, duplicated, modified or
221+ * distributed pursuant to the terms and conditions of a separate,
222+ * written license agreement executed between you and Broadcom (an
223+ * "Authorized License"). Except as set forth in an Authorized License,
224+ * Broadcom grants no license (express or implied), right to use, or
225+ * waiver of any kind with respect to the Software, and Broadcom
226+ * expressly reserves all rights in and to the Software and all
227+ * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED
228+ * LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND
229+ * SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE
230+ * SOFTWARE.
231+ *
232+ * Except as expressly set forth in the Authorized License,
233+ *
234+ * 1. This program, including its structure, sequence and organization,
235+ * constitutes the valuable trade secrets of Broadcom, and you shall use
236+ * all reasonable efforts to protect the confidentiality thereof, and to
237+ * use this information only in connection with your use of Broadcom
238+ * integrated circuit products.
239+ *
240+ * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED
241+ * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES,
242+ * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR
243+ * OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY
244+ * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
245+ * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES,
246+ * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
247+ * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT
248+ * OF USE OR PERFORMANCE OF THE SOFTWARE.
249+ *
250+ * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM
251+ * OR ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL,
252+ * INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY
253+ * RELATING TO YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF
254+ * BROADCOM HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR (ii)
255+ * ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE SOFTWARE
256+ * ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE LIMITATIONS SHALL APPLY
257+ * NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF ANY LIMITED
258+ * REMEDY.
259+ *
260+ ******************************************************************************/
261+
262+/**
263+ * @file bal_cmd.c_
264+ * @brief BAL ING CLI commands support SDK access that is not supported by regular CLI
265+ * The BAL CLI command line interface is implemented by the CLI
266+ * module. The CLI module can be used as the configuration and management
267+ * interface for the BAL Switch Util. BAL Switch Util configuration can be specified
268+ * using a series of BAL CLI commands. The main purpose of the CLI is to provide
269+ * ING API access that are not normally available through public API, such as RPC
270+ * access to ING features that are deep in SDK stack.
271+ *
272+ **/
273+
274+ /*@{*/
275+
276+/* --- system includes --- */
277+
278+#include <unistd.h>
279+#include <stdio.h>
280+#include <string.h>
281+#include <ctype.h>
282+#include <stdlib.h>
283+#include <appl/diag/shell.h>
284+#include <appl/diag/parse.h>
285+#include <sal/appl/sal.h>
286+#include <sal/appl/editline/editline.h>
287+#include <errno.h>
288+#include <sys/types.h>
289+#include <sys/socket.h>
290+#include <netinet/in.h>
291+#include <arpa/inet.h>
292+#include <bcm/rx.h>
293+#include <bcm/error.h>
294+#include <bcm/stack.h>
295+
296+#define BAL_CLI_VERSION "1.0"
297+
298+/* --- project includes --- */
299+extern int start_trap_service(char *ip_port);
300+extern int start_host_listener(char *ip_port);
301+
302+/* --- local static constants ---*/
303+#define BAL_SWITCH_CLI_IP_LEN 128
304+typedef struct bal_switch_cli_cfg_t
305+{
306+ char trap_target[BAL_SWITCH_CLI_IP_LEN]; /* remote ip:port address where the trapped packet sent */
307+ char trap_receive[BAL_SWITCH_CLI_IP_LEN]; /* remote ip where the local port receive message */
308+}bal_switch_cli_cfg_t;
309+
310+static bal_switch_cli_cfg_t g_cur_ctx;
311+
312+static bal_switch_cli_cfg_t *gp_cur_ctx = &g_cur_ctx;
313+
314+enum
315+{
316+ BAL_REASON_SEND_TO_NNI = 1,
317+ BAL_REASON_SEND_TO_PON
318+};
319+
320+/**
321+ * * @brief Maximum number of arguments supported by the 'bal' CLI command
322+ * */
323+#define MAX_ARGS 10
324+
325+/**
326+ ** @brief BAL CLI help text
327+ **/
328+#define HELP \
329+"exit - Exit the BAL sub-shell\n" \
330+"show - Show current settings\n" \
331+"trap_target - register callback and send CPU trapped packets to remote IP:PORT\n" \
332+"trap_receive - Start a receiving thread to listen on PORT for messages from remote IP \n" \
333+
334+
335+/**
336+ ** @brief BAL Switch App help text specific to 'show' commands
337+ **/
338+#define SHOW_HELP \
339+"show config - Display the BAL CLI configuration\n" \
340+"show version - Display the BAL BCM SDK version\n" \
341+
342+
343+/**
344+ * @brief CLI prompt string
345+ * */
346+static char g_bal_cli_prompt[8];
347+
348+
349+/*
350+ * @brief BAL Switch App help text
351+ *
352+ * @return char* A string containing the prompt to display
353+ **/
354+static char *bal_set_prompt()
355+{
356+ sprintf(g_bal_cli_prompt, "bal>");
357+ return g_bal_cli_prompt;
358+}
359+
360+/**
361+ * @brief Parse a line of input into a POSIX-like argument list
362+ *
363+ ** @param parsed_input Unparsed line of CLI input
364+ ** @param argc Pointer to the number of arguments in the list
365+ ** @param argv Pointer to the argument list
366+ ** @return int Number of argument that has been successfully parsed
367+ **/
368+int bal_parse_input (char *parsed_input, int *argc, char **argv)
369+{
370+ char *s;
371+ int largc;
372+
373+ largc = 0;
374+ s = parsed_input;
375+ while ((largc < MAX_ARGS) && (s != NULL) && (*s != 0))
376+ {
377+ /* Skip leading whitespace */
378+ s += strspn (s, " \t");
379+
380+ /* Non-whitespace found */
381+ if (*s != 0)
382+ {
383+ /* Add the string to the argument list */
384+ argv[largc++] = s;
385+
386+ /* Find the trailing whitespace (if any...) */
387+ s = strpbrk (s, " \t");
388+ if (s != NULL)
389+ {
390+ /* Found some white space, null out the first white
391+ space character. */
392+ if (largc < MAX_ARGS)
393+ {
394+ *s++ = 0;
395+ }
396+
397+ /* Otherwise, don't null the last param, to pass it on
398+ * command to parse themselves
399+ */
400+ }
401+ }
402+ }
403+
404+ *argc = largc;
405+
406+ return largc;
407+}
408+
409+ /* BAL packet_in function and definitions */
410+ typedef struct
411+ {
412+ int socket;
413+ struct sockaddr_in addr;
414+ }trap_target_t;
415+ static trap_target_t s_target_device;
416+ static int target_init = 0;
417+ #define DEFAULT_SOP_ADJ 2
418+ #define DEFAULT_REASON_ADJ 4
419+
420+ bcm_rx_t trap_service_cb(int unit, bcm_pkt_t *pkt, void *cookie)
421+ {
422+
423+ uint8 *p_payload;
424+ int dpp_hdr_len, payload_len, n_sent;
425+ trap_target_t *p_target_device = (trap_target_t *)cookie;
426+ uint16 *p_src_port, def_sop;
427+ uint32 *p_reason, def_reason;
428+ /* skip the dpp header - 19 bytes */
429+ p_payload = pkt->_pkt_data.data;
430+ dpp_hdr_len = pkt->tot_len - pkt->pkt_len + 0;
431+ payload_len = pkt->tot_len - dpp_hdr_len;
432+ p_payload += dpp_hdr_len;
433+
434+ /*
435+ * replace SOP_ADJ bytes with source port info before send
436+ * assuming DEFAULT_SOP_ADJ is always 2 bytes
437+ * replace SOP_REASON bytes with trap reason - TBD
438+ */
439+ p_src_port = (uint16 *)(p_payload - DEFAULT_SOP_ADJ);
440+ /* save the original info */
441+ def_sop = *(p_src_port);
442+ /* replace 2 bytes with ingress port info */
443+ *p_src_port = htons(pkt->src_port & 0xff); /* pkt->src_port is 1 byte long */
444+
445+ p_reason = (uint32 *)(p_payload - DEFAULT_SOP_ADJ - DEFAULT_REASON_ADJ);
446+ /* save the original info */
447+ def_reason = *(p_reason);
448+ /* replace 4 bytes with reason code */
449+ *p_reason = htonl(pkt->rx_trap_data);
450+
451+ n_sent = sendto(p_target_device->socket,
452+ p_payload-DEFAULT_SOP_ADJ-DEFAULT_REASON_ADJ,
453+ payload_len+DEFAULT_SOP_ADJ+DEFAULT_REASON_ADJ, 0,
454+ (struct sockaddr *) &(p_target_device->addr),
455+ sizeof(struct sockaddr_in));
456+
457+ /* put back the original values */
458+ *p_src_port = def_sop;
459+ *p_reason = def_reason;
460+
461+ if (n_sent > 0)
462+ return BCM_RX_HANDLED;
463+ else
464+ return BCM_RX_NOT_HANDLED;
465+ }
466+
467+ int start_trap_service( char *ip_port)
468+ {
469+ int ret, port;
470+ char ip[80], *col;
471+
472+ if(target_init == 0)
473+ {
474+ if((s_target_device.socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
475+ {
476+ return -1;
477+ }
478+ target_init = 1;
479+ }
480+ /* fill in traget device info - ip_port has the format of ip:port, so look for ":" for separation */
481+ col = strstr(ip_port, ":");
482+ port = atoi(col+1);
483+ /* terminate the string at the end of IP address */
484+ *col = 0;
485+ strcpy(ip, ip_port);
486+
487+ s_target_device.addr.sin_family = AF_INET;
488+ s_target_device.addr.sin_port = htons(port);
489+ s_target_device.addr.sin_addr.s_addr = inet_addr(ip);
490+
491+ ret = bcm_rx_register(0, "Cpu Traps", trap_service_cb, 50, (void *)&s_target_device, BCM_RCO_F_ALL_COS);
492+ return ret;
493+ }
494+
495+/**
496+ ** @brief CLI parser and handler for 'trap_target' commands
497+ **
498+ ** This routine handles the 'bal trap_target [args]' CLI app configuration
499+ ** commands.
500+ **
501+ ** @param argc Pointer to the number of arguments in the list
502+ ** @param argv Pointer to the argument list
503+ * */
504+void bal_bcm_cli_trap_target(int argc, char **argv)
505+{
506+
507+ if (argc != 1)
508+ {
509+ printf("Invalid arguments\n");
510+ return;
511+ }
512+
513+ {
514+ strcpy(gp_cur_ctx->trap_target, argv[0]);
515+ /* Configure the trap target with the specified setting. */
516+ if (start_trap_service(argv[0]) != 0)
517+ {
518+ printf("Error, failed to start trap service on '%s'\n",
519+ argv[0]);
520+ }
521+ }
522+}
523+
524+typedef struct
525+{
526+ int udp_port;
527+ sal_thread_t threadid;
528+ dpp_rx_cb_f callback;
529+}trap_context_t;
530+
531+ static trap_context_t trap_ctx = {0};
532+ static int listener_init = 0;
533+
534+#define MAX_RX_PACKET_SIZE (2000)
535+
536+static void host_receive(void *p_user_data)
537+{
538+ int rc;
539+ int sUDPSocket;
540+ unsigned char cBuffer[MAX_RX_PACKET_SIZE];
541+ int nBytesRecv = 0;
542+ int nBufSize = MAX_RX_PACKET_SIZE;
543+ socklen_t nReceiveAddrSize = 0;
544+ int maxfd;
545+ fd_set read_fds;
546+ struct timeval tv;
547+ uint16 *p_dst_port, dst_port;
548+ trap_context_t *p_trap_ctx = (trap_context_t *)p_user_data;
549+ uint32 *p_reason, reason;
550+ struct sockaddr_in sReceiveFromAddr;
551+
552+ /* Create a connectionless socket */
553+ sUDPSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
554+ /* Check to see if we have a valid socket */
555+ if(sUDPSocket < 0)
556+ {
557+ printf(" host_receive:create socket failed\n");
558+ return;
559+ }
560+
561+ /* Setup a bind on the socket, telling us what port and
562+ * adapter to receive datagrams on.
563+ * NOTE: we accept UDP packets from any sender as long
564+ * as they arrive on the specified port.
565+ */
566+ memset(&sReceiveFromAddr, 0, sizeof(struct sockaddr_in));
567+
568+ sReceiveFromAddr.sin_family = AF_INET;
569+ sReceiveFromAddr.sin_port = htons(p_trap_ctx->udp_port);
570+ sReceiveFromAddr.sin_addr.s_addr = htonl(INADDR_ANY);
571+
572+ rc = bind(sUDPSocket, (struct sockaddr *)&sReceiveFromAddr,
573+ sizeof(struct sockaddr_in));
574+ if (rc < 0)
575+ {
576+ printf("host_receive:bind failed\n");
577+ return;
578+ }
579+
580+ // Receive a datagram from another device
581+ while(1)
582+ {
583+ FD_ZERO(&read_fds);
584+ FD_SET(sUDPSocket, &read_fds);
585+ maxfd = sUDPSocket;
586+ /* Set the timeout */
587+ tv.tv_sec = 1;
588+ tv.tv_usec = 0; /* 1 seconds */
589+ rc = select(maxfd + 1, &read_fds, NULL, NULL, &tv);
590+
591+ if (rc < 0)
592+ {
593+ printf(" host_receive:select failed err = %d\n", rc);
594+ break;
595+ }
596+ if (rc == 0)
597+ {
598+ fflush(stdout);
599+ continue;
600+ }
601+ // Get the datagram
602+ nBytesRecv = recvfrom(sUDPSocket, cBuffer, nBufSize, 0,
603+ (struct sockaddr *) &sReceiveFromAddr,
604+ &nReceiveAddrSize);
605+ printf("Got %d bytes message \n", nBytesRecv);
606+ /* the first 4 bytes are reason */
607+ p_reason = (uint32 *)(cBuffer);
608+ reason = ntohl(*p_reason);
609+
610+ /* the next 2 bytes are destination port */
611+ p_dst_port = (uint16 *)(cBuffer + DEFAULT_REASON_ADJ);
612+ dst_port = ntohs(*p_dst_port);
613+
614+ /* call the register callback here - set unit to 0 as it is don't care */
615+ if(p_trap_ctx->callback)
616+ {
617+ p_trap_ctx->callback(0,
618+ dst_port,
619+ reason,
620+ cBuffer+DEFAULT_SOP_ADJ+DEFAULT_REASON_ADJ,
621+ nBytesRecv-DEFAULT_SOP_ADJ-DEFAULT_REASON_ADJ);
622+ }
623+ }
624+ close(sUDPSocket);
625+
626+ return;
627+}
628+
629+
630+void dpp_dft_tx_cb(int unit, int dst_port, int reason, unsigned char *payload, int payload_len)
631+{
632+
633+ int i;
634+ bcm_pkt_t *tx_pkt;
635+ uint8_t tx_pkt_dune_header[6];
636+ uint32_t tx_pkt_offset = 0;
637+ bcm_gport_t sys_gport;
638+ bcm_gport_t local_gport;
639+ bcm_port_t sysport = 0;
640+ bcm_gport_t local_cpu_port = 0;
641+ int sdk_rc;
642+
643+ printf("Msg from core:\n");
644+ printf(" dst port:%d, rcv reason: 0x%x, ", dst_port, reason);
645+
646+ /* dump out first 32 bytes */
647+ printf("payload (first 12 bytes): ");
648+ for(i=0; i<12; i++)
649+ {
650+ if(i%6 == 0 && i) printf(" ");
651+ printf("%02x", payload[i]);
652+ }
653+ printf("\n");
654+
655+
656+ /* Map the local port number to a CPU "system" port. */
657+ local_gport = dst_port;
658+ sdk_rc = bcm_stk_gport_sysport_get(unit, local_gport, &sys_gport);
659+ if (sdk_rc != BCM_E_NONE)
660+ {
661+ /* Error */
662+ printf("%s(): [PacketOut] bcm_stk_gport_sysport_get returned with failure code '%s'\n",
663+ __FUNCTION__, bcm_errmsg(sdk_rc));
664+ return;
665+ }
666+
667+ sysport = sys_gport & 0xff;
668+
669+ /* Get the local CPU port */
670+ sdk_rc = bcm_port_local_get(unit, BCM_GPORT_LOCAL_CPU, &local_cpu_port);
671+ if (sdk_rc != BCM_E_NONE)
672+ {
673+ /* Error */
674+ printf("%s(): [PacketOut] bcm_port_local_get returned with failure code '%s'\n",
675+ __FUNCTION__, bcm_errmsg(sdk_rc));
676+ return;
677+ }
678+
679+ /* Allocate a packet structure */
680+ sdk_rc = bcm_pkt_alloc(unit, payload_len+sizeof(tx_pkt_dune_header), 0, &tx_pkt);
681+
682+ if (sdk_rc != BCM_E_NONE)
683+ {
684+ /* Error */
685+ printf("%s(): [PacketOut] bcm_pkt_alloc returned with failure code '%s'\n",
686+ __FUNCTION__, bcm_errmsg(sdk_rc));
687+ return;
688+ }
689+
690+ /* Set up the packet for a single block */
691+ tx_pkt->call_back = 0;
692+ tx_pkt->blk_count = 1;
693+ tx_pkt->unit = unit;
694+
695+ /* Dune TM header */
696+ tx_pkt->_dpp_hdr[3] = 0x00; /* channel num */
697+ tx_pkt->_dpp_hdr[2] = 0x00;
698+ tx_pkt->_dpp_hdr[1] = 0x00;
699+ tx_pkt->_dpp_hdr[0] = 0x00;
700+
701+ tx_pkt->_dpp_hdr_type = 1; /* DPP_HDR_itmh_base */
702+
703+ /* PTCH */
704+ tx_pkt_dune_header[0] = 0x50;
705+ tx_pkt_dune_header[1] = local_cpu_port;
706+
707+ /* ITMH */
708+ tx_pkt_dune_header[2] = 0x01;
709+ tx_pkt_dune_header[3] = 0x00;
710+ tx_pkt_dune_header[4] = (sysport & 0xff); /* Destination port */
711+ tx_pkt_dune_header[5] = 0x00;
712+
713+ /* Insert the DUNE header into the packet */
714+ bcm_pkt_memcpy (tx_pkt, tx_pkt_offset, tx_pkt_dune_header, sizeof(tx_pkt_dune_header));
715+ tx_pkt_offset += sizeof(tx_pkt_dune_header);
716+
717+ /* Insert the payload into the packet */
718+ bcm_pkt_memcpy (tx_pkt, tx_pkt_offset, payload, payload_len);
719+ tx_pkt_offset += payload_len;
720+
721+ printf("%s(): [PacketOut] transmitting a %d length packet, "
722+ "sys_gport:0x%X, sysport: %d\n",
723+ __FUNCTION__,
724+ payload_len,
725+ sys_gport,
726+ sysport);
727+
728+ /* Transmit the packet */
729+ sdk_rc = bcm_tx(unit, tx_pkt, NULL);
730+ if (sdk_rc != BCM_E_NONE)
731+ {
732+ /* Error */
733+ printf( "%s(): bcm_tx returned with failure code '%s'\n",
734+ __FUNCTION__, bcm_errmsg(sdk_rc));
735+ }
736+
737+ /* Cleanup */
738+ bcm_pkt_free(unit, tx_pkt);
739+
740+ return;
741+}
742+
743+void dpp_dft_msg_cb(int unit, int dst_port, int reason, unsigned char *payload, int payload_len)
744+{
745+
746+ int i, len;
747+
748+ printf("Msg from core:\n");
749+ printf(" dst port:%d, rcv reason: 0x%x, ", dst_port, reason);
750+
751+ len = (payload_len > 32)? 32: payload_len;
752+
753+ /* dump out first 32 bytes */
754+ printf("payload (first %d bytes): ", len);
755+ for(i=0; i<len; i++)
756+ {
757+ if(i%8 == 0 && i) printf(" ");
758+ printf("%02x", payload[i]);
759+ }
760+ printf("\n");
761+
762+ return;
763+}
764+
765+void dpp_dft_host_cb(int unit, int dst_port, int reason, unsigned char *payload, int payload_len)
766+{
767+ switch(reason)
768+ {
769+ case BAL_REASON_SEND_TO_NNI:
770+ case BAL_REASON_SEND_TO_PON:
771+ dpp_dft_tx_cb(unit, dst_port, reason, payload, payload_len);
772+ break;
773+ default:
774+ dpp_dft_msg_cb(unit, dst_port, reason, payload, payload_len);
775+ break;
776+ }
777+ return;
778+}
779+
780+
781+
782+
783+
784+
785+
786+
787+
788+
789+/*
790+ * This is the function that is called to start a thread to listen for
791+ * packets sent from BAL to bcm.user for injection into the switch.
792+ *
793+ * This happens when the user includes the trap_receive identifier in
794+ * the rpc.soc file that is co-resident with the bcm.user executable.
795+ *
796+ ** An example line in the rpc.soc file might be:
797+ *
798+ * dune "sand trap_receive 10.3.2.2:50003"
799+ *
800+ * This line specifies to listen on port 50003 and that messages will
801+ * arrive from IP 10.3.2.2 (although the IP address is not respected
802+ * in this code).
803+ *
804+ * */
805+int start_host_listener(char *ip_port)
806+ {
807+
808+ char *col;
809+
810+ if(listener_init != 0)
811+ {
812+ return 0;
813+ }
814+
815+ /* fill in host listener info - ip_port has the format of ip:port, so look for ":" for separation */
816+ col = strstr(ip_port, ":");
817+ trap_ctx.udp_port = atoi(col+1);
818+
819+ /* register a default handler */
820+ trap_ctx.callback = dpp_dft_host_cb;
821+
822+ /* spawn a thread to listen to socket */
823+ trap_ctx.threadid = sal_thread_create("trap_rx", 8192, 50, host_receive, &trap_ctx);
824+
825+ if (trap_ctx.threadid == SAL_THREAD_ERROR)
826+ {
827+ return -2;
828+ }
829+
830+ listener_init = 1;
831+ return 0;
832+ }
833+
834+/**
835+ ** @brief CLI parser and handler for 'trap_receive' commands
836+ **
837+ ** This routine handles the 'bal trap_receive [args]' CLI app configuration
838+ ** commands.
839+ **
840+ ** @param argc Pointer to the number of arguments in the list
841+ ** @param argv Pointer to the argument list
842+ * */
843+void bal_bcm_cli_trap_receive(int argc, char **argv)
844+{
845+
846+ if (argc != 1)
847+ {
848+ printf("Invalid arguments\n");
849+ return;
850+ }
851+
852+ {
853+ strcpy(gp_cur_ctx->trap_receive, argv[0]);
854+ /* Configure the msg receiver with the specified setting. */
855+ if (start_host_listener(argv[0]) != 0)
856+ {
857+ printf("Error, failed to start trap listener on '%s'\n",
858+ argv[0]);
859+ }
860+ }
861+}
862+
863+/**
864+ ** @brief Handler for the 'bal show version' command
865+ **
866+ ** This routine handles the 'bal show version' CLI command
867+ ** and show version information on the console.
868+ **
869+ **/
870+void bal_bcm_show_version(void)
871+{
872+
873+ /* Print out the software revision information */
874+ printf("Broadcom Software, Broadband Abstraction Layer, CLI Version %s \n",
875+ BAL_CLI_VERSION);
876+}
877+
878+
879+/**
880+ ** @brief CLI parser and handler for 'show' commands
881+ **
882+ ** This routine handles the 'bal show [args]' CLI app commands.
883+ **
884+ ** @param argc Pointer to the number of arguments in the list
885+ ** @param argv Pointer to the argument list
886+ **/
887+void bal_bcm_cli_show(int argc, char **argv)
888+{
889+ char *show_cmd;
890+
891+ show_cmd = argv[0];
892+
893+ if (argc == 0)
894+ {
895+ printf("Error: missing show sub-command.\n");
896+ printf("%s", SHOW_HELP);
897+ return;
898+ }
899+
900+ show_cmd = argv[0];
901+
902+ if (sal_strcasecmp(show_cmd, "config") == 0)
903+ {
904+ printf("BAL BCM App Configuration:\n");
905+ printf("--------------------------------\n");
906+ printf("trap_target ip_port = %s\n", gp_cur_ctx->trap_target);
907+ printf("trap_receive ip_port = %s\n", gp_cur_ctx->trap_receive);
908+ }
909+ else if (sal_strcasecmp(show_cmd, "version") == 0)
910+ {
911+ bal_bcm_show_version();
912+ }
913+ else if (sal_strcasecmp(show_cmd, "help") == 0 ||
914+ sal_strcasecmp(show_cmd, "?") == 0)
915+ {
916+ printf("%s", SHOW_HELP);
917+ }
918+ else
919+ {
920+ printf("Error: unknown show command '%s'.\n", show_cmd);
921+ }
922+}
923+
924+/**
925+ ** @brief Executes a command as specified by a single line of CLI input
926+ **
927+ ** @param argc Pointer to the number of arguments in the list
928+ ** @param argv Pointer to the argument list
929+ **/
930+void DoCmd(int argc, char **argv)
931+{
932+ char *cmd;
933+
934+ if (argc == 0 || argv[0] == NULL)
935+ {
936+ return;
937+ }
938+
939+ cmd = argv[0];
940+
941+ printf("CLI executing command '%s'\n", cmd);
942+
943+ if (sal_strcasecmp(cmd, "trap_target") == 0)
944+ {
945+ bal_bcm_cli_trap_target(argc-1, &argv[1]);
946+ }
947+ else if (sal_strcasecmp(cmd, "trap_receive") == 0)
948+ {
949+ bal_bcm_cli_trap_receive(argc-1, &argv[1]);
950+ }
951+ else if (sal_strcasecmp(cmd, "show") == 0)
952+ {
953+ bal_bcm_cli_show(argc-1, &argv[1]);
954+ }
955+ else if (sal_strcasecmp(cmd, "help") == 0 ||
956+ sal_strcasecmp(cmd, "?") == 0)
957+ {
958+ /* Display help */
959+ printf("%s", HELP);
960+ }
961+ else if (sal_strcasecmp(cmd, "exit") == 0)
962+ {
963+ return;
964+ }
965+ else
966+ {
967+ printf("Unknown command '%s'\n", cmd);
968+ }
969+}
970+
971+/**
972+ * * @brief Main processing loop for the CLI
973+ * *
974+ * * @param args Pointer to an BCM SDK formatted argument list
975+ * */
976+void bal_cli_shell(args_t *args)
977+{
978+ char *cmd;
979+ int argc = 0;
980+ char *argv[MAX_ARGS];
981+ static int initialized = 0;
982+
983+ if (initialized == 0)
984+ {
985+ bal_set_prompt();
986+ initialized = 1;
987+ }
988+
989+ if (args->a_argc > 1)
990+ {
991+
992+ DoCmd(args->a_argc-1, &args->a_argv[1]);
993+ }
994+ else
995+ {
996+
997+ printf("CLI running in interactive mode\n");
998+
999+ for (;;)
1000+ {
1001+ /* use ING editline library, DONT free pointer "cmd" as Linux man readline
1002+ suggested, it will cause a crash */
1003+ cmd = readline(g_bal_cli_prompt);
1004+ if (*cmd != '\0')
1005+ {
1006+ add_history(cmd);
1007+ }
1008+ else
1009+ {
1010+ continue;
1011+ }
1012+
1013+ if ((sal_strcasecmp(cmd, "exit") == 0) || (sal_strcasecmp(cmd, "quit") == 0))
1014+ {
1015+ printf ("exiting bal shell.\n");
1016+ break;
1017+ }
1018+
1019+ bal_parse_input(cmd, &argc, argv);
1020+
1021+ DoCmd(argc, argv);
1022+
1023+ }
1024+ }
1025+
1026+ /* "Consume" all of the command line arguments so the bcm.user shell
1027+ * does not complain.
1028+ */
1029+ args->a_arg = args->a_argc;
1030+}
1031+
1032+/**
1033+ * @brief The cmdlist hook for the BAL BCM App CLI command
1034+ *
1035+ * This file contains the function to "hook" into the main bcm.user
1036+ * CLI.
1037+ *
1038+ * @param unit SDK unit number
1039+ * @param args Pointer to an BCM SDK formatted argument list
1040+ *
1041+ * @return cmd_result_t
1042+ *
1043+ * */
1044+cmd_result_t cmd_bal(int unit, args_t *args)
1045+{
1046+ /* char *subcmd = ARG_GET(args); */
1047+
1048+ bal_cli_shell(args);
1049+
1050+ return CMD_OK;
1051+}
1052+/*@}*/
1053diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/appl/diag/cmdlist.c sdk-all-6.5.7/src/appl/diag/cmdlist.c
1054--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/appl/diag/cmdlist.c 2016-12-01 05:16:25.000000000 +0200
1055+++ sdk-all-6.5.7/src/appl/diag/cmdlist.c 2017-01-26 12:04:04.992722758 +0200
1056@@ -57,6 +57,7 @@
1057
1058 #include <appl/diag/diag.h>
1059 #include <appl/diag/cmdlist.h>
1060+#include <appl/diag/bal_cmd.h>
1061
1062 cmd_t *cur_cmd_list[SOC_MAX_NUM_DEVICES];
1063 int cur_cmd_cnt[SOC_MAX_NUM_DEVICES];
1064@@ -98,6 +99,9 @@
1065 "Attach SOC device(s)" },
1066 {"BackGround", sh_bg, sh_bg_usage,
1067 "Execute a command in the background."},
1068+ /* BAL ING API support */
1069+ {"BAL", cmd_bal, cmd_bal_usage,
1070+ "Run a BAL ING Api command."},
1071 #if defined(INCLUDE_BCMX_DIAG)
1072 {"BCM", cmd_mode_bcm, shell_bcm_usage,
1073 "Set shell mode to BCM."},
1074diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/appl/diag/ctrans.c sdk-all-6.5.7/src/appl/diag/ctrans.c
1075--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/appl/diag/ctrans.c 2016-12-01 05:16:25.000000000 +0200
1076+++ sdk-all-6.5.7/src/appl/diag/ctrans.c 2017-01-26 12:23:48.883393220 +0200
1077@@ -1016,6 +1016,7 @@
1078 return rv;
1079 }
1080
1081+#define BAL_CMD_LEN 128
1082
1083 bcm_rx_t
1084 ab_echo_cb(cpudb_key_t src_key,
1085@@ -1033,6 +1034,8 @@
1086 int mode;
1087 int len;
1088 CallbackOptions *options = (CallbackOptions *)cookie;
1089+ char bal_cmd[BAL_CMD_LEN];
1090+ int bal_cmd_len;
1091
1092 if (payload == NULL) { /* Just use first segment for string */
1093 if (pkt == NULL) {
1094@@ -1085,6 +1088,9 @@
1095 _send_echo_pkt(client_id, payload, len, depth - 1,
1096 pkt_flags, mode, options->verbose, src_key, NULL);
1097 }
1098+ bal_cmd_len = ((len-offset) >= BAL_CMD_LEN)? BAL_CMD_LEN-1: len-offset;
1099+ memcpy(bal_cmd, &payload[offset], bal_cmd_len);
1100+ bal_cmd[bal_cmd_len] = 0;
1101
1102 if (async_free) {
1103 rv = BCM_RX_HANDLED_OWNED;
1104@@ -1093,6 +1099,13 @@
1105 rv = BCM_RX_HANDLED;
1106 }
1107
1108+ /** if string has special cli prefix !>, execute the cli command */
1109+ if(bal_cmd[0] == '!' && bal_cmd[1] == '>')
1110+ {
1111+ cli_out("Execute BAL CLI cmd -> %s\n", &bal_cmd[2]);
1112+ sh_process_command(0, &bal_cmd[2]);
1113+ }
1114+
1115 return rv;
1116 }
1117
1118diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/appl/diag/shell.c sdk-all-6.5.7/src/appl/diag/shell.c
1119--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/appl/diag/shell.c 2016-12-01 05:16:25.000000000 +0200
1120+++ sdk-all-6.5.7/src/appl/diag/shell.c 2017-01-26 12:31:49.873427400 +0200
1121@@ -214,10 +214,15 @@
1122 var_unset("ihost_mode", FALSE, TRUE, FALSE);
1123 var_unset("num_ucs", FALSE, TRUE, FALSE);
1124 }
1125+
1126+#ifdef CONFIG_SWITCH_RPC
1127+ cli_out("Running with remote hardware, skip setting unit variable\n");
1128+ return;
1129+#endif
1130
1131 if (new_unit >= 0) {
1132- uint16 dev_id;
1133- uint8 rev_id;
1134+ uint16 dev_id;
1135+ uint8 rev_id;
1136 char *chip_string;
1137 uint16 dev_id_driver;
1138 uint8 rev_id_driver;
1139@@ -466,7 +471,9 @@
1140 /* Not attached, print out error */
1141 if (override_unit)
1142 return TRUE;
1143+#ifndef BUILD_ING_AS_LIB
1144 cli_out("%s: Error: Unit %d not attached\n", pfx, u);
1145+#endif
1146 return(FALSE);
1147 }
1148 return(TRUE);
1149diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/appl/diag/system.c sdk-all-6.5.7/src/appl/diag/system.c
1150--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/appl/diag/system.c 2016-12-01 05:16:25.000000000 +0200
1151+++ sdk-all-6.5.7/src/appl/diag/system.c 2017-01-26 12:35:45.001982454 +0200
1152@@ -2379,7 +2379,13 @@
1153 DISPLAY_MEM_PRINTF(("%s(): Just before BCM shell\r\n",__FUNCTION__)) ;
1154
1155 while (1) {
1156+
1157+#ifndef BUILD_ING_AS_LIB
1158 sh_process(-1, "BCM", TRUE);
1159+#else
1160+ return;
1161+#endif
1162+
1163 #ifdef NO_SAL_APPL
1164 return;
1165 #else
1166diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/bcm/dpp/alloc_mngr_cosq.c sdk-all-6.5.7/src/bcm/dpp/alloc_mngr_cosq.c
1167--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/bcm/dpp/alloc_mngr_cosq.c 2016-12-01 05:16:47.000000000 +0200
1168+++ sdk-all-6.5.7/src/bcm/dpp/alloc_mngr_cosq.c 2017-01-26 12:43:50.511008400 +0200
1169@@ -3644,6 +3644,7 @@
1170 if (flow_type == SOC_TMC_AM_SCH_FLOW_TYPE_CONNECTOR) {
1171 region = _BCM_DPP_AM_COSQ_GET_REGION_INDEX_FROM_FLOW_INDEX(*flow_id);
1172 if (nof_remote_cores != SOC_DPP_CONFIG(unit)->arad->region_nof_remote_cores[core][region]) {
1173+ printf(" nof_remote_cores %d != %d at core %d region %d\n", nof_remote_cores, SOC_DPP_CONFIG(unit)->arad->region_nof_remote_cores[core][region], core, region);
1174 BCMDNX_ERR_EXIT_MSG(BCM_E_PARAM,(_BSL_BCM_MSG("Requested region doesn't support requested number of remote cores")));
1175 }
1176 }
1177diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/bcm/rpc/pack.c sdk-all-6.5.7/src/bcm/rpc/pack.c
1178--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/bcm/rpc/pack.c 2016-12-01 05:17:00.000000000 +0200
1179+++ sdk-all-6.5.7/src/bcm/rpc/pack.c 2017-01-26 12:52:51.016711143 +0200
1180@@ -9975,6 +9975,9 @@
1181 uint8 *
1182 _bcm_pack_rx_trap_config(uint8 *buf, bcm_rx_trap_config_t *var)
1183 {
1184+ uint8 zero_8 = 0;
1185+ uint32 zero_32 = 0;
1186+
1187 BCM_PACK_U32(buf, var->flags);
1188 BCM_PACK_U32(buf, var->dest_port);
1189 BCM_PACK_U32(buf, var->dest_group);
1190@@ -9989,12 +9992,32 @@
1191 BCM_PACK_U32(buf, var->forwarding_type);
1192 BCM_PACK_U32(buf, var->forwarding_header);
1193 BCM_PACK_U32(buf, var->encap_id);
1194- BCM_PACK_U32(buf, var->mirror_cmd->flags);
1195- BCM_PACK_U8(buf, var->mirror_cmd->forward_strength);
1196- BCM_PACK_U8(buf, var->mirror_cmd->copy_strength);
1197- BCM_PACK_U32(buf, var->mirror_cmd->recycle_cmd);
1198- BCM_PACK_U32(buf, var->core_config_arr->dest_port);
1199- BCM_PACK_U32(buf, var->core_config_arr->encap_id);
1200+
1201+ if(var->mirror_cmd)
1202+ {
1203+ BCM_PACK_U32(buf, var->mirror_cmd->flags);
1204+ BCM_PACK_U8(buf, var->mirror_cmd->forward_strength);
1205+ BCM_PACK_U8(buf, var->mirror_cmd->copy_strength);
1206+ BCM_PACK_U32(buf, var->mirror_cmd->recycle_cmd);
1207+ }
1208+ else
1209+ {
1210+ BCM_PACK_U32(buf, zero_32);
1211+ BCM_PACK_U8(buf, zero_8);
1212+ BCM_PACK_U8(buf, zero_8);
1213+ BCM_PACK_U32(buf, zero_32);
1214+ }
1215+ if(var->core_config_arr)
1216+ {
1217+ BCM_PACK_U32(buf, var->core_config_arr->dest_port);
1218+ BCM_PACK_U32(buf, var->core_config_arr->encap_id);
1219+ }
1220+ else
1221+ {
1222+ BCM_PACK_U32(buf, zero_32);
1223+ BCM_PACK_U32(buf, zero_32);
1224+ }
1225+
1226 BCM_PACK_U32(buf, var->core_config_arr_len);
1227 BCM_PACK_U32(buf, var->qos_map_id);
1228 BCM_PACK_U32(buf, var->tunnel_termination_trap_strength);
1229@@ -10005,6 +10028,9 @@
1230 uint8 *
1231 _bcm_unpack_rx_trap_config(uint8 *buf, bcm_rx_trap_config_t *var)
1232 {
1233+ uint8 var_8, temp;
1234+ uint32 var_32;
1235+
1236 BCM_UNPACK_U32(buf, var->flags);
1237 BCM_UNPACK_U32(buf, var->dest_port);
1238 BCM_UNPACK_U32(buf, var->dest_group);
1239@@ -10019,12 +10045,40 @@
1240 BCM_UNPACK_U32(buf, var->forwarding_type);
1241 BCM_UNPACK_U32(buf, var->forwarding_header);
1242 BCM_UNPACK_U32(buf, var->encap_id);
1243- BCM_UNPACK_U32(buf, var->mirror_cmd->flags);
1244- BCM_UNPACK_U8(buf, var->mirror_cmd->forward_strength);
1245- BCM_UNPACK_U8(buf, var->mirror_cmd->copy_strength);
1246- BCM_UNPACK_U32(buf, var->mirror_cmd->recycle_cmd);
1247- BCM_UNPACK_U32(buf, var->core_config_arr->dest_port);
1248- BCM_UNPACK_U32(buf, var->core_config_arr->encap_id);
1249+
1250+ if(var->mirror_cmd)
1251+ {
1252+ BCM_UNPACK_U32(buf, var->mirror_cmd->flags);
1253+ BCM_UNPACK_U8(buf, var->mirror_cmd->forward_strength);
1254+ BCM_UNPACK_U8(buf, var->mirror_cmd->copy_strength);
1255+ BCM_UNPACK_U32(buf, var->mirror_cmd->recycle_cmd);
1256+ }
1257+ else
1258+ {
1259+ BCM_UNPACK_U32(buf, var_32);
1260+ BCM_UNPACK_U8(buf, var_8);
1261+ BCM_UNPACK_U8(buf, var_8);
1262+ BCM_UNPACK_U32(buf, var_32);
1263+ /* make compiler happy : unsed-but-set */
1264+ temp = var_8;
1265+ var_8 = var_32;
1266+ var_32 = temp;
1267+ }
1268+ if(var->core_config_arr)
1269+ {
1270+ BCM_UNPACK_U32(buf, var->core_config_arr->dest_port);
1271+ BCM_UNPACK_U32(buf, var->core_config_arr->encap_id);
1272+ }
1273+ else
1274+ {
1275+ BCM_UNPACK_U32(buf, var_32);
1276+ BCM_UNPACK_U32(buf, var_32);
1277+ /* make compiler happy : unsed-but-set */
1278+ temp = var_8;
1279+ var_8 = var_32;
1280+ var_32 = temp;
1281+ }
1282+
1283 BCM_UNPACK_U32(buf, var->core_config_arr_len);
1284 BCM_UNPACK_U32(buf, var->qos_map_id);
1285 BCM_UNPACK_U32(buf, var->tunnel_termination_trap_strength);
1286diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/bcm/rpc/server.c sdk-all-6.5.7/src/bcm/rpc/server.c
1287--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/bcm/rpc/server.c 2016-12-01 05:17:00.000000000 +0200
1288+++ sdk-all-6.5.7/src/bcm/rpc/server.c 2017-01-26 12:59:00.779462885 +0200
1289@@ -111294,11 +111294,19 @@
1290 r_p_config = NULL;
1291 } else {
1292 r_p_config = &config;
1293+ bcm_rx_trap_config_t_init(r_p_config);
1294 (void) _bcm_unpack_rx_trap_config(r_pp, r_p_config);
1295 }
1296 bcm_rpc_free(r_pkt, r_cookie);
1297
1298- r_ret = bcm_rx_trap_set(unit, trap_id, r_p_config);
1299+ if(r_p_config)
1300+ {
1301+ r_ret = bcm_rx_trap_set(unit, trap_id, r_p_config);
1302+ }
1303+ else
1304+ {
1305+ r_ret = BCM_E_EMPTY;
1306+ }
1307
1308 r_pkt = bcm_rpc_setup('S', (uint32 *)0, 4, r_seq, r_ret);
1309 r_pp = r_pkt + BCM_RPC_HLEN+4;
1310diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/systems/linux/user/common/socdiag.c sdk-all-6.5.7/systems/linux/user/common/socdiag.c
1311--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/systems/linux/user/common/socdiag.c 2016-12-01 05:18:40.000000000 +0200
1312+++ sdk-all-6.5.7/systems/linux/user/common/socdiag.c 2017-01-26 13:02:16.000246446 +0200
1313@@ -177,7 +177,11 @@
1314 /*
1315 * Main loop.
1316 */
1317-int main(int argc, char *argv[])
1318+#ifndef BUILD_ING_AS_LIB
1319+ int main(int argc, char *argv[])
1320+#else
1321+ int socdiag_main(int argc, char *argv[])
1322+#endif
1323 {
1324 int i, len;
1325 char *envstr;
1326@@ -260,8 +264,10 @@
1327 #endif
1328
1329 diag_shell();
1330-
1331+
1332+#ifndef BUILD_ING_AS_LIB
1333 linux_bde_destroy(bde);
1334+#endif
1335 #ifdef MEMLOG_SUPPORT
1336 if (memlog_lock) {
1337 sal_mutex_destroy(memlog_lock);
1338diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/systems/sim/socdiag.c sdk-all-6.5.7/systems/sim/socdiag.c
1339--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/systems/sim/socdiag.c 2016-12-01 05:18:41.000000000 +0200
1340+++ sdk-all-6.5.7/systems/sim/socdiag.c 2017-01-26 13:09:21.033560205 +0200
1341@@ -31,11 +31,16 @@
1342 /*
1343 * Main loop.
1344 */
1345-int main(int argc, char *argv[])
1346+#ifndef BUILD_ING_AS_LIB
1347+ int main(int argc, char *argv[])
1348+#else
1349+ int socdiag_main(int argc, char *argv[])
1350+#endif
1351 {
1352 char *socrc = SOC_INIT_RC;
1353 char *config_file = NULL, *config_temp = NULL;
1354 int len = 0;
1355+ FILE *fp;
1356
1357 if ((config_file = getenv("BCM_CONFIG_FILE")) != NULL) {
1358 len = sal_strlen(config_file);
1359@@ -56,6 +61,12 @@
1360 exit(1);
1361 }
1362
1363+ if ((fp = sal_fopen("rc.soc", "r")) != NULL)
1364+ {
1365+ setenv("SOC_BOOT_SCRIPT", "rc.soc", 0);
1366+ sal_fclose(fp);
1367+ }
1368+
1369 #ifdef DEBUG_STARTUP
1370 debugk_select(DEBUG_STARTUP);
1371 #endif
1372
1373diff -Naur /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/bcm/rpc/rpc.c sdk-all-6.5.7/src/bcm/rpc/rpc.c
1374--- /projects/NTSW_SW_PRJS/ExternalReleases/BCM/6.5.7/ga/sdk-all-6.5.7/src/bcm/rpc/rpc.c 2016-11-30 22:17:00.000000000 -0500
1375+++ sdk-all-6.5.7/src/bcm/rpc/rpc.c 2017-01-27 08:27:37.656186371 -0500
1376@@ -268,7 +268,7 @@
1377
1378 bp = buf;
1379 BCM_PACK_U32(bp, seq);
1380-
1381+/*************** IL 2017-01-26 WHY ADD these check?? not in 6.5.6 *********
1382 if (!BCM_UNIT_VALID(unit) || (BCM_CONTROL(unit)->drv_control == NULL)) {
1383 _bcm_rpc_unlink_request(req);
1384 sal_sem_destroy(req->sem);
1385@@ -276,7 +276,7 @@
1386 sal_free((void *)req);
1387 return BCM_E_MEMORY;
1388 }
1389-
1390+**************************************************************************/
1391 cpu = *(cpudb_key_t *)BCM_CONTROL(unit)->drv_control;
1392 #ifdef BCM_RPC_ATP_TX_CALLBACK
1393 /*
1394