2015-08-10 11:28:12 +02:00
|
|
|
/****************************************************************************
|
2017-04-21 15:40:41 +02:00
|
|
|
* apps/wireless/ieee802154/libutils/ieee802154_addrtostr.c
|
2015-08-10 11:28:12 +02:00
|
|
|
*
|
2021-06-09 16:42:28 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2015-08-10 11:28:12 +02:00
|
|
|
*
|
2021-06-09 16:42:28 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-08-10 11:28:12 +02:00
|
|
|
*
|
2021-06-09 16:42:28 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2015-08-10 11:28:12 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2017-03-29 18:45:49 +02:00
|
|
|
|
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
2017-04-21 15:49:55 +02:00
|
|
|
#include "wireless/ieee802154.h"
|
2015-08-10 11:28:12 +02:00
|
|
|
|
2017-03-24 21:51:12 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-19 11:56:52 +02:00
|
|
|
|
2017-03-24 21:51:12 +01:00
|
|
|
int ieee802154_addrtostr(FAR char *buf, int len,
|
|
|
|
FAR struct ieee802154_addr_s *addr)
|
2015-08-10 11:28:12 +02:00
|
|
|
{
|
2017-06-19 11:56:52 +02:00
|
|
|
#if 0
|
2015-08-10 11:28:12 +02:00
|
|
|
#ifndef CONFIG_BIG_ENDIAN
|
2017-04-21 15:03:50 +02:00
|
|
|
uint16_t panid = ((addr->panid & 0xff) << 8) | ((addr->panid >> 8) & 0xff);
|
2015-08-10 11:28:12 +02:00
|
|
|
#else
|
2017-04-21 15:03:50 +02:00
|
|
|
uint16_t panid = addr->panid;
|
2015-08-10 11:28:12 +02:00
|
|
|
#endif
|
|
|
|
|
2017-04-21 15:03:50 +02:00
|
|
|
if (addr->mode == IEEE802154_ADDRMODE_NONE)
|
2015-08-10 11:28:12 +02:00
|
|
|
{
|
|
|
|
return snprintf(buf, len, "none");
|
|
|
|
}
|
2017-04-21 15:03:50 +02:00
|
|
|
else if (addr->mode == IEEE802154_ADDRMODE_SHORT)
|
2015-08-10 11:28:12 +02:00
|
|
|
{
|
|
|
|
#ifndef CONFIG_BIG_ENDIAN
|
2017-04-21 15:03:50 +02:00
|
|
|
uint16_t saddr = ((addr->saddr & 0xff) << 8) | ((addr->saddr >> 8) & 0xff);
|
2015-08-10 11:28:12 +02:00
|
|
|
#else
|
2017-04-21 15:03:50 +02:00
|
|
|
uint16_t saddr = addr->saddr;
|
2015-08-10 11:28:12 +02:00
|
|
|
#endif
|
|
|
|
return snprintf(buf, len, "%04X/%04X", panid, saddr);
|
|
|
|
}
|
2017-04-21 15:03:50 +02:00
|
|
|
else if (addr->mode == IEEE802154_ADDRMODE_EXTENDED)
|
2015-08-10 11:28:12 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int off = snprintf(buf, len, "%04X/", panid);
|
2017-03-24 21:51:12 +01:00
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
2015-08-10 11:28:12 +02:00
|
|
|
{
|
2017-04-21 15:03:50 +02:00
|
|
|
off += snprintf(buf + off, len -off, "%02X", addr->eaddr[i]);
|
2015-08-10 11:28:12 +02:00
|
|
|
}
|
2017-03-24 21:51:12 +01:00
|
|
|
|
2015-08-10 11:28:12 +02:00
|
|
|
return off;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return snprintf(buf,len,"<INVAL>");
|
|
|
|
}
|
2017-03-24 21:51:12 +01:00
|
|
|
|
2017-06-19 11:56:52 +02:00
|
|
|
return -1;
|
|
|
|
#endif
|
2015-08-10 11:28:12 +02:00
|
|
|
return -1;
|
|
|
|
}
|