1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  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,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #ifndef __BOOTUTIL_SERIAL_PRIV_H__
21 #define __BOOTUTIL_SERIAL_PRIV_H__
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /*
28  * From shell.h
29  */
30 #define SHELL_NLIP_PKT_START1   6
31 #define SHELL_NLIP_PKT_START2   9
32 
33 #define SHELL_NLIP_DATA_START1  4
34 #define SHELL_NLIP_DATA_START2  20
35 
36 /*
37  * From newtmgr.h
38  */
39 #define MGMT_ERR_OK             0
40 #define MGMT_ERR_EUNKNOWN       1
41 #define MGMT_ERR_ENOMEM         2
42 #define MGMT_ERR_EINVAL         3
43 #define MGMT_ERR_ENOENT         5
44 #define MGMT_ERR_ENOTSUP        8
45 #define MGMT_ERR_EBUSY		10
46 
47 #define NMGR_OP_READ            0
48 #define NMGR_OP_WRITE           2
49 
50 #define MGMT_GROUP_ID_DEFAULT   0
51 #define MGMT_GROUP_ID_IMAGE     1
52 #define MGMT_GROUP_ID_PERUSER  64
53 
54 #define NMGR_ID_ECHO            0
55 #define NMGR_ID_CONS_ECHO_CTRL  1
56 #define NMGR_ID_RESET           5
57 
58 #ifndef __packed
59 #define __packed __attribute__((__packed__))
60 #endif
61 
62 struct nmgr_hdr {
63     uint8_t  nh_op;             /* NMGR_OP_XXX */
64     uint8_t  nh_flags;
65     uint16_t nh_len;            /* length of the payload */
66     uint16_t nh_group;          /* NMGR_GROUP_XXX */
67     uint8_t  nh_seq;            /* sequence number */
68     uint8_t  nh_id;             /* message ID within group */
69 } __packed;
70 
71 /*
72  * From imgmgr.h
73  */
74 #define IMGMGR_NMGR_ID_STATE            0
75 #define IMGMGR_NMGR_ID_UPLOAD           1
76 
77 void boot_serial_input(char *buf, int len);
78 extern const struct boot_uart_funcs *boot_uf;
79 
80 /**
81  * @brief Selects direct image to upload according to the "image"
82  * parameter of the mcumgr update frame.
83  *
84  * @param[in] image_id  the value of the "image" parameter of the
85  *                      mcumgr update frame to be translated.
86  *
87  * @return flash area ID for the image if defined;
88  *         -EINVAL when flash area for given image number has not been
89  *         defined.
90  */
91 extern int flash_area_id_from_direct_image(int image_id);
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif /*  __BOOTUTIL_SERIAL_PRIV_H__ */
98