blob: defac3812d0a295a9cc2569474071b541cbb389f [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2015 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24#if WITH_LIB_MINIP
25#include <app.h>
26
27#include <platform.h>
28#include <stdio.h>
29#include <debug.h>
30#include <string.h>
31#include <pow2.h>
32#include <err.h>
33#include <assert.h>
34#include <trace.h>
35
36#include <app/lkboot.h>
37
38#include "lkboot.h"
39
40#include <lib/minip.h>
41
42#define LOCAL_TRACE 0
43
44static ssize_t tcp_readx(void *s, void *_data, size_t len) {
45 char *data = _data;
46 while (len > 0) {
47 int r = tcp_read(s, data, len);
48 if (r <= 0) return -1;
49 data += r;
50 len -= r;
51 }
52 return 0;
53}
54
55lkb_t *lkboot_tcp_opened(void *s)
56{
57 lkb_t *lkb;
58
59 lkb = lkboot_create_lkb(s, tcp_readx, (void *)tcp_write);
60 if (!lkb)
61 return NULL;
62
63 return lkb;
64}
65
66#endif