blob: a29243a2de85007b0ad174439f490621cfcb17d6 [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001/*
2<:copyright-BRCM:2014:DUAL/GPL:standard
3
4 Copyright (c) 2014 Broadcom Corporation
5 All Rights Reserved
6
7Unless you and Broadcom execute a separate written software license
8agreement governing use of this software, this software is licensed
9to you under the terms of the GNU General Public License version 2
10(the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
11with the following added to such license:
12
13 As a special exception, the copyright holders of this software give
14 you permission to link this software with independent modules, and
15 to copy and distribute the resulting executable under terms of your
16 choice, provided that you also meet, for each linked independent
17 module, the terms and conditions of the license of that module.
18 An independent module is a module which is not derived from this
19 software. The special exception does not apply to any modifications
20 of the software.
21
22Not withstanding the above, under no circumstances may you combine
23this software in any way with any other Broadcom software provided
24under a license other than the GPL, without Broadcom's express prior
25written consent.
26
27:>
28*/
29
30#include <bcmos_system.h>
31#include <bcmcli.h>
32#include <bcmolt_model_types.h>
33#include <bcmolt_msg.h>
34#include <bcmolt_api.h>
35#include <bcm_api_cli_helpers.h>
36#include "bcmolt_image_transfer.h"
37#include "bcmolt_image_transfer_cli.h"
38
39static bcmos_bool bcmolt_user_appl_device_state_is_ready(bcmolt_devid device)
40{
41 bcmos_errno err;
42 bcmolt_device_cfg cfg = {};
43 bcmolt_device_key key = {};
44
45 BCMOLT_CFG_INIT(&cfg, device, key);
46 BCMOLT_CFG_PROP_GET(&cfg, device, state);
47 err = bcmolt_cfg_get(device, &cfg.hdr);
48 return (err == BCM_ERR_OK) && (cfg.data.state == BCMOLT_DEVICE_STATE_READY);
49}
50
51/** start the image transfer.
52 */
53static bcmos_errno bcmolt_user_appl_cli_image_transfer_start(bcmcli_session *session,
54 const bcmcli_cmd_parm parms[], uint16_t n_parms)
55{
56 bcmolt_device_image_type image_type;
57 bcmolt_devid device = 0;
58 bcmos_errno err;
59
60 if (!bcmolt_user_appl_device_state_is_ready(device))
61 {
62 bcmcli_session_print(session, "device not connected\n");
63 return BCM_ERR_NOT_CONNECTED;
64 }
65
66 image_type = bcmcli_find_named_parm(session, "image_type")->value.unumber;
67
68 err = bcmolt_user_mftp_start(device, image_type);
69 if (err != BCM_ERR_OK)
70 {
71 bcmcli_session_print(session, "%s\n", bcmos_strerror(err));
72 }
73 return err;
74}
75
76bcmos_errno bcmolt_user_appl_cli_image_transfer_init(bcmcli_entry *top_dir)
77{
78 bcmcli_entry *dir = bcmcli_dir_add(top_dir, "image_transfer",
79 "Image Transfer user application", BCMCLI_ACCESS_ADMIN, NULL);
80 BCMOS_CHECK_RETURN_ERROR(!dir, BCM_ERR_NOMEM);
81
82 BCMCLI_MAKE_CMD(dir, "start", "Start Image Transfer application", bcmolt_user_appl_cli_image_transfer_start,
83 BCMCLI_MAKE_PARM_ENUM("image_type", "Image type", bcmolt_device_image_type_string_table, BCMCLI_PARM_FLAG_NONE));
84
85 return BCM_ERR_OK;
86}
87