Coverage Report

Created: 2026-01-10 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wpantund/src/ncp-spinel/SpinelNCPTaskWake.cpp
Line
Count
Source
1
/*
2
 *
3
 * Copyright (c) 2016 Nest Labs, Inc.
4
 * All rights reserved.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 *
18
 */
19
20
#if HAVE_CONFIG_H
21
#include <config.h>
22
#endif
23
24
#include "assert-macros.h"
25
#include <syslog.h>
26
#include <errno.h>
27
#include "SpinelNCPTaskWake.h"
28
#include "SpinelNCPInstance.h"
29
#include "spinel-extra.h"
30
31
using namespace nl;
32
using namespace nl::wpantund;
33
34
nl::wpantund::SpinelNCPTaskWake::SpinelNCPTaskWake(
35
  SpinelNCPInstance* instance,
36
  CallbackWithStatusArg1 cb
37
7.27k
):  SpinelNCPTask(instance, cb)
38
7.27k
{
39
7.27k
}
40
41
void
42
nl::wpantund::SpinelNCPTaskWake::finish(int status, const boost::any& value)
43
6.13k
{
44
6.13k
  mInstance->mResetIsExpected = false;
45
46
6.13k
  SpinelNCPTask::finish(status, value);
47
6.13k
}
48
49
50
int
51
nl::wpantund::SpinelNCPTaskWake::vprocess_event(int event, va_list args)
52
198k
{
53
198k
  int ret = kWPANTUNDStatus_Failure;
54
55
198k
  EH_BEGIN();
56
57
  // The first event to a task is EVENT_STARTING_TASK. The following
58
  // line makes sure that we don't start processing this task
59
  // until it is properly scheduled. All tasks immediately receive
60
  // the initial `EVENT_STARTING_TASK` event, but further events
61
  // will only be received by that task once it is that task's turn
62
  // to execute.
63
7.27k
  EH_WAIT_UNTIL(EVENT_STARTING_TASK != event);
64
65
5.61k
  mInstance->set_ncp_power(true);
66
5.61k
  mInstance->mResetIsExpected = true;
67
68
5.61k
  if (mInstance->mCapabilities.count(SPINEL_CAP_MCU_POWER_STATE)) {
69
249
    mNextCommand = SpinelPackData(
70
249
      SPINEL_FRAME_PACK_CMD_PROP_VALUE_SET(SPINEL_DATATYPE_UINT8_S),
71
249
      SPINEL_PROP_MCU_POWER_STATE,
72
249
      SPINEL_MCU_POWER_STATE_ON
73
249
    );
74
75
249
    EH_SPAWN(&mSubPT, vprocess_send_command(event, args));
76
235
    ret = mNextCommandRet;
77
235
    require_noerr(ret, on_error);
78
79
5.36k
  } else {
80
5.36k
    CONTROL_REQUIRE_PREP_TO_SEND_COMMAND_WITHIN(NCP_DEFAULT_COMMAND_SEND_TIMEOUT, on_error);
81
5.30k
    GetInstance(this)->mOutboundBufferLen = spinel_datatype_pack(GetInstance(this)->mOutboundBuffer, sizeof(GetInstance(this)->mOutboundBuffer), "Ci", 0, SPINEL_CMD_NOOP);
82
5.30k
    CONTROL_REQUIRE_OUTBOUND_BUFFER_FLUSHED_WITHIN(NCP_DEFAULT_COMMAND_SEND_TIMEOUT, on_error);
83
84
5.29k
    EH_REQUIRE_WITHIN(
85
5.29k
      NCP_DEFAULT_COMMAND_RESPONSE_TIMEOUT,
86
5.29k
      !ncp_state_is_sleeping(mInstance->get_ncp_state())
87
5.29k
        && (!ncp_state_is_initializing(mInstance->get_ncp_state())),
88
5.29k
      on_error
89
5.29k
    );
90
91
2.36k
    ret = kWPANTUNDStatus_Ok;
92
2.36k
  }
93
94
2.45k
  finish(ret);
95
96
2.45k
  EH_EXIT();
97
98
3.03k
on_error:
99
100
3.03k
  if (ret == kWPANTUNDStatus_Ok) {
101
0
    ret = kWPANTUNDStatus_Failure;
102
0
  }
103
104
3.03k
  syslog(LOG_ERR, "Wake failed: %d", ret);
105
106
3.03k
  mInstance->reinitialize_ncp();
107
108
3.03k
  finish(ret);
109
110
198k
  EH_END();
111
0
}