source: uKadecot/trunk/ecnl_ssp/echonet_task.c@ 101

Last change on this file since 101 was 101, checked in by coas-nagasima, 8 years ago

TOPPERS/uKadecotのソースコードを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/plain
File size: 57.8 KB
Line 
1/*
2 * TOPPERS ECHONET Lite Communication Middleware
3 *
4 * Copyright (C) 2014 Cores Co., Ltd. Japan
5 *
6 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
7 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
8 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
9 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
10 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
11 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
12 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
13 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
14ƒƒ“ƒgi—˜—p
15 * ŽÒƒ}ƒjƒ…
16ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
17 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
18 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
19 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
20 * ‚ƁD
21 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
22ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
23ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
24 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
25 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
26 * •ñ‚·‚邱‚ƁD
27 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
28 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
29 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
30 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
31 * –Ɛӂ·‚邱‚ƁD
32 *
33 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
34 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
35 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
36 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
37 * ‚̐ӔC‚𕉂í‚È‚¢D
38 *
39 * @(#) $Id: echonet_task.c 101 2015-06-02 15:37:23Z coas-nagasima $
40 */
41
42/*
43 * ECHONET Lite ƒ^ƒXƒN
44 */
45
46#include <kernel.h>
47#include <stdio.h>
48#include <stdlib.h>
49#include <stdarg.h>
50#include <string.h>
51#include <t_syslog.h>
52
53#include "syssvc/serial.h"
54#include "syssvc/syslog.h"
55
56#include "uip.h"
57
58#include "echonet.h"
59#include "echonet_fbs.h"
60#include "echonet_task.h"
61#include "echonet_dbg.h"
62#ifdef ECHONET_CONTROLLER_EXTENTION
63#include "echonet_agent.h"
64#endif
65
66#ifndef ECHONET_TASK_GET_TIMER
67#define ECHONET_TASK_GET_TIMER TMO_FEVR
68#endif /* ECHONET_TASK_GET_TIMER */
69
70#ifndef ECHONET_TASK_PROGRESS
71#define ECHONET_TASK_PROGRESS(timer)
72#endif /* ECHONET_TASK_PROGRESS */
73
74#ifndef ECHONET_TASK_TIMEOUT
75#define ECHONET_TASK_TIMEOUT
76#endif /* ECHONET_TASK_TIMEOUT */
77
78static struct ecnl_state s;
79
80/* ŽóMƒƒbƒZ[ƒW‚ðŠJ•ú‚·‚é‚©”Û‚© */
81static bool_t g_release_esv;
82
83/* ŽóMƒƒbƒZ[ƒW‚ð“]‘—‚·‚é‚©”Û‚© */
84bool_t g_forward_esv;
85
86ER _ecn_tsk_ntf_inl(intptr_t fa_exinf);
87
88ER _ecn_tsk_snd_mbx(ECN_FBS_ID fa_rsp_fbs, bool_t from_app)
89{
90 ER a_ret;
91 intptr_t msg = (intptr_t)fa_rsp_fbs.ptr;
92 ID mbxid = ecn_udp_mailboxid;
93 ECN_ENOD_ID target = fa_rsp_fbs.ptr->hdr.target;
94#ifdef ECN_DBG_PUT_ENA
95 intptr_t a_fbs_sub1 = (intptr_t)fa_rsp_fbs.ptr->lnk.p_sub[0];
96#endif
97 if (from_app && (((T_EDATA *)fa_rsp_fbs.ptr)->hdr.edata.esv == ESV_INFC)) {
98 if (target < ENOD_MULTICAST_ID || tnum_enodadr <= target)
99 return E_NOEXS;
100 apitid_table[target] = ((T_EDATA *)fa_rsp_fbs.ptr)->hdr.ecn_hdr.tid;
101 mbxid = ecn_svc_mailboxid;
102 }
103 else {
104 switch (target) {
105 case ENOD_MULTICAST_ID:
106 if (from_app)
107 apitid_table[target] = ((T_EDATA *)fa_rsp_fbs.ptr)->hdr.ecn_hdr.tid;
108
109 mbxid = ecn_udp_mailboxid;
110 break;
111 case ENOD_LOCAL_ID:
112 if (from_app)
113 mbxid = ecn_svc_mailboxid;
114 else
115 mbxid = ecn_api_mailboxid;
116 break;
117 case ENOD_API_ID:
118 mbxid = ecn_api_mailboxid;
119 break;
120 default:
121 if (from_app)
122 apitid_table[target] = ((T_EDATA *)fa_rsp_fbs.ptr)->hdr.ecn_hdr.tid;
123
124 if (target < ENOD_REMOTE_ID || tnum_enodadr <= target)
125 return E_NOEXS;
126 target += - ENOD_REMOTE_ID + 1;
127 if (from_app && (target < tnum_enodid)) {
128 /* ”ñ“¯Šú‚̃Šƒ‚[ƒgƒm[ƒh‚̓T[ƒrƒXˆ—ƒ^ƒXƒN‚ŏˆ—‚·‚é */
129 switch (eobjcb_table[target].profile->eobjatr) {
130 case EOBJ_SYNC_REMOTE_NODE:
131 mbxid = ecn_udp_mailboxid;
132 break;
133 case EOBJ_ASYNC_REMOTE_NODE:
134 mbxid = ecn_svc_mailboxid;
135 break;
136 default:
137 return E_SYS;
138 }
139 }
140 else {
141 mbxid = ecn_udp_mailboxid;
142 }
143 break;
144 }
145 }
146#ifdef ECN_DBG_PUT_ENA
147 ECN_DBG_PUT "psnd_dtq(%d, 0x%08X-0x%08X)", mbxid, (intptr_t)msg, a_fbs_sub1 ECN_DBG_END;
148 _ecn_dbg_bindmp((const uint8_t *)msg, 256);
149#endif
150 a_ret = psnd_dtq(mbxid, msg);
151#ifdef ECN_DBG_PUT_ENA
152 ECN_DBG_PUT "psnd_dtq(%d, 0x%08X-0x%08X) result = %d:%s", mbxid, (intptr_t)msg, a_fbs_sub1, a_ret, itron_strerror(a_ret) ECN_DBG_END;
153#endif
154 return a_ret;
155}
156
157static void _ecn_tsk_int_module_init(intptr_t fa_exinf);
158static void _ecn_tsk_int_startup(intptr_t fa_exinf);
159static uint16_t _ecn_tsk_new_tid(void);
160static void _ecn_tsk_int_msg(intptr_t fa_exinf, ECN_FBS_ID fa_fbs_id);
161static void _ecn_tsk_ecn_msg(intptr_t fa_exinf, ECN_FBS_ID fa_fbs_id);
162
163static void _ecn_tsk_eoj_set(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_update,
164 ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv, ECN_SRV_CODE fa_sna_esv,
165 ECN_FBS_ID *fa_fbs_anno);
166static void _ecn_tsk_eoj_get(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_forward, ATR fa_access,
167 ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv, ECN_SRV_CODE fa_sna_esv);
168static void _ecn_tsk_eoj_res(ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv,
169 ECN_SRV_CODE fa_sna_esv);
170static void _ecn_tsk_eoj_set_get(const EOBJINIB *fp_obj, ATR fa_eobjatr,
171 ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv, ECN_SRV_CODE fa_sna_esv,
172 ECN_FBS_ID *fa_fbs_anno);
173static void _ecn_tsk_eoj_set_get_res(const EOBJINIB *fp_obj, ATR fa_eobjatr,
174 ECN_FBS_ID fa_fbs_id, ECN_FBS_ID *fa_fbs_anno);
175
176/* ƒ‚ƒWƒ…
177[ƒ‹‰Šú‰»ƒtƒ‰ƒO */
178static uint8_t m_eobjlist_need_init = 1;
179
180/* ƒV[ƒPƒ“ƒX”ԍ† */
181static uint16_t g_current_tid = 1;
182
183/*
184 * ECHONET Lite ƒ^ƒXƒN‚̏‰Šú‰»iƒRƒ“ƒXƒgƒ‰ƒNƒ^‘Š“–j
185 */
186void echonet_task_init(intptr_t exinf)
187{
188 if (m_eobjlist_need_init)
189 _ecn_tsk_int_module_init(exinf);
190}
191
192/*
193 * ƒ‚ƒWƒ…
194[ƒ‹‰Šú‰»
195 */
196static void _ecn_tsk_int_module_init(intptr_t exinf)
197{
198 if (!m_eobjlist_need_init)
199 return;
200
201 /* ECN_DBG_PUT "[ECHONET MainTask:%d] started", tskid ECN_DBG_END; */
202 syslog(LOG_NOTICE, "[ECHONET MainTask] started");
203
204 m_eobjlist_need_init = 0;
205
206#ifdef ECHONET_CONTROLLER_EXTENTION
207 ecn_agent_init();
208#endif
209}
210
211/*
212 * ECHONET Lite ƒ^ƒXƒN‚Ì–{‘Ì
213 */
214static
215PT_THREAD(echonet_task_pt(intptr_t fa_exinf))
216{
217 ER a_ret, a_ret2;
218 union
219 {
220 intptr_t p_msg;
221 ECN_FBS_ID fbs_id;
222 } a_mdt;
223 static SYSTIM a_prev, a_now;
224 TMO a_timer;
225#ifdef ECHONET_CONTROLLER_EXTENTION
226 TMO a_timera;
227#endif
228
229 PT_BEGIN(&s.pt);
230
231 a_ret = sta_cyc(ecn_svc_cychdrid);
232 if (a_ret != E_OK) {
233 ECN_DBG_PUT "sta_cyc() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
234 PT_EXIT(&s.pt);
235 }
236
237 _ecn_tsk_int_startup(fa_exinf);
238
239 a_ret2 = get_tim(&a_now);
240 if (a_ret2 != E_OK) {
241 ECN_DBG_PUT "get_tim() result = %d:%s", a_ret2, itron_strerror(a_ret2) ECN_DBG_END;
242 PT_EXIT(&s.pt);
243 }
244
245 /* ƒƒbƒZ[ƒWƒ‹[ƒv */
246 for (;;) {
247 a_prev = a_now;
248
249 a_timer = ECHONET_TASK_GET_TIMER;
250#ifdef ECHONET_CONTROLLER_EXTENTION
251 a_timera = ecn_agent_get_timer();
252 if(a_timer == TMO_FEVR){
253 a_timer =a_timera;
254 }
255 else if((a_timera != TMO_FEVR) && (a_timera < a_timer)){
256 a_timer = a_timera;
257 }
258#endif
259 timer_set(&s.timer, a_timer);
260
261 PT_WAIT_UNTIL(&s.pt, (((a_ret = prcv_dtq(ecn_svc_mailboxid, &a_mdt.p_msg)) == E_OK)
262 || ((a_ret = timer_expired(&s.timer) ? E_TMOUT : E_WBLK) == E_TMOUT)));
263 if ((a_ret != E_OK) && (a_ret != E_TMOUT)) {
264 ECN_DBG_PUT "trcv_dtq() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
265 PT_EXIT(&s.pt);
266 }
267
268 a_ret2 = get_tim(&a_now);
269 if (a_ret2 != E_OK) {
270 ECN_DBG_PUT "get_tim() result = %d:%s", a_ret2, itron_strerror(a_ret2) ECN_DBG_END;
271 PT_EXIT(&s.pt);
272 }
273
274 a_timer = a_now - a_prev;
275 ECHONET_TASK_PROGRESS(a_timer);
276#ifdef ECHONET_CONTROLLER_EXTENTION
277 ecn_agent_progress(a_timer);
278#endif
279
280 if (a_ret == E_OK) {
281 ECN_DBG_PUT "trcv_dtq() mbx recv (%d byte)", _ecn_fbs_get_datalen(a_mdt.fbs_id) ECN_DBG_END;
282 g_release_esv = true;
283
284 switch (a_mdt.fbs_id.ptr->hdr.type) {
285 /* “à•”Žg—pƒƒbƒZ[ƒW */
286 case ECN_MSG_INTERNAL:
287 _ecn_tsk_int_msg(fa_exinf, a_mdt.fbs_id);
288 break;
289
290 /* ECHONET—pƒƒbƒZ[ƒW */
291 case ECN_MSG_ECHONET:
292 _ecn_tsk_ecn_msg(fa_exinf, a_mdt.fbs_id);
293 break;
294
295 default:
296 syslog(LOG_WARNING, "echonet_task() a_fbs_id.ptr->k.hdr.k.t_edt.type:0x%02X undefined.", a_mdt.fbs_id.ptr->hdr.type);
297 }
298
299 /* —̈æ‰ð•ú */
300 if (g_release_esv)
301 _ecn_fbs_del(a_mdt.fbs_id);
302 }
303
304 ECHONET_TASK_TIMEOUT;
305#ifdef ECHONET_CONTROLLER_EXTENTION
306 ecn_agent_timeout();
307#endif
308 }
309
310 PT_END(&s.pt);
311}
312
313/*
314 * ECHONET Lite ƒvƒƒgƒXƒŒƒbƒh‹N“®ƒ^ƒXƒN
315 */
316void echonet_task(intptr_t fa_exinf)
317{
318 echonet_task_pt(fa_exinf);
319}
320
321/*
322 * ECHONET Lite ƒ^ƒXƒN‹N“®—pŽüŠúƒnƒ“ƒhƒ‰[
323 */
324void echonet_cychdr(intptr_t exinf)
325{
326 (void)iact_tsk((ID)exinf);
327}
328
329/*
330 * ƒV[ƒPƒ“ƒX”ԍ†¶¬
331 */
332static uint16_t _ecn_tsk_new_tid(void)
333{
334 return g_current_tid++;
335}
336
337/*
338 * —v‹“d•¶ì¬
339 * ˆø”
340 * ECN_FBS_ID *fp_fbs_id Žæ“¾‚µ‚½FBS_ID‚ÌŠi”[æ
341 * ID fa_seoj ‘—MŒ³‚ÌECHONETƒIƒuƒWƒFƒNƒgID
342 * ID fa_deoj ˆ¶æ‚ÌECHONETƒIƒuƒWƒFƒNƒgID
343 * uint8_t fa_epc ƒvƒƒpƒeƒBƒR[ƒh
344 * uint8_t fa_pdc ƒvƒƒpƒeƒB’lƒf[ƒ^ƒTƒCƒY
345 * const void *p_edt ƒvƒƒpƒeƒB’lƒf[ƒ^
346 * ECN_SRV_CODE fa_esv ECHONET Light ƒT[ƒrƒXƒR[ƒh
347 */
348ER _ecn_tsk_mk_esv(ECN_FBS_ID *fp_fbs_id, ID fa_seoj, ID fa_deoj,
349 uint8_t fa_epc, uint8_t fa_pdc, const void *p_edt, ECN_SRV_CODE fa_esv)
350{
351 ER a_ret;
352 int a_size, i;
353 ECN_FBS_ID a_fbs_id = { 0 }; /* —v‹“d•¶—pƒƒ‚ƒŠ */
354 T_ECN_EDT_HDR a_ecn_hdp; /* ecn_hdr+edata+ecn_prp 14byte */
355 ID a_enodid;
356 const EOBJINIB *a_eobj;
357 const EOBJINIB *a_enod;
358
359 if (!fp_fbs_id)
360 return E_PAR; /* Žæ“¾‚µ‚½FBS_ID‚ÌŠi”[æ‚ªNULL */
361 if (ECHONET_MEMPOOL_BLOCK_SIZE <= fa_pdc)
362 return E_PAR; /* ƒvƒƒpƒeƒB’lƒTƒCƒY‚ª‘å‚«‚·‚¬‚é */
363 if (!p_edt && 0 < fa_pdc)
364 return E_PAR; /* ƒvƒƒpƒeƒB’lƒTƒCƒY‚ª1ˆÈã‚Ȃ̂Ƀf[ƒ^ƒ|ƒCƒ“ƒ^‚ªNULL */
365
366 if (fa_seoj <= EOBJ_NULL || tmax_eobjid < fa_seoj)
367 return E_NOEXS; /* ECHONETƒIƒuƒWƒFƒNƒgID‚ª–¢’è‹` */
368#ifndef ECHONET_CONTROLLER_EXTENTION
369 if (fa_deoj < EOBJ_NULL || tmax_eobjid < fa_deoj)
370 return E_NOEXS; /* ECHONETƒIƒuƒWƒFƒNƒgID‚ª–¢’è‹` */
371#else
372 if (fa_deoj < EOBJ_NULL || (tmax_eobjid + TNUM_AEOBJID) < fa_deoj)
373 return E_NOEXS; /* ECHONETƒIƒuƒWƒFƒNƒgID‚ª–¢’è‹` */
374#endif
375 if (fa_deoj == EOBJ_NULL && fa_esv == ESV_INFC)
376 return E_NOEXS; /* ECHONETƒIƒuƒWƒFƒNƒgID‚ª–¢’è‹` */
377
378 /* —v‹Å¬ƒTƒCƒY‚̎擾 */
379 a_size = sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY) + sizeof(T_ECN_PRP);
380
381 /* —v‹“d•¶—pƒƒ‚ƒŠ‚̎擾 */
382 a_ret = _ecn_fbs_cre(a_size, &a_fbs_id);
383 if (a_ret != E_OK || !a_fbs_id.ptr) { /* Šm•ÛŽ¸”s */
384 ECN_DBG_PUT "_ecn_fbs_cre(%d) result = %d:%s",
385 a_size,
386 a_ret, itron_strerror(a_ret) ECN_DBG_END;
387 return E_NOMEM;
388 }
389
390 /* —v‹“d•¶Ý’è */
391 memset(&a_ecn_hdp, 0, sizeof(a_ecn_hdp));
392 a_ecn_hdp.ecn_hdr.ehd1 = ECN_EDH1_ECHONET_LITE;
393 a_ecn_hdp.ecn_hdr.ehd2 = ECN_EDH2_FORMAT_1;
394 a_ecn_hdp.ecn_hdr.tid = _ecn_tsk_new_tid();
395 memcpy(&a_ecn_hdp.edata.seoj, &eobjinib_table[fa_seoj - 1].eojx1, sizeof(a_ecn_hdp.edata.seoj));
396 a_ecn_hdp.edata.esv = fa_esv;
397 a_ecn_hdp.edata.opc = 1; /* ˆ—ƒvƒƒpƒeƒB” */
398 a_ecn_hdp.ecn_prp.epc = fa_epc; /* ƒvƒƒpƒeƒBƒR[ƒh */
399 a_ecn_hdp.ecn_prp.pdc = fa_pdc; /* •tƒf[ƒ^ƒTƒCƒY */
400
401 /* —v‹“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ */
402 a_ret = _ecn_fbs_add_data_ex(a_fbs_id, &a_ecn_hdp, a_size);
403 if (a_ret) {
404 ECN_DBG_PUT "_ecn_fbs_add_data_ex(*, ecn_hdp{esv:0x%02X,epc:0x%02X}, %d) result = %d:%s",
405 a_ecn_hdp.edata.esv, a_ecn_hdp.ecn_prp.epc, a_size,
406 a_ret, itron_strerror(a_ret) ECN_DBG_END;
407 goto lb_except;
408 }
409 if (0 < fa_pdc) {
410 /* •tƒf[ƒ^’ljÁ */
411 a_ret = _ecn_fbs_add_data_ex(a_fbs_id, p_edt, fa_pdc);
412 if (a_ret) {
413 ECN_DBG_PUT "_ecn_fbs_add_data_ex(*, ecn_hdp{esv:0x%02X,epc:0x%02X} edt, %d) result = %d:%s",
414 a_ecn_hdp.edata.esv, a_ecn_hdp.ecn_prp.epc, fa_pdc,
415 a_ret, itron_strerror(a_ret) ECN_DBG_END;
416 goto lb_except;
417 }
418 }
419 if (fa_deoj == 0) {
420 ECN_DBG_PUT "%s", "ƒ}ƒ‹ƒ`ƒLƒƒƒXƒg" ECN_DBG_END;
421 /* fa_deoj == 0 : ƒ}ƒ‹ƒ`ƒLƒƒƒXƒg */
422 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx1 = EOJ_X1_PROFILE;
423 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx2 = EOJ_X2_NODE_PROFILE;
424 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx3 = 0x01;
425 a_fbs_id.ptr->hdr.target = ENOD_MULTICAST_ID;
426 }
427 else if (fa_deoj <= tmax_eobjid) {
428 ECN_DBG_PUT "fa_deoj = %d", fa_deoj ECN_DBG_END;
429 /* if (fa_deoj < 1 || tmax_eobjid < fa_deoj) c‚ُ̈íŒn‚͊֐”–`“ª‚ŏœŠOÏ‚Ý‚Æ‚·‚é */
430 a_eobj = &eobjinib_table[fa_deoj - 1];
431 memcpy(&((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj, &a_eobj->eojx1,
432 sizeof(((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj));
433
434 /* ƒe[ƒuƒ‹‚©‚猟õ */
435 a_fbs_id.ptr->hdr.target = ENOD_NOT_MATCH_ID;
436 a_enodid = (a_eobj->enodid == 0) ? fa_deoj : a_eobj->enodid;
437 a_enod = &eobjinib_table[a_enodid - 1];
438 if ((a_enod->eobjatr == EOBJ_LOCAL_NODE)
439 || ((a_enod->eobjatr == EOBJ_ASYNC_REMOTE_NODE) && (fa_esv == ESV_GET))) {
440 a_fbs_id.ptr->hdr.target = ENOD_LOCAL_ID;
441 }
442 else{
443 for (i = 1; i < tnum_enodid; i++) {
444 const EOBJCB *temp = &eobjcb_table[i];
445 if (a_enod != temp->profile)
446 continue;
447
448 a_fbs_id.ptr->hdr.target = (ECN_ENOD_ID)(i + ENOD_REMOTE_ID - 1);
449 break;
450 }
451 }
452 if (a_fbs_id.ptr->hdr.target == ENOD_NOT_MATCH_ID) {
453 goto lb_except;
454 ECN_DBG_PUT "deoj = %02X %02X %02x : enod not match",
455 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx1,
456 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx2,
457 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx3 ECN_DBG_END;
458 }
459#ifdef ECN_DBG_PUT_ENA
460 else {
461 ECN_DBG_PUT "deoj = %02X %02X %02x : %s",
462 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx1,
463 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx2,
464 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx3,
465 _ecn_dbg_enod2str(a_fbs_id.ptr->hdr.target) ECN_DBG_END;
466 }
467#endif
468 }
469#ifdef ECHONET_CONTROLLER_EXTENTION
470 else{
471 T_ECN_EOJ eoj;
472 ECN_ENOD_ID enodid;
473 ECN_DBG_PUT "fa_deoj = %d", fa_deoj ECN_DBG_END;
474 /* ƒIƒuƒWƒFƒNƒgID‚©‚çEOJ‚ƃm[ƒhID‚ðŽæ“¾ */
475 if(ecn_agent_get_eoj_enodid(fa_deoj, &eoj, &enodid)){
476 memcpy(&((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj, &eoj,
477 sizeof(((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj));
478 a_fbs_id.ptr->hdr.target = enodid;
479 }
480 else {
481 goto lb_except;
482 ECN_DBG_PUT "deoj = %02X %02X %02x : enod not match",
483 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx1,
484 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx2,
485 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx3 ECN_DBG_END;
486 }
487#ifdef ECN_DBG_PUT_ENA
488 else {
489 ECN_DBG_PUT "deoj = %02X %02X %02x : %s",
490 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx1,
491 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx2,
492 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx3,
493 _ecn_dbg_enod2str(a_fbs_id.ptr->hdr.target) ECN_DBG_END;
494 }
495#endif
496 }
497#endif
498 a_fbs_id.ptr->hdr.type = ECN_MSG_ECHONET;
499 a_fbs_id.ptr->hdr.sender = ENOD_API_ID;
500 if (fa_esv == ESV_INFC)
501 a_fbs_id.ptr->hdr.reply = a_fbs_id.ptr->hdr.target;
502 else if (fa_esv == ESV_INF_REQ)
503 a_fbs_id.ptr->hdr.reply = ENOD_MULTICAST_ID;
504 else
505 a_fbs_id.ptr->hdr.reply = ENOD_API_ID;
506
507 /* ³íI—¹ */
508 *fp_fbs_id = a_fbs_id;
509 return E_OK;
510
511lb_except:
512 /* ƒf[ƒ^ì¬Ž¸”s‚µ‚½‚ç—̈æ‰ð•ú */
513 if (a_fbs_id.ptr)
514 _ecn_fbs_del(a_fbs_id);
515
516 return a_ret;
517}
518
519/*
520 * “à•”Žg—pƒƒbƒZ[ƒW
521 */
522static void _ecn_tsk_int_msg(intptr_t fa_exinf, ECN_FBS_ID fa_fbs_id)
523{
524 T_ECN_INTERNAL_MSG a_im;
525 ECN_FBS_SSIZE_T a_len;
526 int a_ans;
527
528 a_im.command = 0;
529 a_len = 0;
530 a_ans = _ecn_fbs_get_data(fa_fbs_id, &a_im.command, sizeof(a_im.command), &a_len);
531 if (a_ans || !a_len) {
532 return; /* NG */
533 }
534
535 switch (a_im.command) {
536 case ECN_INM_NOTIFY_INSTANCELIST:
537 ECN_DBG_PUT "do _ecn_tsk_int_startup()" ECN_DBG_END;
538 _ecn_tsk_int_startup(fa_exinf);
539 break;
540 default:
541#ifdef ECHONET_CONTROLLER_EXTENTION
542 if(ecn_agent_proc_int_msg(fa_fbs_id, a_im.command))
543 break;
544#endif
545 ECN_DBG_PUT "recv: unefined internal-msg: %d", a_im.command ECN_DBG_END;
546 break;
547 }
548}
549
550/*
551 * ƒ^ƒXƒN‰Šú‰»
552 */
553static void _ecn_tsk_int_startup(intptr_t fa_exinf)
554{
555 ER a_ret;
556
557 if (m_eobjlist_need_init)
558 _ecn_tsk_int_module_init(fa_exinf);
559
560 /* ƒCƒ“ƒXƒ^ƒ“ƒXƒŠƒXƒg’Ê’m‚Ì‘—M */
561 a_ret = _ecn_tsk_ntf_inl(fa_exinf);
562 if (a_ret) {
563 syslog(LOG_WARNING, "_ecn_tsk_ntf_inl() result = %d:%s", a_ret, itron_strerror(a_ret));
564 }
565}
566
567/*
568 * ƒCƒ“ƒXƒ^ƒ“ƒXƒŠƒXƒg’Ê’m‚Ì‘—M
569 * ECHONET-Lite_Ver.1.10_02.pdf p.43 }4-1-4
570 */
571ER _ecn_tsk_ntf_inl(intptr_t fa_exinf)
572{
573 const T_ECN_EOJ a_seoj = /* 0x01 : ˆê”ʃm[ƒhA0x02F‘—Mê—pƒm[ƒh */
574 { EOJ_X1_PROFILE, EOJ_X2_NODE_PROFILE, 0x01 };
575 const T_ECN_EOJ a_deoj =
576 { EOJ_X1_PROFILE, EOJ_X2_NODE_PROFILE, 0x01 };
577 T_ECN_EDT_HDR a_hdr;
578 ER a_ret = E_OK;
579 ECN_FBS_ID a_fbs = { 0 };
580 int a_eoj_ct = 0;
581 int i;
582 uint8_t a_count;
583 const EOBJCB *enod = &eobjcb_table[0]; /* ƒ[ƒJƒ‹ƒm[ƒh */
584 const EOBJINIB *eobj;
585
586 ECN_DBG_PUT "do _ecn_tsk_ntf_inl()" ECN_DBG_END;
587
588 memset(&a_hdr, 0, sizeof(a_hdr));
589 a_hdr.ecn_hdr.ehd1 = ECN_EDH1_ECHONET_LITE;
590 a_hdr.ecn_hdr.ehd2 = ECN_EDH2_FORMAT_1;
591 a_hdr.edata.seoj = a_seoj;
592 a_hdr.edata.deoj = a_deoj;
593 a_hdr.edata.esv = ESV_INF;
594 a_hdr.edata.opc = 1;
595 a_hdr.ecn_prp.epc = ECN_EPC_INL_BCS;
596
597 for (i = 0; i < enod->eobjcnt; i++) {
598 eobj = enod->eobjs[i];
599
600 if (!a_eoj_ct) {
601 /* ƒƒ‚ƒŠŠm•ÛEƒwƒbƒ_Ši”[ */
602 a_hdr.ecn_hdr.tid = (uint8_t)_ecn_tsk_new_tid(); /* ƒV[ƒPƒ“ƒX”ԍ†¶¬ */
603 a_ret = _ecn_fbs_cre(sizeof(a_hdr), &a_fbs);
604 if (a_ret != E_OK) /* Šm•ÛŽ¸”s */
605 goto lb_except;
606 a_ret = _ecn_fbs_add_data(a_fbs, &a_hdr, sizeof(a_hdr));
607 if (a_ret != E_OK) /* ƒf[ƒ^’ljÁŽ¸”s */
608 goto lb_except;
609
610 a_fbs.ptr->hdr.type = ECN_MSG_ECHONET;
611 a_fbs.ptr->hdr.sender = ENOD_LOCAL_ID;
612 a_fbs.ptr->hdr.target = ENOD_MULTICAST_ID;
613 a_fbs.ptr->hdr.reply = ENOD_LOCAL_ID;
614 ((T_EDATA *)a_fbs.ptr)->hdr.ecn_prp.pdc = 1; /* Œ” */
615 /* Œ”‚ðŠi”[ */
616 a_count = (uint8_t)(enod->eobjcnt - i);
617 if (a_count >= ECN_IST_LST_EOJ_MAX_CT)
618 a_count = ECN_IST_LST_EOJ_MAX_CT;
619 a_ret = _ecn_fbs_add_data_ex(a_fbs, &a_count, sizeof(a_count));
620 if (a_ret != E_OK) /* ƒf[ƒ^’ljÁŽ¸”s */
621 goto lb_except;
622 }
623 /* ECHONETƒIƒuƒWƒFƒNƒgID(3byte)‚ðŠi”[ */
624 a_ret = _ecn_fbs_add_data_ex(a_fbs, &eobj->eojx1, sizeof(T_ECN_EOJ));
625 if (a_ret != E_OK) /* ƒf[ƒ^’ljÁŽ¸”s */
626 goto lb_except;
627
628 /* Œ”EedtƒTƒCƒY‰ÁŽZ */
629 ((T_EDATA *)a_fbs.ptr)->hdr.ecn_prp.pdc += sizeof(T_ECN_EOJ);
630 if (++a_eoj_ct < ECN_IST_LST_EOJ_MAX_CT)
631 continue;
632
633 /* 1ƒAƒiƒEƒ“ƒX‚ł̏ãŒÀ‚É’B‚µ‚½‚çAˆê’U‘—M */
634 a_ret = _ecn_tsk_snd_mbx(a_fbs, false);
635 if (a_ret != E_OK) /* ƒf[ƒ^‘—MŽ¸”s */
636 goto lb_except;
637 a_eoj_ct = 0;
638 a_fbs.ptr = 0;
639 }
640 if (a_eoj_ct) {
641 /* –¢‘—Mƒf[ƒ^‚ª‚ ‚Á‚½‚çA‘—M */
642 a_ret = _ecn_tsk_snd_mbx(a_fbs, false);
643 if (a_ret != E_OK) /* ƒf[ƒ^‘—MŽ¸”s */
644 goto lb_except;
645 a_fbs.ptr = 0;
646 }
647 goto lb_finally;
648
649lb_except:
650 if (a_fbs.ptr)
651 _ecn_fbs_del(a_fbs);
652
653lb_finally:
654 return a_ret;
655}
656
657const EOBJCB *_ecn_eno_fnd(ECN_ENOD_ID enodid)
658{
659 const EOBJCB *enod = NULL;
660 int i;
661
662 switch (enodid) {
663 case ENOD_MULTICAST_ID:
664 case ENOD_LOCAL_ID:
665 case ENOD_API_ID:
666 enod = &eobjcb_table[0];
667 break;
668 default:
669 i = enodid - ENOD_REMOTE_ID + 1;
670 if ((i >= 1) && (i < tnum_enodid))
671 enod = &eobjcb_table[i];
672#ifdef ECHONET_CONTROLLER_EXTENTION
673 else{
674 ecn_node_t *p_tmp = ecn_agent_find_node(enodid);
675 if (p_tmp == NULL)
676 return NULL;
677 return &p_tmp->eobj;
678 }
679#endif
680 break;
681 }
682
683 return enod;
684}
685
686/*
687 * 3byte‚Ìeobjid‚Å”z—ñ’†‚ðŒŸõ‚·‚é
688 */
689const EOBJINIB *_ecn_eoj_fnd(const EOBJCB *fp_nod, const T_ECN_EOJ *fp_eoj)
690{
691 const EOBJINIB *p_obj;
692 int i, count = fp_nod->eobjcnt;
693
694#ifdef ECHONET_CONTROLLER_EXTENTION
695 if (fp_nod->eobjs == NULL) {
696 ecn_obj_t *p_tmp = ecn_agent_find_eobj(fp_nod, *fp_eoj);
697 if(p_tmp == NULL)
698 return NULL;
699 return &p_tmp->inib;
700 }
701#endif
702
703 for (i = 0; i < count; i++) {
704 p_obj = fp_nod->eobjs[i];
705
706 if (p_obj->eojx1 != fp_eoj->eojx1)
707 continue;
708 if (p_obj->eojx2 != fp_eoj->eojx2)
709 continue;
710 if (p_obj->eojx3 != fp_eoj->eojx3)
711 continue;
712
713 return p_obj;
714 }
715
716 return 0;
717}
718
719static int _ecn_tsk_ecn_msg_main(ECN_FBS_ID fa_fbs_id, const EOBJINIB *p_obj, ATR eobjatr,
720 const EOBJINIB *p_sobj, ATR sobjatr);
721
722/*
723 * ECHONET—pƒƒbƒZ[ƒW
724 */
725static void _ecn_tsk_ecn_msg(intptr_t fa_exinf, ECN_FBS_ID fa_fbs_id)
726{
727 const EOBJCB *p_nod, *p_snod;
728 const EOBJINIB *p_obj, *p_sobj = NULL;
729 ATR eobjatr, sobjatr = EPC_NONE;
730 T_ECN_EDT_HDR *p_esv;
731 ER a_ret;
732 int i, count;
733 T_ECN_EOJ *p_eoj;
734 bool_t a_prc;
735 bool_t a_fwd;
736 ECN_ENOD_ID sender;
737
738#ifdef ECN_DBG_PUT_ENA
739 syslog(LOG_NOTICE, "mbx recv:");
740 _ecn_dbg_bindmp(fa_fbs_id.ptr->bin, sizeof(fa_fbs_id.ptr->bin));
741#endif
742
743 p_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
744
745 if (p_esv->ecn_hdr.ehd1 != ECN_EDH1_ECHONET_LITE
746 || p_esv->ecn_hdr.ehd2 != ECN_EDH2_FORMAT_1) {
747 syslog(LOG_WARNING, "_ecn_tsk_ecn_msg() format fault: 0x%02X,0x%02X", p_esv->ecn_hdr.ehd1, p_esv->ecn_hdr.ehd2);
748 return;
749 }
750
751 /* ‘—Mˆ¶‚©‚çƒm[ƒh‚ðŒŸõ */
752 p_nod = _ecn_eno_fnd(fa_fbs_id.ptr->hdr.target);
753 /* ‘—MŒ³‚©‚çƒm[ƒh‚ðŒŸõ */
754 sender = fa_fbs_id.ptr->hdr.sender;
755 p_snod = _ecn_eno_fnd(sender);
756 if (p_snod != NULL) {
757 sobjatr = p_snod->profile->eobjatr;
758 /* ƒm[ƒhƒvƒƒtƒ@ƒCƒ‹‚̏ꍇ */
759 if ((p_esv->edata.seoj.eojx1 == EOJ_X1_PROFILE)
760 && (p_esv->edata.seoj.eojx2 == EOJ_X2_NODE_PROFILE)) {
761 p_sobj = p_snod->profile;
762 }
763 /* ‹@ŠíƒIƒuƒWƒFƒNƒg‚̏ꍇ */
764 else {
765 p_sobj = _ecn_eoj_fnd(p_snod, &p_esv->edata.seoj);
766 }
767 }
768
769#ifdef ECHONET_CONTROLLER_EXTENTION
770 ecn_agent_proc_ecn_msg(&p_snod, &p_sobj, (T_EDATA *)fa_fbs_id.ptr);
771#endif
772
773 /* ƒm[ƒh“à‚Ì‹@ŠíƒIƒuƒWƒFƒNƒg‚ðŒŸõ */
774 a_prc = false;
775 a_fwd = false;
776 g_forward_esv = false;
777 if (p_nod != NULL) {
778 eobjatr = p_nod->profile->eobjatr;
779 p_eoj = &p_esv->edata.deoj;
780 /* ƒm[ƒhƒvƒƒtƒ@ƒCƒ‹‚̏ꍇ */
781 if ((p_eoj->eojx1 == EOJ_X1_PROFILE)
782 && (p_eoj->eojx2 == EOJ_X2_NODE_PROFILE)) {
783 /* “d•¶ˆ—ŽÀs */
784 if (_ecn_tsk_ecn_msg_main(fa_fbs_id, p_nod->profile, eobjatr, p_sobj, sobjatr) == 1)
785 a_fwd = true;
786 a_prc = true;
787 }
788 /* ‹@ŠíƒIƒuƒWƒFƒNƒg‚̏ꍇ */
789 else {
790 count = p_nod->eobjcnt;
791#ifdef ECHONET_CONTROLLER_EXTENTION
792 p_obj = NULL;
793#endif
794 for (i = 0; i < count; i++) {
795#ifdef ECHONET_CONTROLLER_EXTENTION
796 if(p_nod->eobjs == NULL)
797 p_obj = ecn_agent_next_eobj(p_nod, p_obj);
798 else
799 p_obj = p_nod->eobjs[i];
800#else
801 p_obj = p_nod->eobjs[i];
802#endif
803 if (p_obj->eojx1 != p_eoj->eojx1)
804 continue;
805 if (p_obj->eojx2 != p_eoj->eojx2)
806 continue;
807 /* ƒCƒ“ƒXƒ^ƒ“ƒXƒR[ƒh‚ª‚O‚̏ꍇA“¯‚¶ƒNƒ‰ƒX‚Ì‘S‚ẴCƒ“ƒXƒ^ƒ“ƒXˆ¶ */
808 if ((p_obj->eojx3 != p_eoj->eojx3) && (p_eoj->eojx3 != 0))
809 continue;
810
811 /* “d•¶ˆ—ŽÀs */
812 if (_ecn_tsk_ecn_msg_main(fa_fbs_id, p_obj, eobjatr, p_sobj, sobjatr) == 1)
813 a_fwd = true;
814 a_prc = true;
815 }
816 }
817 }
818 /* ‹@ŠíƒIƒuƒWƒFƒNƒg‚ªŒ©‚‚©‚ç‚È‚¢ê‡‚Å‚à */
819 if (!a_prc) {
820 /* “d•¶ˆ—ŽÀsi‰ž“šŽóM—pj */
821 if (_ecn_tsk_ecn_msg_main(fa_fbs_id, NULL, EPC_NONE, p_sobj, sobjatr) == 1)
822 a_fwd = true;
823 }
824
825 /* ‰ž“š‚̏ꍇƒAƒvƒŠƒP[ƒVƒ‡ƒ“‚É“]‘—‚·‚é */
826 if (a_fwd && ((p_esv->ecn_hdr.tid == apitid_table[sender])
827 || g_forward_esv))
828 {
829 g_release_esv = false;
830
831 ECN_CAP_PUT "redirect ecn_svc_mailboxid ¨ ecn_api_mailboxid (esv:0x%02X)",
832 p_esv->edata.esv ECN_CAP_END;
833 fa_fbs_id.ptr->hdr.target = ENOD_API_ID;
834 a_ret = psnd_dtq(ecn_api_mailboxid, (intptr_t)fa_fbs_id.ptr);
835 if (a_ret != E_OK) {
836 syslog(LOG_WARNING, "_ecn_tsk_ecn_msg() : psnd_dtq() result = %d:%s", a_ret, itron_strerror(a_ret));
837 _ecn_fbs_del(fa_fbs_id);
838 }
839 }
840#ifdef ECHONET_CONTROLLER_EXTENTION
841 ecn_agent_proc_ecn_msg_end();
842#endif
843}
844
845static int _ecn_tsk_ecn_msg_main(ECN_FBS_ID fa_fbs_id, const EOBJINIB *p_obj, ATR eobjatr,
846 const EOBJINIB *p_sobj, ATR sobjatr)
847{
848 int result;
849 T_ECN_EDT_HDR *p_esv;
850 ECN_FBS_ID a_fbs_anno = { NULL };
851
852 p_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
853
854 switch (p_esv->edata.esv) {
855 /* 0x60 ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹i‰ž“š•s—vj */
856 case ESV_SET_I:
857 if (!p_obj) {
858 ECN_DBG_PUT "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
859 p_esv->edata.deoj.eojx1 << 16 | p_esv->edata.deoj.eojx2 << 8 | p_esv->edata.deoj.eojx3 ECN_DBG_END;
860 result = -1;
861 break;
862 }
863 _ecn_tsk_eoj_set(p_obj, eobjatr, false, fa_fbs_id, ESV_NOP, ESV_SET_I_SNA, &a_fbs_anno); /* 0; 0x50 */
864 result = 0;
865 break;
866
867 /* 0x61 ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹i‰ž“š—vj */
868 case ESV_SET_C:
869 if (!p_obj) {
870 ECN_DBG_PUT "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
871 p_esv->edata.deoj.eojx1 << 16 | p_esv->edata.deoj.eojx2 << 8 | p_esv->edata.deoj.eojx3 ECN_DBG_END;
872 result = -1;
873 break;
874 }
875 _ecn_tsk_eoj_set(p_obj, eobjatr, false, fa_fbs_id, ESV_SET_RES, ESV_SET_C_SNA, &a_fbs_anno); /* 0x71; 0x51 */
876 result = 0;
877 break;
878
879 /* 0x62 ƒvƒƒpƒeƒB’l“ǂݏo‚µ—v‹ */
880 case ESV_GET:
881 if (!p_obj) {
882 ECN_DBG_PUT "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
883 p_esv->edata.deoj.eojx1 << 16 | p_esv->edata.deoj.eojx2 << 8 | p_esv->edata.deoj.eojx3 ECN_DBG_END;
884 result = -1;
885 break;
886 }
887 _ecn_tsk_eoj_get(p_obj, eobjatr, false, EPC_RULE_GET, fa_fbs_id, ESV_GET_RES, ESV_GET_SNA); /* 0x72; 0x52 */
888 result = 0;
889 break;
890
891 /* 0x63 ƒvƒƒpƒeƒB’l’Ê’m—v‹ */
892 case ESV_INF_REQ:
893 if (!p_obj) {
894 ECN_DBG_PUT "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
895 p_esv->edata.deoj.eojx1 << 16 | p_esv->edata.deoj.eojx2 << 8 | p_esv->edata.deoj.eojx3 ECN_DBG_END;
896 result = -1;
897 break;
898 }
899 fa_fbs_id.ptr->hdr.reply = ENOD_MULTICAST_ID;
900 _ecn_tsk_eoj_get(p_obj, eobjatr, false, (EPC_RULE_GET|EPC_RULE_ANNO), fa_fbs_id, ESV_INF, ESV_INF_SNA); /* 0x73; 0x53 */
901 result = 0;
902 break;
903
904 /* 0x6E ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ—v‹ */
905 case ESV_SET_GET:
906 if (!p_obj) {
907 ECN_DBG_PUT "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
908 p_esv->edata.deoj.eojx1 << 16 | p_esv->edata.deoj.eojx2 << 8 | p_esv->edata.deoj.eojx3 ECN_DBG_END;
909 result = -1;
910 break;
911 }
912 _ecn_tsk_eoj_set_get(p_obj, eobjatr, fa_fbs_id, ESV_SET_GET_RES, ESV_SET_GET_SNA, &a_fbs_anno); /* 0x7E; 0x5E */
913 result = 0;
914 break;
915
916 /* 0x74 ƒvƒƒpƒeƒB’l’Ê’mi‰ž“š—vj */
917 case ESV_INFC:
918 if (!p_sobj)
919 _ecn_tsk_eoj_res(fa_fbs_id, ESV_INFC_RES, ESV_INFC_RES); /* 0x74; 0 */
920 else if (sobjatr == EOBJ_LOCAL_NODE)
921 _ecn_tsk_eoj_get(p_sobj, sobjatr, true, (EPC_RULE_GET|EPC_RULE_ANNO), fa_fbs_id, ESV_INFC, ESV_NOP); /* 0x74; 0 */
922 else
923 _ecn_tsk_eoj_set(p_sobj, sobjatr, true, fa_fbs_id, ESV_INFC_RES, ESV_INFC_RES, &a_fbs_anno); /* 0x7A; 0 */
924 result = 0;
925 break;
926
927 /* 0x60 ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹i‰ž“š•s—vj */
928 case ESV_SET_I_SNA: /* 0x50 ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹•s‰Â‰ž“š */
929 result = 1;
930 break;
931
932 /* 0x61 ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹i‰ž“š—vj */
933 case ESV_SET_RES: /* 0x71 ƒvƒƒpƒeƒB’l‘‚«ž‚݉ž“š */
934 case ESV_SET_C_SNA: /* 0x51 ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹•s‰Â‰ž“š */
935 result = 1;
936 break;
937
938 /* 0x62 ƒvƒƒpƒeƒB’l“ǂݏo‚µ—v‹ */
939 case ESV_GET_RES: /* 0x72 ƒvƒƒpƒeƒB’l“ǂݏo‚µ‰ž“š */
940 case ESV_GET_SNA: /* 0x52 ƒvƒƒpƒeƒB’l“ǂݏo‚µ•s‰Â‰ž“š */
941 if (!p_sobj) {
942 ECN_DBG_PUT "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
943 p_esv->edata.seoj.eojx1 << 16 | p_esv->edata.seoj.eojx2 << 8 | p_esv->edata.seoj.eojx3 ECN_DBG_END;
944 result = -1;
945 break;
946 }
947 _ecn_tsk_eoj_set(p_sobj, sobjatr, true, fa_fbs_id, ESV_NOP, ESV_NOP, &a_fbs_anno); /* 0; 0 */
948 result = 1;
949 break;
950
951 /* 0x63 ƒvƒƒpƒeƒB’l’Ê’m—v‹ */
952 case ESV_INF: /* 0x73 ƒvƒƒpƒeƒB’l’Ê’m */
953 case ESV_INF_SNA: /* 0x53 ƒvƒƒpƒeƒB’l’Ê’m•s‰Â‰ž“š */
954 if (!p_sobj) {
955 ECN_DBG_PUT "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
956 p_esv->edata.seoj.eojx1 << 16 | p_esv->edata.seoj.eojx2 << 8 | p_esv->edata.seoj.eojx3 ECN_DBG_END;
957 result = -1;
958 break;
959 }
960 _ecn_tsk_eoj_set(p_sobj, sobjatr, true, fa_fbs_id, ESV_NOP, ESV_NOP, &a_fbs_anno); /* 0; 0 */
961 result = 1;
962 break;
963
964 /* 0x6E ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ—v‹ */
965 case ESV_SET_GET_RES: /* 0x7E ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ‰ž“š */
966 case ESV_SET_GET_SNA: /* 0x5E ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ•s‰Â‰ž“š */
967 if (!p_sobj) {
968 ECN_DBG_PUT "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
969 p_esv->edata.seoj.eojx1 << 16 | p_esv->edata.seoj.eojx2 << 8 | p_esv->edata.seoj.eojx3 ECN_DBG_END;
970 result = -1;
971 break;
972 }
973 _ecn_tsk_eoj_set_get_res(p_sobj, sobjatr, fa_fbs_id, &a_fbs_anno); /* 0x7A; 0 */
974 result = 1;
975 break;
976
977 /* 0x74 ƒvƒƒpƒeƒB’l’Ê’mi‰ž“š—vj */
978 case ESV_INFC_RES: /* 0x7A ƒvƒƒpƒeƒB’l’Ê’m‰ž“š */
979 result = 1;
980 break;
981
982 default:
983 syslog(LOG_WARNING, "_ecn_tsk_ecn_msg_main() esv 0x%02X undefined.", p_esv->edata.esv);
984 result = -1;
985 break;
986 }
987
988 /* ƒvƒƒpƒeƒB’Ê’m—v‹‚𑗐M */
989 if (a_fbs_anno.ptr != NULL) {
990 ER a_ret = _ecn_tsk_snd_mbx(a_fbs_anno, true);
991 if (a_ret != E_OK)
992 _ecn_fbs_del(a_fbs_anno);
993 }
994
995 return result;
996}
997
998#ifdef ECN_DBG_PUT_ENA
999static void f_put_fbs_eoj(const char *fp_fncnm, const char *fp_varnm,
1000 ECN_FBS_ID fa_fbs_id);
1001static void f_put_fbs_eoj(const char *fp_fncnm, const char *fp_varnm,
1002 ECN_FBS_ID fa_fbs_id)
1003{
1004 ECN_DBG_PUT "%s() %s eoj src:%06X dest:%06X",
1005 fp_fncnm, fp_varnm,
1006 ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.seoj.eojx1 << 16 | ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.seoj.eojx2 << 8 | ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.seoj.eojx3,
1007 ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.deoj.eojx1 << 16 | ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.deoj.eojx2 << 8 | ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.deoj.eojx3 ECN_DBG_END;
1008}
1009#else
1010#define f_put_fbs_eoj(f,v,r)
1011#endif /* #ifdef ECN_DBG_PUT_ENA */
1012
1013static const EPRPINIB *_ecn_tsk_eoj_get_property(const EOBJINIB *fp_obj, uint8_t fa_epc);
1014static const EPRPINIB *_ecn_tsk_eoj_get_property(const EOBJINIB *fp_obj, uint8_t fa_epc)
1015{
1016 const EPRPINIB *p = fp_obj->eprp;
1017 uint_t i;
1018#ifdef ECHONET_CONTROLLER_EXTENTION
1019 if (fp_obj->eprpcnt == 0) {
1020 return ecn_agent_get_property(fp_obj, fa_epc, p);
1021 }
1022#endif
1023 for (i = 0; i < fp_obj->eprpcnt; i++, p++) {
1024 if (p->eprpcd != fa_epc)
1025 continue;
1026
1027 return p;
1028 }
1029 ECN_DBG_PUT "_ecn_tsk_eoj_get_property(0x%02X-0x%02X-0x%02X, epc:0x%02X) not found.",
1030 fp_obj->eojx1, fp_obj->eojx2, fp_obj->eojx3,
1031 fa_epc ECN_DBG_END;
1032
1033 return NULL;
1034}
1035
1036static int _ecn_tsk_eoj_set_edt(const EPRPINIB *fp_prp, void *fp_src, int fa_srcsz,
1037 bool_t *fa_anno);
1038static int _ecn_tsk_eoj_set_edt(const EPRPINIB *fp_prp, void *fp_src, int fa_srcsz,
1039 bool_t *fa_anno)
1040{
1041 if (!fp_prp->eprpset)
1042 return -1;
1043
1044 ECN_DBG_PUT "_ecn_tsk_eoj_set_edt(epc:0x%02X) call eprpset()",
1045 fp_prp->eprpcd ECN_DBG_END;
1046
1047 return fp_prp->eprpset(fp_prp, fp_src, fa_srcsz, fa_anno);
1048}
1049
1050static int _ecn_tsk_eoj_get_edt(const EPRPINIB *fp_prp, void *fp_dst, int fa_dstsz);
1051static int _ecn_tsk_eoj_get_edt(const EPRPINIB *fp_prp, void *fp_dst, int fa_dstsz)
1052{
1053 if (fa_dstsz < fp_prp->eprpsz)
1054 return -1;
1055 if (!fp_prp->eprpget)
1056 return -1;
1057
1058 ECN_DBG_PUT "_ecn_tsk_eoj_get_edt(epc:0x%02X) call eprpget()",
1059 fp_prp->eprpcd ECN_DBG_END;
1060
1061 return fp_prp->eprpget(fp_prp, fp_dst, fp_prp->eprpsz);
1062}
1063
1064static T_ECN_SUB_BLK *_ecn_tsk_get_prp_pce(ECN_FBS_ID fa_fbs_id, T_ECN_PRP *fp_prp,
1065 T_ECN_SUB_BLK *const fp_prev_blk);
1066
1067/*
1068 * ECN_FBS_ID‚©‚çT_ECN_PRP1Œ‚Æ‚»‚Ì•tƒf[ƒ^(edt)‚𒊏o‚µAedt‚̃|ƒCƒ“ƒ^‚ð•Ô‚·
1069 * ˆø”
1070 * ECN_FBS_ID fa_fbs_id “Ç‚ÝŽæ‚éFBS
1071 * T_ECN_PRP *fp_prp epc+pdc‚ÌŠi”[æ
1072 * T_ECN_SUB_BLK * const fp_prev_blk ‘O‰ñŽg‚Á‚½ƒƒ‚ƒŠ‚̃|ƒCƒ“ƒ^(–³‚¯‚ê‚Î0)
1073 * ³íFƒ|ƒCƒ“ƒ^ NG:0
1074 * ƒ|ƒCƒ“ƒ^‚Í_ecn_fbs_mbx_rel()‚ʼnð•ú‚·‚é•K—v‚ª‚ ‚é
1075 */
1076static T_ECN_SUB_BLK *_ecn_tsk_get_prp_pce(ECN_FBS_ID fa_fbs_id, T_ECN_PRP *fp_prp,
1077 T_ECN_SUB_BLK *const fp_prev_blk)
1078{
1079 T_ECN_SUB_BLK *p_blk = 0;
1080 int a_size;
1081 ER a_ret;
1082
1083 /* ƒvƒƒpƒeƒB—pƒƒ‚ƒŠ‚̎擾 */
1084 if (fp_prev_blk) {
1085 p_blk = fp_prev_blk; /* ‘O‰ñŽg‚Á‚½ƒƒ‚ƒŠ‚ª‚ ‚é‚È‚çAÄ—˜—p‚·‚é */
1086 }
1087 else {
1088 p_blk = (T_ECN_SUB_BLK *)_ecn_fbs_mbx_get(sizeof(*p_blk));
1089 if (!p_blk) {
1090 ECN_DBG_PUT "_ecn_fbs_mbx_get() fault." ECN_DBG_END;
1091 return 0; /* ƒƒ‚ƒŠ•s‘« */
1092 }
1093 }
1094 memset(p_blk, 0, sizeof(*p_blk));
1095
1096 /* T_ECN_PRP•”•ª(epc,pdc)‚ð“Ç‚ÝŽæ‚é */
1097 a_size = 0;
1098 a_ret = _ecn_fbs_get_data(fa_fbs_id, fp_prp, sizeof(*fp_prp), &a_size);
1099 if (a_ret || a_size < (int)sizeof(*fp_prp)) {
1100 ECN_DBG_PUT "_ecn_fbs_get_data() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1101 goto lb_except;
1102 }
1103
1104 if (0 < fp_prp->pdc) {
1105 /* •tƒf[ƒ^•”•ª(edt)‚ð“Ç‚ÝŽæ‚é */
1106 a_size = 0;
1107 a_ret = _ecn_fbs_get_data(fa_fbs_id, p_blk, fp_prp->pdc, &a_size);
1108 if (a_ret || a_size < (int)fp_prp->pdc) {
1109 ECN_DBG_PUT "_ecn_fbs_get_data() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1110 goto lb_except;
1111 }
1112 }
1113
1114 return p_blk;
1115
1116lb_except:
1117 /* ƒvƒƒpƒeƒB—pƒƒ‚ƒŠ‰ð•ú */
1118 if (p_blk && !fp_prev_blk)
1119 _ecn_fbs_mbx_rel(p_blk);
1120
1121 return 0; /* 0:NG */
1122}
1123
1124static ER _ecn_tsk_eoj_set_main(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_update,
1125 ECN_FBS_ID fa_fbs_id, ECN_FBS_ID a_fbs_res, ECN_FBS_ID *fa_fbs_anno, int a_count,
1126 int *p_sw_ok);
1127/* ƒvƒƒpƒeƒB’l‘‚«ž‚ÝŽÀs */
1128static ER _ecn_tsk_eoj_set_main(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_update,
1129 ECN_FBS_ID fa_fbs_id, ECN_FBS_ID a_fbs_res, ECN_FBS_ID *fa_fbs_anno, int a_count,
1130 int *p_sw_ok)
1131{
1132 T_ECN_SUB_BLK *p_edt = 0;
1133 T_ECN_PRP a_prp; /* epc+pdc */
1134 const EPRPINIB *a_eprp;
1135 int i, a_ans;
1136 ER a_ret;
1137 uint8_t a_size;
1138 bool_t a_anno = false, a_update;
1139
1140 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc = 0;
1141
1142 for (i = 0; i < a_count; i++) {
1143 /* ECN_FBS_ID‚©‚çT_ECN_PRP1Œ‚Æ‚»‚Ì•tƒf[ƒ^‚𒊏o‚µA‚»‚̃|ƒCƒ“ƒ^‚ð•Ô‚· */
1144 p_edt = _ecn_tsk_get_prp_pce(fa_fbs_id, &a_prp, p_edt);
1145 if (!p_edt) {
1146 ECN_DBG_PUT "_ecn_tsk_eoj_set_main(): _ecn_tsk_get_prp_pce() fault." ECN_DBG_END;
1147 goto lb_except;
1148 }
1149
1150 /* ƒvƒƒpƒeƒB‚̐ݒè set_prp(obj, reqp, resp) */
1151 a_size = a_prp.pdc;
1152 /* obj,epc‚ɑΉž‚·‚ésetŠÖ”‚ðŒÄ‚Ô */
1153 a_eprp = _ecn_tsk_eoj_get_property(fp_obj, a_prp.epc);
1154 if ((a_eprp != NULL)
1155 && (fa_update || (((a_eprp->eprpatr & EPC_RULE_SET) != 0) || (fa_eobjatr == EOBJ_LOCAL_NODE)))) {
1156 a_anno = (fa_eobjatr == EOBJ_LOCAL_NODE) && ((a_eprp->eprpatr & EPC_ANNOUNCE) != 0);
1157 a_update = a_anno;
1158 a_ans = _ecn_tsk_eoj_set_edt(a_eprp, p_edt->payload, a_size, &a_update);
1159 if (a_anno && (a_ans > 0))
1160 a_anno = a_update;
1161 }
1162 else {
1163 a_ans = -1;
1164 }
1165 if (a_ans == a_size) {
1166 ECN_DBG_PUT "_ecn_tsk_eoj_set_edt(0x%06X, 0x%02x, 0x%02X..., %u) ok.",
1167 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1168 a_prp.epc, p_edt->payload[0], a_size ECN_DBG_END;
1169 a_prp.pdc = 0;
1170 } else {
1171 ECN_DBG_PUT "_ecn_tsk_eoj_set_edt(0x%06X, 0x%02x, 0x%02X..., %u) fault.",
1172 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1173 a_prp.epc, p_edt->payload[0], a_size ECN_DBG_END;
1174 *p_sw_ok = 0; /* ƒvƒƒpƒeƒBÝ’莸”s */
1175 /* ‰ž“šˆ—‚̏ꍇEDT‚͐ݒ肵‚È‚¢ */
1176 if (fa_update)
1177 a_prp.pdc = 0;
1178 }
1179
1180 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ(epc,pdc‚Ì2byte) */
1181 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_prp, sizeof(a_prp));
1182 if (a_ret) {
1183 ECN_DBG_PUT "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1184 goto lb_except;
1185 }
1186
1187 if (0 < a_prp.pdc) {
1188 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ(edt n-byte) */
1189 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, p_edt->payload, a_prp.pdc);
1190 if (a_ret) {
1191 ECN_DBG_PUT "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1192 goto lb_except;
1193 }
1194 }
1195 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc ++;
1196
1197 /* ƒvƒƒpƒeƒB’Ê’m‚ ‚è‚̏ꍇ */
1198 if (a_anno && (a_ans == a_size)) {
1199 if (fa_fbs_anno->ptr == NULL) {
1200 _ecn_tsk_mk_esv(fa_fbs_anno, (ID)1, (((intptr_t)fp_obj - (intptr_t)eobjinib_table) / sizeof(EPRPINIB)) + 1,
1201 a_prp.epc, 0, NULL, ESV_INF_REQ);
1202 }
1203 else{
1204 ecn_add_edt((T_EDATA *)fa_fbs_anno->ptr, a_prp.epc, 0, 0);
1205 }
1206 }
1207 }
1208 a_ret = E_OK; /* ok */
1209 goto lb_finally;
1210
1211lb_except:
1212 a_ret = E_SYS;
1213
1214lb_finally:
1215 /* ƒvƒƒpƒeƒB—pƒƒ‚ƒŠ‰ð•ú */
1216 if (p_edt)
1217 _ecn_fbs_mbx_rel(p_edt);
1218
1219 return a_ret;
1220}
1221
1222static ER _ecn_tsk_eoj_get_main(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_forward, ATR fa_access,
1223 ECN_FBS_ID fa_fbs_id, ECN_FBS_ID a_fbs_res, int a_count, int *p_sw_ok);
1224/* ƒvƒƒpƒeƒB’l“ǂݏo‚µŽÀs */
1225static ER _ecn_tsk_eoj_get_main(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_forward, ATR fa_access,
1226 ECN_FBS_ID fa_fbs_id, ECN_FBS_ID a_fbs_res, int a_count, int *p_sw_ok)
1227{
1228 T_ECN_SUB_BLK *p_edt = 0;
1229 void *p_prp_buf = 0; /* ì‹Æ—̈æ */
1230 const EPRPINIB *a_eprp;
1231 ER a_ret = E_SYS;
1232 T_ECN_PRP a_prp; /* epc+pdc */
1233 int i, a_ans;
1234
1235 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc = 0;
1236
1237 /* ì‹Æ—̈æŠm•Û */
1238 p_prp_buf = _ecn_fbs_mbx_get(ECHONET_MEMPOOL_BLOCK_SIZE);
1239 if (!p_prp_buf) {
1240 ECN_DBG_PUT "_ecn_fbs_mbx_get() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1241 goto lb_except; /* ƒƒ‚ƒŠ•s‘« */
1242 }
1243
1244 for (i = 0; i < a_count; i++) {
1245 /* ECN_FBS_ID‚©‚çT_ECN_PRP1Œ‚Æ‚»‚Ì•tƒf[ƒ^‚𒊏o */
1246 p_edt = _ecn_tsk_get_prp_pce(fa_fbs_id, &a_prp, p_edt);
1247 if (!p_edt) {
1248 ECN_DBG_PUT "_ecn_tsk_eoj_get_main(): _ecn_tsk_get_prp_pce() fault." ECN_DBG_END;
1249 goto lb_except;
1250 }
1251
1252 /* ƒvƒƒpƒeƒB‚̎擾 get_eprp(obj, reqp, resp, size) */
1253 memset(p_prp_buf, 0, ECHONET_MEMPOOL_BLOCK_SIZE);
1254 /* obj,epc‚ɑΉž‚·‚égetŠÖ”‚ðŒÄ‚Ô */
1255 a_eprp = _ecn_tsk_eoj_get_property(fp_obj, a_prp.epc);
1256 if ((a_eprp != NULL) && (((a_eprp->eprpatr & fa_access) != 0) && (fa_eobjatr == EOBJ_LOCAL_NODE) || fa_forward)) {
1257 a_ans = _ecn_tsk_eoj_get_edt(a_eprp, p_prp_buf, ECHONET_MEMPOOL_BLOCK_SIZE - 1);
1258 }
1259 else {
1260 a_ans = -1;
1261 }
1262 if (0 < a_ans && a_ans <= (int)UINT8_MAX) {
1263 a_prp.pdc = (uint8_t)a_ans;
1264 } else {
1265 *p_sw_ok = 0; /* ƒvƒƒpƒeƒBŽæ“¾Ž¸”s */
1266 a_ans = 0;
1267 a_prp.pdc = 0;
1268 }
1269
1270 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ(epc,pdc‚Ì2byte) */
1271 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_prp, sizeof(a_prp));
1272 if (a_ret) {
1273 ECN_DBG_PUT "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1274 goto lb_except;
1275 }
1276 if (0 < a_ans) {
1277 /* •tƒf[ƒ^’ljÁ */
1278 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, p_prp_buf, a_ans);
1279 if (a_ret) {
1280 ECN_DBG_PUT "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1281 goto lb_except;
1282 }
1283 }
1284 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc ++;
1285 }
1286 a_ret = E_OK; /* ok */
1287 goto lb_finally;
1288
1289lb_except:
1290 a_ret = E_SYS;
1291
1292lb_finally:
1293 /* ì‹Æ—̈æ‰ð•ú */
1294 if (p_prp_buf)
1295 _ecn_fbs_mbx_rel(p_prp_buf);
1296
1297 /* ƒvƒƒpƒeƒB—pƒƒ‚ƒŠ‰ð•ú */
1298 if (p_edt)
1299 _ecn_fbs_mbx_rel(p_edt);
1300
1301 return a_ret;
1302}
1303
1304static ER _ecn_tsk_eoj_res_main(ECN_FBS_ID fa_fbs_id, ECN_FBS_ID a_fbs_res, int a_count, int *p_sw_ok);
1305/* ƒvƒƒpƒeƒB’l“ǂݏo‚µŽÀs */
1306static ER _ecn_tsk_eoj_res_main(ECN_FBS_ID fa_fbs_id, ECN_FBS_ID a_fbs_res, int a_count, int *p_sw_ok)
1307{
1308 T_ECN_SUB_BLK *p_edt = 0;
1309 void *p_prp_buf = 0; /* ì‹Æ—̈æ */
1310 ER a_ret = E_SYS;
1311 T_ECN_PRP a_prp; /* epc+pdc */
1312 int i;
1313
1314 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc = 0;
1315
1316 /* ì‹Æ—̈æŠm•Û */
1317 p_prp_buf = _ecn_fbs_mbx_get(ECHONET_MEMPOOL_BLOCK_SIZE);
1318 if (!p_prp_buf) {
1319 ECN_DBG_PUT "_ecn_fbs_mbx_get() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1320 goto lb_except; /* ƒƒ‚ƒŠ•s‘« */
1321 }
1322
1323 for (i = 0; i < a_count; i++) {
1324 /* ECN_FBS_ID‚©‚çT_ECN_PRP1Œ‚Æ‚»‚Ì•tƒf[ƒ^‚𒊏o */
1325 p_edt = _ecn_tsk_get_prp_pce(fa_fbs_id, &a_prp, p_edt);
1326 if (!p_edt) {
1327 ECN_DBG_PUT "_ecn_tsk_eoj_get_main(): _ecn_tsk_get_prp_pce() fault." ECN_DBG_END;
1328 goto lb_except;
1329 }
1330
1331 a_prp.pdc = 0;
1332
1333 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ(epc,pdc‚Ì2byte) */
1334 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_prp, sizeof(a_prp));
1335 if (a_ret) {
1336 ECN_DBG_PUT "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1337 goto lb_except;
1338 }
1339 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc++;
1340 }
1341 a_ret = E_OK; /* ok */
1342 goto lb_finally;
1343
1344lb_except:
1345 a_ret = E_SYS;
1346
1347lb_finally:
1348 /* ì‹Æ—̈æ‰ð•ú */
1349 if (p_prp_buf)
1350 _ecn_fbs_mbx_rel(p_prp_buf);
1351
1352 /* ƒvƒƒpƒeƒB—pƒƒ‚ƒŠ‰ð•ú */
1353 if (p_edt)
1354 _ecn_fbs_mbx_rel(p_edt);
1355
1356 return a_ret;
1357}
1358
1359/* ƒvƒƒpƒeƒB’l“Ç‚Ý”ò‚΂µŽÀs */
1360static ER _ecn_tsk_eoj_skip_main(const EOBJINIB *fp_obj, ECN_FBS_ID fa_fbs_id,
1361 int a_count);
1362static ER _ecn_tsk_eoj_skip_main(const EOBJINIB *fp_obj, ECN_FBS_ID fa_fbs_id,
1363 int a_count)
1364{
1365 T_ECN_PRP a_prp; /* epc+pdc */
1366 int i, a_size;
1367 ER a_ret;
1368
1369 for (i = 0; i < a_count; i++) {
1370 /* T_ECN_PRP•”•ª(epc,pdc)‚ð“Ç‚ÝŽæ‚é */
1371 a_size = 0;
1372 a_ret = _ecn_fbs_get_data(fa_fbs_id, &a_prp, sizeof(a_prp), &a_size);
1373 if (a_ret || a_size < (int)sizeof(a_prp)) {
1374 ECN_DBG_PUT "_ecn_fbs_get_data() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1375 goto lb_except;
1376 }
1377
1378 /* pdc•ª“Ç‚Ý”ò‚΂µ */
1379 a_ret = _ecn_fbs_seek_rpos(fa_fbs_id, a_prp.pdc);
1380 if (a_ret) {
1381 ECN_DBG_PUT "_ecn_fbs_seek_rpos() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1382 goto lb_except;
1383 }
1384 }
1385 a_ret = E_OK; /* ok */
1386 goto lb_finally;
1387
1388lb_except:
1389 a_ret = E_SYS;
1390
1391lb_finally:
1392 return a_ret;
1393}
1394
1395static void _ecn_tsk_mk_rsp_hdr(const EOBJINIB *fp_obj, T_ECN_EDT_HDR *fp_rsp_esv,
1396 T_ECN_EDT_HDR const *fp_req_esv);
1397/* ‰ž“š“d•¶Ý’è */
1398static void _ecn_tsk_mk_rsp_hdr(const EOBJINIB *fp_obj, T_ECN_EDT_HDR *fp_rsp_esv,
1399 T_ECN_EDT_HDR const *fp_req_esv)
1400{
1401 fp_rsp_esv->ecn_hdr.ehd1 = ECN_EDH1_ECHONET_LITE;
1402 fp_rsp_esv->ecn_hdr.ehd2 = ECN_EDH2_FORMAT_1;
1403 fp_rsp_esv->ecn_hdr.tid = fp_req_esv->ecn_hdr.tid;
1404 fp_rsp_esv->edata.seoj.eojx1 = fp_obj->eojx1;
1405 fp_rsp_esv->edata.seoj.eojx2 = fp_obj->eojx2;
1406 fp_rsp_esv->edata.seoj.eojx3 = fp_obj->eojx3;
1407 fp_rsp_esv->edata.deoj = fp_req_esv->edata.seoj;
1408}
1409
1410static void _ecn_tsk_mk_rsp_hdr_res(T_ECN_EDT_HDR *fp_rsp_esv,
1411 T_ECN_EDT_HDR const *fp_req_esv);
1412static void _ecn_tsk_mk_rsp_hdr_res(T_ECN_EDT_HDR *fp_rsp_esv,
1413 T_ECN_EDT_HDR const *fp_req_esv)
1414{
1415 fp_rsp_esv->ecn_hdr.ehd1 = ECN_EDH1_ECHONET_LITE;
1416 fp_rsp_esv->ecn_hdr.ehd2 = ECN_EDH2_FORMAT_1;
1417 fp_rsp_esv->ecn_hdr.tid = fp_req_esv->ecn_hdr.tid;
1418 fp_rsp_esv->edata.seoj = fp_req_esv->edata.deoj;
1419 fp_rsp_esv->edata.deoj = fp_req_esv->edata.seoj;
1420}
1421
1422/* ‰ž“š“d•¶—pfbsÝ’è */
1423static void _ecn_tsk_set_rsp_fbs(ECN_FBS_ID fa_rsp_fbs, T_ECN_FST_BLK const *fp_req_ptr);
1424/* ‰ž“š“d•¶—pfbsÝ’è(sender/target‚̐ݒè) */
1425static void _ecn_tsk_set_rsp_fbs(ECN_FBS_ID fa_rsp_fbs, T_ECN_FST_BLK const *fp_req_ptr)
1426{
1427 fa_rsp_fbs.ptr->hdr.type = ECN_MSG_ECHONET;
1428 fa_rsp_fbs.ptr->hdr.sender = ENOD_LOCAL_ID;
1429 fa_rsp_fbs.ptr->hdr.target = fp_req_ptr->hdr.reply;
1430 fa_rsp_fbs.ptr->hdr.reply = ENOD_LOCAL_ID;
1431}
1432
1433/* ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹ */
1434static void _ecn_tsk_eoj_set(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_update,
1435 ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv, ECN_SRV_CODE fa_sna_esv,
1436 ECN_FBS_ID *fa_fbs_anno)
1437{
1438 T_ECN_EDT_HDR const *p_req_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
1439 T_ECN_EDT_HDR a_ecn_hdp;
1440 ECN_FBS_ID a_fbs_res = { 0 };
1441 ER a_ret;
1442 int a_size;
1443 int a_sw_ok = 1;
1444 T_ECN_EOJ eoj;
1445
1446 memset(&a_ecn_hdp, 0, sizeof(a_ecn_hdp));
1447
1448 /* ‰ž“šÅ‘åƒTƒCƒY‚̎擾 */
1449 a_size = sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY) + sizeof(T_ECN_PRP);
1450
1451 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚̎擾 */
1452 a_ret = _ecn_fbs_cre(a_size, &a_fbs_res);
1453 if (a_ret != E_OK || !a_fbs_res.ptr) /* Šm•ÛŽ¸”s */
1454 return;
1455
1456 /* ‰ž“š“d•¶Ý’è */
1457 if(p_req_esv->edata.deoj.eojx3 != 0)
1458 _ecn_tsk_mk_rsp_hdr_res(&a_ecn_hdp, p_req_esv);
1459 else
1460 _ecn_tsk_mk_rsp_hdr(fp_obj, &a_ecn_hdp, p_req_esv);
1461
1462 /* ³íŽž‚̉ž“š“d•¶‚ªƒvƒƒpƒeƒB’l’Ê’m‰ž“š‚̏ꍇ */
1463 if (fa_res_esv == ESV_INFC_RES) {
1464 /* ‘—MŒ³‚ƈ¶æ‚ð“ü‚ê‘Ö‚¦ */
1465 eoj = a_ecn_hdp.edata.seoj;
1466 a_ecn_hdp.edata.seoj = a_ecn_hdp.edata.deoj;
1467 a_ecn_hdp.edata.deoj = eoj;
1468 }
1469
1470 f_put_fbs_eoj("_ecn_tsk_eoj_set", "fa_fbs_id", fa_fbs_id); /* s/deoj ƒfƒoƒbƒOo—Í */
1471
1472 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ */
1473 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_ecn_hdp,
1474 sizeof(a_ecn_hdp.ecn_hdr) + sizeof(a_ecn_hdp.edata));
1475 if (a_ret)
1476 goto lb_except;
1477
1478 /* payloadæ“ª‚ÌT_ECN_HDR(ecn_hdr), T_ECN_EDATA_BODY(edata)‚ð“Ç‚Ý”ò‚΂· */
1479 a_ret = _ecn_fbs_set_rpos(fa_fbs_id, offsetof(T_ECN_EDT_HDR, ecn_prp));
1480 if (a_ret)
1481 goto lb_except;
1482
1483 /* ‰ž“š“d•¶—pfbsÝ’è */
1484 _ecn_tsk_set_rsp_fbs(a_fbs_res, fa_fbs_id.ptr);
1485
1486 /* ƒvƒƒpƒeƒB’l‘‚«ž‚ÝŽÀs */
1487 a_ret = _ecn_tsk_eoj_set_main(fp_obj, fa_eobjatr, fa_update, fa_fbs_id, a_fbs_res,
1488 fa_fbs_anno, p_req_esv->edata.opc, &a_sw_ok);
1489 if (a_ret)
1490 goto lb_except;
1491
1492 /* ‰ž“š—v‚̏ꍇ */
1493 if (a_sw_ok) {
1494 if (!fa_res_esv) {
1495 /* ‰ž“š•s—v‚̏ꍇ */
1496 _ecn_fbs_del(a_fbs_res);
1497 goto lb_finally;
1498 }
1499 /* Ý’菈—¬Œ÷ */
1500 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_res_esv;
1501 } else {
1502 if (!fa_sna_esv) {
1503 /* ‰ž“š•s—v‚̏ꍇ */
1504 _ecn_fbs_del(a_fbs_res);
1505 goto lb_finally;
1506 }
1507 /* Ý’菈—Ž¸”s */
1508 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_sna_esv;
1509 }
1510 /* ‰ž“š‘—M */
1511 a_ret = _ecn_tsk_snd_mbx(a_fbs_res, false);
1512 if (a_ret == E_OK)
1513 goto lb_finally;
1514
1515lb_except:
1516 /* ƒf[ƒ^‘—MŽ¸”s‚µ‚½‚ç—̈æ‰ð•ú */
1517 if (a_fbs_res.ptr)
1518 _ecn_fbs_del(a_fbs_res);
1519
1520lb_finally:
1521 return;
1522}
1523
1524/* ƒvƒƒpƒeƒB’l“ǂݏo‚µ—v‹ */
1525static void _ecn_tsk_eoj_get(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_forward, ATR fa_access,
1526 ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv, ECN_SRV_CODE fa_sna_esv)
1527{
1528 T_ECN_EDT_HDR const *p_req_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
1529 T_ECN_EDT_HDR a_ecn_hdp;
1530 ECN_FBS_ID a_fbs_res = { 0 };
1531 ER a_ret;
1532 int a_size;
1533 int a_sw_ok = 1;
1534
1535 memset(&a_ecn_hdp, 0, sizeof(a_ecn_hdp));
1536
1537 /* ‰ŠúŽæ“¾ƒTƒCƒY */
1538 a_size = sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY) + sizeof(T_ECN_PRP);
1539
1540 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚̎擾 */
1541 a_ret = _ecn_fbs_cre(a_size, &a_fbs_res);
1542 if (a_ret != E_OK || !a_fbs_res.ptr) { /* Šm•ÛŽ¸”s */
1543 ECN_DBG_PUT "_ecn_fbs_cre() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1544 goto lb_finally;
1545 }
1546
1547 /* ‰ž“š“d•¶Ý’è */
1548 if(p_req_esv->edata.deoj.eojx3 != 0)
1549 _ecn_tsk_mk_rsp_hdr_res(&a_ecn_hdp, p_req_esv);
1550 else
1551 _ecn_tsk_mk_rsp_hdr(fp_obj, &a_ecn_hdp, p_req_esv);
1552
1553 f_put_fbs_eoj("_ecn_tsk_eoj_get", "fa_fbs_id", fa_fbs_id); /* s/deoj ƒfƒoƒbƒOo—Í */
1554
1555 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ */
1556 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_ecn_hdp,
1557 sizeof(a_ecn_hdp.ecn_hdr) + sizeof(a_ecn_hdp.edata));
1558 if (a_ret) {
1559 ECN_DBG_PUT "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1560 goto lb_except;
1561 }
1562
1563 /* payloadæ“ª‚ÌT_ECN_HDR(ecn_hdr), T_ECN_EDATA_BODY(edata)‚ð“Ç‚Ý”ò‚΂· */
1564 a_ret = _ecn_fbs_set_rpos(fa_fbs_id, offsetof(T_ECN_EDT_HDR, ecn_prp));
1565 if (a_ret) {
1566 ECN_DBG_PUT "_ecn_fbs_set_rpos() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1567 goto lb_except;
1568 }
1569
1570 /* ‰ž“š“d•¶—pfbsÝ’è */
1571 _ecn_tsk_set_rsp_fbs(a_fbs_res, fa_fbs_id.ptr);
1572
1573 /* ƒvƒƒpƒeƒB’l“ǂݍž‚ÝŽÀs */
1574 a_ret = _ecn_tsk_eoj_get_main(fp_obj, fa_eobjatr, fa_forward, fa_access, fa_fbs_id, a_fbs_res,
1575 ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.opc, &a_sw_ok);
1576 if (a_ret) {
1577 ECN_DBG_PUT "_ecn_tsk_eoj_get_main() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1578 goto lb_except;
1579 }
1580
1581 if (a_sw_ok) {
1582 if (!fa_res_esv) {
1583 /* ‰ž“š•s—v‚̏ꍇ */
1584 _ecn_fbs_del(a_fbs_res);
1585 goto lb_finally;
1586 }
1587 /* Ý’菈—¬Œ÷ */
1588 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_res_esv;
1589 } else {
1590 if (!fa_sna_esv) {
1591 /* ‰ž“š•s—v‚̏ꍇ */
1592 _ecn_fbs_del(a_fbs_res);
1593 goto lb_finally;
1594 }
1595 /* Ý’菈—Ž¸”s */
1596 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_sna_esv;
1597 }
1598 /* ‰ž“š‘—M */
1599 a_ret = _ecn_tsk_snd_mbx(a_fbs_res, false);
1600 if (a_ret != E_OK) {
1601 ECN_DBG_PUT "_ecn_tsk_snd_mbx() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1602 goto lb_except;
1603 }
1604 goto lb_finally;
1605
1606lb_except:
1607 /* ƒf[ƒ^‘—MŽ¸”s‚µ‚½‚ç—̈æ‰ð•ú */
1608 if (a_fbs_res.ptr)
1609 _ecn_fbs_del(a_fbs_res);
1610
1611lb_finally:
1612 return;
1613}
1614
1615/* ƒvƒƒpƒeƒB’l“ǂݏo‚µ—v‹ */
1616static void _ecn_tsk_eoj_res(ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv,
1617 ECN_SRV_CODE fa_sna_esv)
1618{
1619 T_ECN_EDT_HDR const *p_req_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
1620 T_ECN_EDT_HDR a_ecn_hdp;
1621 ECN_FBS_ID a_fbs_res = { 0 };
1622 ER a_ret;
1623 int a_size;
1624 int a_sw_ok = 1;
1625
1626 memset(&a_ecn_hdp, 0, sizeof(a_ecn_hdp));
1627
1628 /* ‰ŠúŽæ“¾ƒTƒCƒY */
1629 a_size = sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY) + sizeof(T_ECN_PRP);
1630
1631 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚̎擾 */
1632 a_ret = _ecn_fbs_cre(a_size, &a_fbs_res);
1633 if (a_ret != E_OK || !a_fbs_res.ptr) { /* Šm•ÛŽ¸”s */
1634 ECN_DBG_PUT "_ecn_fbs_cre() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1635 goto lb_finally;
1636 }
1637
1638 /* ‰ž“š“d•¶Ý’è */
1639 _ecn_tsk_mk_rsp_hdr_res(&a_ecn_hdp, p_req_esv);
1640
1641 f_put_fbs_eoj("_ecn_tsk_eoj_res", "fa_fbs_id", fa_fbs_id); /* s/deoj ƒfƒoƒbƒOo—Í */
1642
1643 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ */
1644 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_ecn_hdp,
1645 sizeof(a_ecn_hdp.ecn_hdr) + sizeof(a_ecn_hdp.edata));
1646 if (a_ret) {
1647 ECN_DBG_PUT "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1648 goto lb_except;
1649 }
1650
1651 /* payloadæ“ª‚ÌT_ECN_HDR(ecn_hdr), T_ECN_EDATA_BODY(edata)‚ð“Ç‚Ý”ò‚΂· */
1652 a_ret = _ecn_fbs_set_rpos(fa_fbs_id, offsetof(T_ECN_EDT_HDR, ecn_prp));
1653 if (a_ret) {
1654 ECN_DBG_PUT "_ecn_fbs_set_rpos() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1655 goto lb_except;
1656 }
1657
1658 /* ‰ž“š“d•¶—pfbsÝ’è */
1659 _ecn_tsk_set_rsp_fbs(a_fbs_res, fa_fbs_id.ptr);
1660
1661 /* ƒvƒƒpƒeƒB’l“ǂݍž‚ÝŽÀs */
1662 a_ret = _ecn_tsk_eoj_res_main(fa_fbs_id, a_fbs_res,
1663 ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.opc, &a_sw_ok);
1664 if (a_ret) {
1665 ECN_DBG_PUT "_ecn_tsk_eoj_res_main() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1666 goto lb_except;
1667 }
1668
1669 if (a_sw_ok) {
1670 if (!fa_res_esv) {
1671 /* ‰ž“š•s—v‚̏ꍇ */
1672 _ecn_fbs_del(a_fbs_res);
1673 goto lb_finally;
1674 }
1675 /* Ý’菈—¬Œ÷ */
1676 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_res_esv;
1677 } else {
1678 if (!fa_sna_esv) {
1679 /* ‰ž“š•s—v‚̏ꍇ */
1680 _ecn_fbs_del(a_fbs_res);
1681 goto lb_finally;
1682 }
1683 /* Ý’菈—Ž¸”s */
1684 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_sna_esv;
1685 }
1686 /* ‰ž“š‘—M */
1687 a_ret = _ecn_tsk_snd_mbx(a_fbs_res, false);
1688 if (a_ret != E_OK) {
1689 ECN_DBG_PUT "_ecn_tsk_snd_mbx() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
1690 goto lb_except;
1691 }
1692 goto lb_finally;
1693
1694lb_except:
1695 /* ƒf[ƒ^‘—MŽ¸”s‚µ‚½‚ç—̈æ‰ð•ú */
1696 if (a_fbs_res.ptr)
1697 _ecn_fbs_del(a_fbs_res);
1698
1699lb_finally:
1700 return;
1701}
1702
1703static void _ecn_tsk_eoj_set_get(const EOBJINIB *fp_obj, ATR fa_eobjatr,
1704 ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv, ECN_SRV_CODE fa_sna_esv,
1705 ECN_FBS_ID *fa_fbs_anno)
1706{
1707 T_ECN_EDT_HDR const *p_req_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
1708 T_ECN_EDT_HDR a_ecn_hdp;
1709 ECN_FBS_ID a_fbs_res = { 0 };
1710 int a_rdprp_wrpos; /* ƒvƒƒpƒeƒB“ǂݍž‚ÝŒ”‘‚«ž‚ÝŽž‚̃wƒbƒhˆÊ’u */
1711 ER a_ret;
1712 int i, a_size, a_rdlen;
1713 int a_sw_ok = 1;
1714 int a_count = ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.opc; /* ˆ—ƒvƒƒpƒeƒB” */
1715
1716 memset(&a_ecn_hdp, 0, sizeof(a_ecn_hdp));
1717
1718 ECN_DBG_PUT "_ecn_tsk_eoj_set_get() eoj:%06X",
1719 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3 ECN_DBG_END;
1720
1721 /* ‰ŠúŽæ“¾ƒTƒCƒY */
1722 a_size = sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY) + sizeof(T_ECN_PRP);
1723
1724 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚̎擾 */
1725 a_ret = _ecn_fbs_cre(a_size, &a_fbs_res);
1726 if (a_ret != E_OK || !a_fbs_res.ptr) /* Šm•ÛŽ¸”s */
1727 goto lb_finally;
1728
1729 /* ‰ž“š“d•¶Ý’è */
1730 if(p_req_esv->edata.deoj.eojx3 != 0)
1731 _ecn_tsk_mk_rsp_hdr_res(&a_ecn_hdp, p_req_esv);
1732 else
1733 _ecn_tsk_mk_rsp_hdr(fp_obj, &a_ecn_hdp, p_req_esv);
1734 a_size -= sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY);
1735
1736 f_put_fbs_eoj("_ecn_tsk_eoj_set_get", "fa_fbs_id", fa_fbs_id); /* s/deoj ƒfƒoƒbƒOo—Í */
1737
1738 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ */
1739 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_ecn_hdp,
1740 sizeof(a_ecn_hdp.ecn_hdr) + sizeof(a_ecn_hdp.edata));
1741 if (a_ret)
1742 goto lb_except;
1743
1744 /* payloadæ“ª‚ÌT_ECN_HDR(ecn_hdr), T_ECN_EDATA_BODY(edata)‚ð“Ç‚Ý”ò‚΂· */
1745 a_ret = _ecn_fbs_set_rpos(fa_fbs_id, offsetof(T_ECN_EDT_HDR, ecn_prp));
1746 if (a_ret)
1747 goto lb_except;
1748
1749 /* ‰ž“š“d•¶—pfbsÝ’è */
1750 _ecn_tsk_set_rsp_fbs(a_fbs_res, fa_fbs_id.ptr);
1751
1752 /* ƒvƒƒpƒeƒB’l‘‚«ž‚ÝŽÀs */
1753 a_ret = _ecn_tsk_eoj_set_main(fp_obj, fa_eobjatr, false, fa_fbs_id, a_fbs_res,
1754 fa_fbs_anno, a_count, &a_sw_ok);
1755 if (a_ret) {
1756 syslog(LOG_WARNING, "_ecn_tsk_eoj_set_get() eoj:%06X _ecn_tsk_eoj_set_main() fault. result = %d",
1757 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1758 a_ret);
1759 goto lb_except;
1760 }
1761 ECN_DBG_PUT "_ecn_tsk_eoj_set_get() eoj:%06X _ecn_tsk_eoj_set_main() ok sw_ok:%s",
1762 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1763 (a_sw_ok ? "true" : "false") ECN_DBG_END;
1764
1765 /* ŽŸ‚ÌŒ”‚ð“Ç‚ÝŽæ‚é(1byte) */
1766 /* ¨ ECHONET-Lite_Ver.1.10_02.pdf p.40 [OPCGet] */
1767 a_rdlen = i = 0;
1768 a_ret = _ecn_fbs_get_data(fa_fbs_id, &i, 1, &a_rdlen);
1769 if (a_ret < 0 || a_rdlen < 1)
1770 goto lb_except; /* NG */
1771 a_count = *(uint8_t *)&i;
1772
1773 /* ƒvƒƒpƒeƒB“ǂݍž‚ÝŒ”‘‚«ž‚ÝŽž‚̃wƒbƒhî•ñ‚ð‹L˜^ */
1774 a_rdprp_wrpos = _ecn_fbs_get_datalen(a_fbs_res);
1775
1776 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ (OPCGet 1byte) */
1777 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &i, 1);
1778 if (a_ret)
1779 goto lb_except;
1780
1781 /* ‚±‚ÌŽž“_‚ł̉ž“š“d•¶’†ƒvƒƒpƒeƒBŒ”‚ð‹L˜^ */
1782 i = ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc;
1783 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc = 0;
1784
1785 /* ƒvƒƒpƒeƒB’l“ǂݍž‚ÝŽÀs */
1786 a_ret = _ecn_tsk_eoj_get_main(fp_obj, fa_eobjatr, false, EPC_RULE_GET, fa_fbs_id, a_fbs_res,
1787 a_count, &a_sw_ok);
1788 if (a_ret) {
1789 syslog(LOG_WARNING, "_ecn_tsk_eoj_set_get() eoj:%06X _ecn_tsk_eoj_get_main() fault. result = %d",
1790 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1791 a_ret);
1792 goto lb_except;
1793 }
1794 ECN_DBG_PUT "_ecn_tsk_eoj_set_get() eoj:%06X _ecn_tsk_eoj_get_main() ok sw_ok:%s",
1795 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1796 (a_sw_ok ? "true" : "false") ECN_DBG_END;
1797
1798 /* ƒvƒƒpƒeƒB“ǂݍž‚ÝŒ”‘‚«ž‚ÝŽž‚̃wƒbƒhî•ñ‚ŁA“ǂݏo‚µŒ”‚ð‹L˜^ */
1799 _ecn_fbs_poke(a_fbs_res, a_rdprp_wrpos, ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc);
1800
1801 /* ‹L˜^‚µ‚Ä‚¨‚¢‚½ƒvƒƒpƒeƒBŒ”i‘‚«ž‚ÝŒ”j‚ð‘‚«–ß‚· */
1802 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc = (uint8_t)i;
1803
1804 /* ‰ž“š—v‚̏ꍇ */
1805 if (a_sw_ok) {
1806 /* Ý’菈—¬Œ÷ */
1807 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_res_esv;
1808 } else {
1809 /* Ý’菈—Ž¸”s */
1810 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_sna_esv;
1811 }
1812 /* ‰ž“š‘—M */
1813 a_ret = _ecn_tsk_snd_mbx(a_fbs_res, false);
1814 if (a_ret == E_OK)
1815 goto lb_finally;
1816
1817lb_except:
1818 /* ƒf[ƒ^‘—MŽ¸”s‚µ‚½‚ç—̈æ‰ð•ú */
1819 if (a_fbs_res.ptr)
1820 _ecn_fbs_del(a_fbs_res);
1821
1822lb_finally:
1823 return;
1824}
1825
1826static void _ecn_tsk_eoj_set_get_res(const EOBJINIB *fp_obj, ATR fa_eobjatr,
1827 ECN_FBS_ID fa_fbs_id, ECN_FBS_ID *fa_fbs_anno)
1828{
1829 T_ECN_EDT_HDR const *p_req_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
1830 T_ECN_EDT_HDR a_ecn_hdp;
1831 ECN_FBS_ID a_fbs_dmy = { 0 };
1832 ER a_ret;
1833 int i, a_size, a_rdlen;
1834 int a_sw_ok = 1;
1835 int a_count = ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.opc; /* ˆ—ƒvƒƒpƒeƒB” */
1836
1837 memset(&a_ecn_hdp, 0, sizeof(a_ecn_hdp));
1838
1839 ECN_DBG_PUT "_ecn_tsk_eoj_set_get_res() eoj:%06X",
1840 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3 ECN_DBG_END;
1841
1842 /* ‰ŠúŽæ“¾ƒTƒCƒY */
1843 a_size = sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY) + sizeof(T_ECN_PRP);
1844
1845 /* ‰ž“š“d•¶—pƒƒ‚ƒŠiƒ_ƒ~[j‚̎擾 */
1846 a_ret = _ecn_fbs_cre(a_size, &a_fbs_dmy);
1847 if (a_ret != E_OK || !a_fbs_dmy.ptr) /* Šm•ÛŽ¸”s */
1848 goto lb_finally;
1849
1850 /* ‰ž“š“d•¶Ý’è */
1851 _ecn_tsk_mk_rsp_hdr_res(&a_ecn_hdp, p_req_esv);
1852 a_size -= sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY);
1853
1854 /* payloadæ“ª‚ÌT_ECN_HDR(ecn_hdr), T_ECN_EDATA_BODY(edata)‚ð“Ç‚Ý”ò‚΂· */
1855 a_ret = _ecn_fbs_set_rpos(fa_fbs_id, offsetof(T_ECN_EDT_HDR, ecn_prp));
1856 if (a_ret)
1857 goto lb_except;
1858
1859 /* ƒvƒƒpƒeƒB’l‘‚«ž‚݉ž“š“Ç‚Ý”ò‚΂µŽÀs */
1860 a_ret = _ecn_tsk_eoj_skip_main(fp_obj, fa_fbs_id, a_count);
1861 if (a_ret) {
1862 syslog(LOG_WARNING, "_ecn_tsk_eoj_set_get_res() eoj:%06X _ecn_tsk_eoj_set_main() fault. result = %d",
1863 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1864 a_ret);
1865 goto lb_except;
1866 }
1867 ECN_DBG_PUT "_ecn_tsk_eoj_set_get_res() eoj:%06X _ecn_tsk_eoj_set_main() ok sw_ok:%s",
1868 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1869 (a_sw_ok ? "true" : "false") ECN_DBG_END;
1870
1871 /* ŽŸ‚ÌŒ”‚ð“Ç‚ÝŽæ‚é(1byte) */
1872 /* ¨ ECHONET-Lite_Ver.1.10_02.pdf p.40 [OPCGet] */
1873 a_rdlen = i = 0;
1874 a_ret = _ecn_fbs_get_data(fa_fbs_id, &i, 1, &a_rdlen);
1875 if (a_ret < 0 || a_rdlen < 1)
1876 goto lb_except; /* NG */
1877 a_count = *(uint8_t *)&i;
1878
1879 /* ƒvƒƒpƒeƒB’l“ǂݏo‚µ‰ž“š‚̏‘‚«ž‚ÝŽÀs */
1880 a_ret = _ecn_tsk_eoj_set_main(fp_obj, fa_eobjatr, true, fa_fbs_id, a_fbs_dmy,
1881 fa_fbs_anno, a_count, &a_sw_ok);
1882 if (a_ret) {
1883 syslog(LOG_WARNING, "_ecn_tsk_eoj_set_get_res() eoj:%06X _ecn_tsk_eoj_get_main() fault. result = %d",
1884 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1885 a_ret);
1886 goto lb_except;
1887 }
1888 ECN_DBG_PUT "_ecn_tsk_eoj_set_get_res() eoj:%06X _ecn_tsk_eoj_get_main() ok sw_ok:%s",
1889 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1890 (a_sw_ok ? "true" : "false") ECN_DBG_END;
1891
1892 goto lb_finally;
1893
1894lb_except:
1895 /* ƒf[ƒ^‘—MŽ¸”s‚µ‚½‚ç—̈æ‰ð•ú */
1896 if (a_fbs_dmy.ptr)
1897 _ecn_fbs_del(a_fbs_dmy);
1898
1899lb_finally:
1900 return;
1901}
1902
1903/*
1904 * ‰ž“š“d•¶‘Ò‚¿‚ÌŠ„‚荞‚Ý“d•¶ì¬
1905 */
1906ER _ecn_mk_brk_wai(ECN_FBS_ID *pk_fbs_id, const void *p_dat, size_t fa_size)
1907{
1908 ER a_ret;
1909 ECN_FBS_ID a_fbs_id = { 0 }; /* —v‹“d•¶—pƒƒ‚ƒŠ */
1910
1911 if (!pk_fbs_id)
1912 return E_PAR;
1913 *pk_fbs_id = a_fbs_id;
1914 if (sizeof(a_fbs_id.ptr->payload) <= fa_size)
1915 return E_PAR; /* •tƒf[ƒ^‚ª‘å‚«‚·‚¬‚é */
1916 if (!p_dat && 0 < fa_size)
1917 return E_PAR; /* •tƒf[ƒ^ƒTƒCƒY‚ª1ˆÈã‚Ȃ̂Ƀf[ƒ^ƒ|ƒCƒ“ƒ^‚ªNULL */
1918
1919 /* —v‹“d•¶—pƒƒ‚ƒŠ‚̎擾 */
1920 a_ret = _ecn_fbs_cre((0 < fa_size ? fa_size : 1), &a_fbs_id);
1921 if (a_ret != E_OK || !a_fbs_id.ptr) { /* Šm•ÛŽ¸”s */
1922 syslog(LOG_WARNING, "_ecn_fbs_cre(%d) result = %d:%s", fa_size, a_ret, itron_strerror(a_ret));
1923 return a_ret;
1924 }
1925
1926 /* —v‹“d•¶Ý’è */
1927 a_fbs_id.ptr->hdr.type = ECN_MSG_USER_BREAK;
1928 a_fbs_id.ptr->hdr.sender = ENOD_API_ID;
1929 a_fbs_id.ptr->hdr.target = ENOD_API_ID;
1930 a_fbs_id.ptr->hdr.reply = ENOD_API_ID;
1931
1932 if (0 < fa_size && p_dat) {
1933 /* •tƒf[ƒ^’ljÁ */
1934 a_ret = _ecn_fbs_add_data_ex(a_fbs_id, p_dat, fa_size);
1935 if (a_ret) {
1936 syslog(LOG_WARNING, "_ecn_fbs_add_data_ex(*, dat, %lu) result = %d:%s",
1937 fa_size,
1938 a_ret, itron_strerror(a_ret));
1939 goto lb_except;
1940 }
1941 }
1942
1943 *pk_fbs_id = a_fbs_id;
1944
1945 /* ³íI—¹ */
1946 return a_ret;
1947
1948lb_except:
1949 /* ƒf[ƒ^ì¬Ž¸”s‚µ‚½‚ç—̈æ‰ð•ú */
1950 if (a_fbs_id.ptr)
1951 _ecn_fbs_del(a_fbs_id);
1952
1953 return a_ret;
1954}
1955
1956/* ‰ž“š“d•¶—pfbsÝ’è(sender/target‚̐ݒè) */
1957ER _ecn_tsk_cre_req_fbs(ID sender, uint8_t cmd, ECN_FBS_ID *pk_req)
1958{
1959 ER ret;
1960 ECN_FBS_ID req;
1961
1962 ret = _ecn_fbs_cre(1, &req);
1963 if (ret != E_OK) {
1964 ECN_DBG_PUT "_ecn_tsk_cre_req_fbs() : _ecn_fbs_cre() result = %d:%s", ret, itron_strerror(ret) ECN_DBG_END;
1965 return ret;
1966 }
1967
1968 ret = _ecn_fbs_add_data(req, &cmd, sizeof(cmd));
1969 if (ret != E_OK) {
1970 _ecn_fbs_del(req);
1971 ECN_DBG_PUT "_ecn_tsk_cre_req_fbs() : _ecn_fbs_add_data() result = %d:%s", ret, itron_strerror(ret) ECN_DBG_END;
1972 return ret;
1973 }
1974
1975 req.ptr->hdr.type = ECN_MSG_INTERNAL;
1976 req.ptr->hdr.sender_mbxid = sender;
1977 req.ptr->hdr.target_mbxid = ecn_svc_mailboxid;
1978 req.ptr->hdr.reply_mbxid = sender;
1979
1980 *pk_req = req;
1981
1982 return E_OK;
1983}
1984
1985/* ‰ž“š“d•¶—pfbsÝ’è(sender/target‚̐ݒè) */
1986ER _ecn_tsk_cre_res_fbs(ECN_FBS_ID req, uint8_t cmd, ECN_FBS_ID *pk_res)
1987{
1988 ER ret;
1989 ECN_FBS_ID res;
1990
1991 ret = _ecn_fbs_cre(1, &res);
1992 if (ret != E_OK) {
1993 ECN_DBG_PUT "_ecn_tsk_cre_res_fbs() : _ecn_fbs_cre() result = %d:%s", ret, itron_strerror(ret) ECN_DBG_END;
1994 return ret;
1995 }
1996
1997 ret = _ecn_fbs_add_data(res, &cmd, sizeof(cmd));
1998 if (ret != E_OK) {
1999 _ecn_fbs_del(res);
2000 ECN_DBG_PUT "_ecn_tsk_cre_res_fbs() : _ecn_fbs_add_data() result = %d:%s", ret, itron_strerror(ret) ECN_DBG_END;
2001 return ret;
2002 }
2003
2004 res.ptr->hdr.type = ECN_MSG_INTERNAL;
2005 res.ptr->hdr.sender_mbxid = ecn_svc_mailboxid;
2006 res.ptr->hdr.target_mbxid = req.ptr->hdr.reply_mbxid;
2007 res.ptr->hdr.reply_mbxid = ecn_svc_mailboxid;
2008
2009 *pk_res = res;
2010
2011 return E_OK;
2012}
Note: See TracBrowser for help on using the repository browser.