1 | /*
|
---|
2 | * TOPPERS ECHONET Lite Communication Middleware
|
---|
3 | *
|
---|
4 | * Copyright (C) 2014 Cores Co., Ltd. Japan
|
---|
5 | *
|
---|
6 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
7 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
8 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
9 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
10 | * \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
11 | * XR[hÉÜÜêĢ鱯D
|
---|
12 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
13 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
14 | gip
|
---|
15 | * Ò}j
|
---|
16 | AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL
|
---|
17 | * Ì³ÛØKèðfÚ·é±ÆD
|
---|
18 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
19 | * pūȢ`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
20 | * ÆD
|
---|
21 | * (a) Äzzɺ¤hL
|
---|
22 | gipÒ}j
|
---|
23 | AÈÇjÉCãLÌ
|
---|
24 | * ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD
|
---|
25 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
26 | * ñ·é±ÆD
|
---|
27 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
28 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
29 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
30 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
31 | * ÆÓ·é±ÆD
|
---|
32 | *
|
---|
33 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
34 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
35 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
36 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
37 | * ÌÓCðíÈ¢D
|
---|
38 | *
|
---|
39 | * @(#) $Id: uip_adpt.c 101 2015-06-02 15:37:23Z coas-nagasima $
|
---|
40 | */
|
---|
41 |
|
---|
42 | #include <kernel.h>
|
---|
43 | #include "uip.h"
|
---|
44 | #include "uip_adpt.h"
|
---|
45 | #include "t_syslog.h"
|
---|
46 | #include "kernel_cfg.h"
|
---|
47 |
|
---|
48 | /*
|
---|
49 | * uip_taskðN®
|
---|
50 | */
|
---|
51 | ER uip_start()
|
---|
52 | {
|
---|
53 | ER ret;
|
---|
54 |
|
---|
55 | /* uip_taskpüúnhÌN® */
|
---|
56 | ret = sta_cyc(UIP_CYCHDR);
|
---|
57 | if (ret != E_OK) {
|
---|
58 | syslog(LOG_DEBUG, "sta_cyc() result = %d", ret);
|
---|
59 | return ret;
|
---|
60 | }
|
---|
61 |
|
---|
62 | return E_OK;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /*
|
---|
66 | * convert_hexdigit -- 16i¨¶ñÏ·
|
---|
67 | */
|
---|
68 | int_t convert_hexdigit (char *buf, uint_t val, int_t radix, int_t width, char padchar)
|
---|
69 | {
|
---|
70 | static const char radhex[] = "0123456789abcdef";
|
---|
71 |
|
---|
72 | char digits[11], *start;
|
---|
73 | int_t ix, pad;
|
---|
74 |
|
---|
75 | ix = 0;
|
---|
76 | start = buf;
|
---|
77 | do {
|
---|
78 | digits[ix ++] = radhex[(val % radix) & 0x0f];
|
---|
79 | val /= radix;
|
---|
80 | } while (val != 0);
|
---|
81 | for (pad = ix; pad < width; pad ++)
|
---|
82 | *buf ++ = padchar;
|
---|
83 | while (ix -- > 0)
|
---|
84 | *buf ++ = digits[ix];
|
---|
85 | *buf = '\0';
|
---|
86 | return (int_t)(buf - start);
|
---|
87 | }
|
---|
88 |
|
---|
89 | /*
|
---|
90 | * ip2str -- IPv4 AhXð¶ñÉÏ··éB
|
---|
91 | */
|
---|
92 | char *ip2str(char *buf, const T_IN4_ADDR ipaddr)
|
---|
93 | {
|
---|
94 | char *start;
|
---|
95 |
|
---|
96 | start = buf;
|
---|
97 | buf += convert_hexdigit(buf, (uint_t)((ipaddr[0] >> 0) & 0xff), 10, 0, ' ');
|
---|
98 | *(buf ++) = '.';
|
---|
99 | buf += convert_hexdigit(buf, (uint_t)((ipaddr[0] >> 8) & 0xff), 10, 0, ' ');
|
---|
100 | *(buf ++) = '.';
|
---|
101 | buf += convert_hexdigit(buf, (uint_t)((ipaddr[1] >> 0) & 0xff), 10, 0, ' ');
|
---|
102 | *(buf ++) = '.';
|
---|
103 | buf += convert_hexdigit(buf, (uint_t)((ipaddr[1] >> 8) & 0xff), 10, 0, ' ');
|
---|
104 | *buf = '\0';
|
---|
105 |
|
---|
106 | return start;
|
---|
107 | }
|
---|
108 |
|
---|
109 | ID uip_getid(struct uip_conn *conn)
|
---|
110 | {
|
---|
111 | int index;
|
---|
112 |
|
---|
113 | index = ((intptr_t)conn - (intptr_t)uip_conns) / sizeof(uip_conns[0]);
|
---|
114 | if ((index < 0) || (index >= sizeof(uip_conns) / sizeof(uip_conns[0])))
|
---|
115 | return -1;
|
---|
116 |
|
---|
117 | return index + 1;
|
---|
118 | }
|
---|
119 |
|
---|
120 | struct uip_conn *uip_getconn(ID connid)
|
---|
121 | {
|
---|
122 | int index = connid - 1;
|
---|
123 |
|
---|
124 | if ((index < 0) || (index >= sizeof(uip_conns) / sizeof(uip_conns[0])))
|
---|
125 | return NULL;
|
---|
126 |
|
---|
127 | return &uip_conns[index];
|
---|
128 | }
|
---|