summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTonyCave2013-12-04 10:39:37 -0600
committerTonyCave2013-12-04 10:39:37 -0600
commit35fab736557eb52790ff9e086f8d17aaa0198c69 (patch)
tree69bc3c8cef99986aad8d46879406d9510cf7a119
parentc26bd9dbde9d106444c08de8de655bedcdd4c6dc (diff)
downloadlighting-gateway-35fab736557eb52790ff9e086f8d17aaa0198c69.tar.gz
lighting-gateway-35fab736557eb52790ff9e086f8d17aaa0198c69.tar.xz
lighting-gateway-35fab736557eb52790ff9e086f8d17aaa0198c69.zip
added support for starting FN control bridge and sending management permit join
-rw-r--r--client/CClients/lightFlashCmdLine/linux-gnu/makefile2
-rw-r--r--client/CClients/listDevsCmdLine/linux-gnu/makefile2
-rwxr-xr-xclient/CClients/openNetwork/Source/openNetwork.c6
-rw-r--r--client/CClients/openNetwork/linux-gnu/makefile2
-rw-r--r--zbFwStart/makefile26
-rw-r--r--zbFwStart/zbFwStart.c182
-rwxr-xr-xzbSocDriver/zbSocCmd.c56
-rwxr-xr-xzbSocDriver/zbSocCmd.h2
8 files changed, 267 insertions, 11 deletions
diff --git a/client/CClients/lightFlashCmdLine/linux-gnu/makefile b/client/CClients/lightFlashCmdLine/linux-gnu/makefile
index 8d799d3..35ba87b 100644
--- a/client/CClients/lightFlashCmdLine/linux-gnu/makefile
+++ b/client/CClients/lightFlashCmdLine/linux-gnu/makefile
@@ -5,7 +5,7 @@ DEVICE = COORDINATOR
5#Relative project path 5#Relative project path
6PROJ_DIR = 6PROJ_DIR =
7 7
8INCLUDE = -I$(PROJ_DIR)../../../../server/Source -I$(PROJ_DIR)../../Source -I$(PROJ_DIR)../Source 8INCLUDE = -I$(PROJ_DIR)../../../../zbSocDriver -I$(PROJ_DIR)../../../../server/Source -I$(PROJ_DIR)../../Source -I$(PROJ_DIR)../Source
9LIBS = -lpthread 9LIBS = -lpthread
10 10
11#CC= /data/opt/vendors/codesourcery/lite/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc 11#CC= /data/opt/vendors/codesourcery/lite/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc
diff --git a/client/CClients/listDevsCmdLine/linux-gnu/makefile b/client/CClients/listDevsCmdLine/linux-gnu/makefile
index 5d05687..c569de2 100644
--- a/client/CClients/listDevsCmdLine/linux-gnu/makefile
+++ b/client/CClients/listDevsCmdLine/linux-gnu/makefile
@@ -5,7 +5,7 @@ DEVICE = COORDINATOR
5#Relative project path 5#Relative project path
6PROJ_DIR = 6PROJ_DIR =
7 7
8INCLUDE = -I$(PROJ_DIR)../../../../server/Source -I$(PROJ_DIR)../Source -I$(PROJ_DIR)../../Source 8INCLUDE = -I$(PROJ_DIR)../../../../zbSocDriver -I$(PROJ_DIR)../../../../server/Source -I$(PROJ_DIR)../Source -I$(PROJ_DIR)../../Source
9LIBS = -lpthread 9LIBS = -lpthread
10 10
11#CC= /data/opt/vendors/codesourcery/lite/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc 11#CC= /data/opt/vendors/codesourcery/lite/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc
diff --git a/client/CClients/openNetwork/Source/openNetwork.c b/client/CClients/openNetwork/Source/openNetwork.c
index 589493d..a2592b2 100755
--- a/client/CClients/openNetwork/Source/openNetwork.c
+++ b/client/CClients/openNetwork/Source/openNetwork.c
@@ -151,11 +151,13 @@ void sendOpenNetwork(uint8_t duration)
151 151
152 printf("sendOpenNetwork++: duration=%d\n", duration); 152 printf("sendOpenNetwork++: duration=%d\n", duration);
153 153
154 msg.cmdId = SRPC_OPEN_NETWORK; 154 msg.cmdId = SRPC_PERMIT_JOIN;
155 msg.len = 3; 155 msg.len = 5;
156 156
157 //duration 157 //duration
158 *pRpcCmd++ = duration; 158 *pRpcCmd++ = duration;
159 *pRpcCmd++ = JOIN_AUTH_NUM & 0xFF;
160 *pRpcCmd++ = (JOIN_AUTH_NUM & 0xFF00) >> 8;
159 161
160 socketClientSendData(&msg); 162 socketClientSendData(&msg);
161} 163}
diff --git a/client/CClients/openNetwork/linux-gnu/makefile b/client/CClients/openNetwork/linux-gnu/makefile
index 1ea0e57..8c2939b 100644
--- a/client/CClients/openNetwork/linux-gnu/makefile
+++ b/client/CClients/openNetwork/linux-gnu/makefile
@@ -5,7 +5,7 @@ DEVICE = COORDINATOR
5#Relative project path 5#Relative project path
6PROJ_DIR = 6PROJ_DIR =
7 7
8INCLUDE = -I$(PROJ_DIR)../../../../server/Source -I$(PROJ_DIR)../Source -I$(PROJ_DIR)../../Source 8INCLUDE = -I$(PROJ_DIR)../../../../zbSocDriver -I$(PROJ_DIR)../../../../server/Source -I$(PROJ_DIR)../Source -I$(PROJ_DIR)../../Source
9LIBS = -lpthread 9LIBS = -lpthread
10 10
11#CC= /data/opt/vendors/codesourcery/lite/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc 11#CC= /data/opt/vendors/codesourcery/lite/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc
diff --git a/zbFwStart/makefile b/zbFwStart/makefile
new file mode 100644
index 0000000..8d6fa55
--- /dev/null
+++ b/zbFwStart/makefile
@@ -0,0 +1,26 @@
1
2SBU_REV= "0.1"
3
4
5GCC = gcc
6
7CFLAGS = -Wall -DVERSION_NUMBER=${SBU_REV}
8OBJECTS = zbFwStart.o ../zbSocDriver/zbSocCmd.o
9INCLUDE = -I../zbSocDriver/
10DEFS =
11
12APP_NAME=zbFwStart.bin
13
14.PHONY: all, clean
15
16${APP_NAME}: ${OBJECTS}
17 $(GCC) $(CFLAGS) $(OBJECTS) -o ${APP_NAME}
18
19%.o: %.c
20 ${GCC} ${CFLAGS} ${INCLUDE} ${DEFS} -c -o $@ $<
21
22all: ${APP_NAME}
23
24clean:
25 rm -rf *.o ${APP_NAME}
26 rm -rf ../zbSocDriver/*.o ${APP_NAME}
diff --git a/zbFwStart/zbFwStart.c b/zbFwStart/zbFwStart.c
new file mode 100644
index 0000000..c5a95c0
--- /dev/null
+++ b/zbFwStart/zbFwStart.c
@@ -0,0 +1,182 @@
1/**************************************************************************************************
2 * Filename: zbFwStart.c
3 * Description: This starts the network (if needed) and gets the FW model.
4 *
5 *
6 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
38
39#include <string.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <poll.h>
43
44#include "zbSocCmd.h"
45
46uint8_t tlIndicationCb(epInfo_t *epInfo);
47uint8_t utilGetDevInfoRspCb(uint8_t status, uint16_t nwkAddr,
48 uint8_t ieeeAddr[8], uint8_t devType, uint8_t devState);
49uint8_t zclGetModelCb(uint8_t *ModelId);
50
51static zbSocCallbacks_t zbSocCbs =
52{ tlIndicationCb, // pfnTlIndicationCb - TouchLink Indication callback
53 NULL, // pfnNewDevIndicationCb - New Device Indication callback
54 NULL, //pfnZclGetStateCb - ZCL response callback for get State
55 NULL, //pfnZclGetLevelCb_t - ZCL response callback for get Level
56 NULL, // pfnZclGetHueCb - ZCL response callback for get Hue
57 NULL, //pfnZclGetSatCb - ZCL response callback for get Sat
58 NULL, //pfnzdoSimpleDescRspCb - ZDO simple desc rsp
59 NULL, // pfnZdoLeaveIndCb - ZDO Leave indication
60 utilGetDevInfoRspCb, //pfnUtilGetDevInfoRspCb
61 zclGetModelCb //pfnZclGetModelCb
62 };
63
64void usage(char* exeName)
65{
66 printf("Usage: ./%s <port>\n", exeName);
67 printf("Eample: ./%s /dev/ttyACM0\n", exeName);
68}
69
70int main(int argc, char* argv[])
71{
72 int retval = 0;
73 int zbSoc_fd;
74
75 //printf("%s -- %s %s\n", argv[0], __DATE__, __TIME__);
76
77
78 // accept only 1
79 if (argc != 2)
80 {
81 usage(argv[0]);
82 //printf("attempting to use /dev/ttyACM0\n");
83 zbSoc_fd = zbSocOpen("/dev/ttyO4");
84 }
85 else
86 {
87 zbSoc_fd = zbSocOpen(argv[1]);
88 }
89
90 if (zbSoc_fd == -1)
91 {
92 exit(-1);
93 }
94
95 zbSocRegisterCallbacks(zbSocCbs);
96
97 //Attempt to start the network (assuming it is a control bridge
98 //that needs a command to start the network).
99 zbSocBridgeStartNwk();
100
101 zbSocGetInfo();
102
103 while (1)
104 {
105 struct pollfd pollFd;
106
107 //set the zllSoC serial port FD in the poll file descriptors
108 pollFd.fd = zbSoc_fd;
109 pollFd.events = POLLIN;
110
111 //printf("%s: waiting for poll()\n", argv[1]);
112
113 poll(&pollFd, 1, 500);
114
115 //printf("%s: got poll()\n", argv[1]);
116
117 //did the poll unblock because of the zllSoC serial?
118 if (pollFd.revents)
119 {
120 //printf("%s: Message from ZB SoC\n", argv[1]);
121 zbSocProcessRpc();
122 }
123 else
124 {
125 //printf("timeout\n");
126 static int timeoutCnt = 0;
127 timeoutCnt++;
128 if(timeoutCnt > 5)
129 {
130 printf("Unknown model\n");
131 zbSocClose();
132 exit(0);
133 }
134 else if(timeoutCnt > 3)
135 {
136 //maybe MT_UTIL is not define, assume coord (nwkAddr=0x0) and try to get model ID
137 zbSocGetModel(0x0000, 0xff, afAddr16Bit);
138 }
139 else
140 {
141 zbSocGetInfo();
142 }
143 }
144 }
145
146 return retval;
147}
148
149uint8_t tlIndicationCb(epInfo_t *epInfo)
150{
151
152return 0;
153}
154
155uint8_t utilGetDevInfoRspCb(uint8_t status, uint16_t nwkAddr,
156 uint8_t ieeeAddr[8], uint8_t devType, uint8_t devState)
157{
158 //printf("processRpcUtilGetDevInfoRsp: status:%x devState:%x, nwkAddr:%x ieeeIdx:%x:%x:%x:%x:%x:%x:%x:%x\n", status, devState, nwkAddr,
159//ieeeAddr[7], ieeeAddr[6], ieeeAddr[5], ieeeAddr[4], ieeeAddr[3], ieeeAddr[2], ieeeAddr[1], ieeeAddr[0]);
160
161 zbSocGetModel(nwkAddr, 0xff, afAddr16Bit);
162
163 return 0;
164}
165
166uint8_t zclGetModelCb(uint8_t *ModelId)
167{
168 uint8_t strIdx;
169 printf("Model ID:");
170
171 for(strIdx = 0; strIdx < ModelId[0]; strIdx++)
172 {
173 printf("%c", ModelId[strIdx+1]);
174 }
175 printf("\n");
176
177 zbSocClose();
178 exit(0);
179
180 return 0;
181}
182
diff --git a/zbSocDriver/zbSocCmd.c b/zbSocDriver/zbSocCmd.c
index e3e87aa..22d8fd1 100755
--- a/zbSocDriver/zbSocCmd.c
+++ b/zbSocDriver/zbSocCmd.c
@@ -86,6 +86,7 @@ len, /*RPC payload Len */ \
86#define ZLL_MT_APP_RPC_CMD_JOIN_HA 0x04 86#define ZLL_MT_APP_RPC_CMD_JOIN_HA 0x04
87#define ZLL_MT_APP_RPC_CMD_PERMIT_JOIN 0x05 87#define ZLL_MT_APP_RPC_CMD_PERMIT_JOIN 0x05
88#define ZLL_MT_APP_RPC_CMD_SEND_RESET_TO_FN 0x06 88#define ZLL_MT_APP_RPC_CMD_SEND_RESET_TO_FN 0x06
89#define ZLL_MT_APP_RPC_CMD_START_DISTRIB_NWK 0x07
89 90
90#define MT_APP_RSP 0x80 91#define MT_APP_RSP 0x80
91#define MT_APP_ZLL_TL_IND 0x81 92#define MT_APP_ZLL_TL_IND 0x81
@@ -388,6 +389,30 @@ void zbSocTouchLink(void)
388} 389}
389 390
390/********************************************************************* 391/*********************************************************************
392 * @fn zbSocBridgeStartNwk
393 *
394 * @brief Send the start network command to the CC253x.
395 *
396 * @param none
397 *
398 * @return none
399 */
400void zbSocBridgeStartNwk(void)
401{
402 uint8_t cmd[] =
403 { APPCMDHEADER(13) 0x06, //Data Len
404 0x02, //Address Mode
405 0x00,//2dummy bytes
406 0x00, ZLL_MT_APP_RPC_CMD_START_DISTRIB_NWK, 0x00, //
407 0x00, //
408 0x00 //FCS - fill in later
409 };
410
411 calcFcs(cmd, sizeof(cmd));
412 zbSocTransportWrite(cmd, sizeof(cmd));
413}
414
415/*********************************************************************
391 * @fn zbSocResetToFn 416 * @fn zbSocResetToFn
392 * 417 *
393 * @brief Send the reset to factory new command to the CC253x. 418 * @brief Send the reset to factory new command to the CC253x.
@@ -446,21 +471,40 @@ void zbSocSendResetToFn(void)
446 */ 471 */
447void zbSocOpenNwk(uint8_t duration) 472void zbSocOpenNwk(uint8_t duration)
448{ 473{
449 uint8_t cmd[] = 474 uint16_t srcNwkAddr = 0xFFFD; //Everyone with RxOnWhenIdle == TRUE
475
476 uint8_t mgmtPermit[] =
477 { 0xFE, 5, /*RPC payload Len */
478 MT_RPC_CMD_SREQ | MT_RPC_SYS_ZDO,
479 0x36, /*MT_ZDO_MGMT_PERMIT_JOIN_REQ*/
480 afAddrBroadcast, //addr mode
481 (srcNwkAddr & 0x00ff), /*Src Nwk Addr - To send the bind message to*/
482 (srcNwkAddr & 0xff00) >> 8, /*Src Nwk Addr - To send the bind message to*/
483 duration, /*Dst endpoint for the binding*/
484 1, /*trust center significance set*/
485 0x00 //FCS - fill in later
486 };
487
488 uint8_t localPermit[] =
450 { APPCMDHEADER(13) 0x06, //Data Len 489 { APPCMDHEADER(13) 0x06, //Data Len
451 0x02, //Address Mode 490 0x02, //Address Mode
452 0x00,//2dummy bytes 491 0x00,//2dummy bytes
453 0x00, ZLL_MT_APP_RPC_CMD_PERMIT_JOIN, 0x00, // 492 0x00, ZLL_MT_APP_RPC_CMD_PERMIT_JOIN,
493 duration, //
454 0x00, // 494 0x00, //
455 0x00 //FCS - fill in later 495 0x00 //FCS - fill in later
456 }; 496 };
457 497
458 cmd[15] = duration;
459
460 printf("zbSocOpenNwk: duration %ds\n", duration); 498 printf("zbSocOpenNwk: duration %ds\n", duration);
461 499
462 calcFcs(cmd, sizeof(cmd)); 500 calcFcs(localPermit, sizeof(localPermit));
463 zbSocTransportWrite(cmd, sizeof(cmd)); 501 zbSocTransportWrite(localPermit, sizeof(localPermit));
502
503 //wait for message to be consumed
504 usleep(30);
505
506 calcFcs(mgmtPermit, sizeof(mgmtPermit));
507 zbSocTransportWrite(mgmtPermit, sizeof(mgmtPermit));
464} 508}
465 509
466/********************************************************************* 510/*********************************************************************
diff --git a/zbSocDriver/zbSocCmd.h b/zbSocDriver/zbSocCmd.h
index e622206..8ae5f36 100755
--- a/zbSocDriver/zbSocCmd.h
+++ b/zbSocDriver/zbSocCmd.h
@@ -125,6 +125,8 @@ void zbSocTouchLink(void);
125void zbSocResetToFn(void); 125void zbSocResetToFn(void);
126void zbSocSendResetToFn(void); 126void zbSocSendResetToFn(void);
127void zbSocOpenNwk(uint8_t duration); 127void zbSocOpenNwk(uint8_t duration);
128void zbSocBridgeStartNwk(void);
129
128//ZCL Set API's 130//ZCL Set API's
129void zbSocSetState(uint8_t state, uint16_t dstAddr, uint8_t endpoint, 131void zbSocSetState(uint8_t state, uint16_t dstAddr, uint8_t endpoint,
130 uint8_t addrMode); 132 uint8_t addrMode);