blob: 2d3a6a822ead0b1a5564efc84b2f84c590194b07 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001This enables automatic connection after the control daemon is started,
2and also stops the connection on termination.
3
4Using the autoboot restart command (in combination with configuring the
5state machine to wait) is necessary because the stop command doesn't
6actually stop the connection, and would also leave the driver in a state
7where an explicit start command is necessary to connect again.
8
9--- a/src/dsl_cpe_init_cfg.c
10+++ b/src/dsl_cpe_init_cfg.c
11@@ -27,7 +27,7 @@ DSL_InitData_t gInitCfgData =
12 DSL_CPE_FW2_SET(DSL_NULL, 0x0),
13 DSL_CPE_XTU_SET(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7),
14 DSL_CPE_LINE_INV_NE_SET(DSL_NULL),
15- DSL_CPE_AUTOBOOT_CTRL_SET(DSL_AUTOBOOT_CTRL_STOP),
16+ DSL_CPE_AUTOBOOT_CTRL_SET(DSL_AUTOBOOT_CTRL_START),
17 DSL_CPE_AUTOBOOT_CFG_SET(DSL_FALSE, DSL_FALSE, DSL_FALSE),
18 DSL_CPE_TEST_MODE_CTRL_SET(DSL_TESTMODE_DISABLE),
19 DSL_CPE_LINE_ACTIVATE_CTRL_SET(DSL_G997_INHIBIT_LDSF, DSL_G997_INHIBIT_ACSF, DSL_G997_NORMAL_STARTUP),
20--- a/src/dsl_cpe_control.c
21+++ b/src/dsl_cpe_control.c
22@@ -6491,6 +6491,57 @@ DSL_int32_t DSL_CPE_DeviceInit (
23 return ret;
24 }
25
26+DSL_CPE_STATIC DSL_void_t DSL_CPE_ShutdownConnection(void)
27+{
28+ DSL_Error_t nRet = DSL_SUCCESS;
29+ DSL_int_t nDevice = 0;
30+ DSL_AutobootConfig_t sAutobootCfg;
31+ DSL_AutobootControl_t sAutobootCtl;
32+
33+ for (nDevice = 0; nDevice < DSL_CPE_MAX_DSL_ENTITIES; ++nDevice)
34+ {
35+ g_bWaitBeforeConfigWrite[nDevice] = DSL_TRUE;
36+ g_bWaitBeforeLinkActivation[nDevice] = DSL_TRUE;
37+ g_bWaitBeforeRestart[nDevice] = DSL_TRUE;
38+
39+ g_bAutoContinueWaitBeforeConfigWrite[nDevice] = DSL_FALSE;
40+ g_bAutoContinueWaitBeforeLinkActivation[nDevice] = DSL_FALSE;
41+ g_bAutoContinueWaitBeforeRestart[nDevice] = DSL_FALSE;
42+
43+ memset(&sAutobootCfg, 0x0, sizeof(DSL_AutobootConfig_t));
44+ sAutobootCfg.data.nStateMachineOptions.bWaitBeforeConfigWrite = DSL_TRUE;
45+ sAutobootCfg.data.nStateMachineOptions.bWaitBeforeLinkActivation = DSL_TRUE;
46+ sAutobootCfg.data.nStateMachineOptions.bWaitBeforeRestart = DSL_TRUE;
47+
48+ nRet = (DSL_Error_t)DSL_CPE_Ioctl(
49+ DSL_CPE_GetGlobalContext()->fd[nDevice],
50+ DSL_FIO_AUTOBOOT_CONFIG_SET, (DSL_int_t)&sAutobootCfg);
51+
52+ if (nRet < DSL_SUCCESS)
53+ {
54+ DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
55+ "Autoboot configuration for device (%d) failed!, nRet = %d!"
56+ DSL_CPE_CRLF, nDevice, sAutobootCfg.accessCtl.nReturn));
57+ }
58+
59+ memset(&sAutobootCtl, 0, sizeof(DSL_AutobootControl_t));
60+ sAutobootCtl.data.nCommand = DSL_AUTOBOOT_CTRL_RESTART;
61+
62+ nRet = (DSL_Error_t)DSL_CPE_Ioctl(
63+ DSL_CPE_GetGlobalContext()->fd[nDevice],
64+ DSL_FIO_AUTOBOOT_CONTROL_SET, (DSL_int_t)&sAutobootCtl);
65+
66+ if (nRet < DSL_SUCCESS)
67+ {
68+ DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
69+ "Autoboot restart for device (%d) failed!, nRet = %d!"
70+ DSL_CPE_CRLF, nDevice, sAutobootCtl.accessCtl.nReturn));
71+ }
72+ }
73+
74+ DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
75+ "Connection shutdown finished." DSL_CPE_CRLF));
76+}
77
78 /**
79 Termination handler. Will clean up in case of ctrl-c.
80@@ -6521,6 +6572,8 @@ DSL_CPE_STATIC DSL_void_t DSL_CPE_Termi
81
82 DSL_CPE_Control_Context_t *pCtrlCtx;
83
84+ DSL_CPE_ShutdownConnection();
85+
86 pCtrlCtx = DSL_CPE_GetGlobalContext();
87 if (pCtrlCtx != DSL_NULL)
88 {
89@@ -7416,6 +7469,9 @@ void DSL_CPE_main(void)
90 DSL_CPE_STATIC DSL_Error_t DSL_CPE_Control_Exit (DSL_void_t * pContext)
91 {
92 dummy_console_t *pConsole = pContext;
93+
94+ DSL_CPE_ShutdownConnection();
95+
96 pConsole->bRun = DSL_FALSE;
97 return DSL_SUCCESS;
98 }