aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-06-11 12:11:04 +0200
committerSven Gothel <[email protected]>2021-06-11 12:11:04 +0200
commitca5da49571242292a0be8ab404c878027ddbbb6a (patch)
tree835acf352cc03d7fc28dbd2a57f40db8254209bd
parentc6e1928c4a8f29d86c5766889e906e72d22b872d (diff)
SMPKeyBin: Make key base filename compatible to FAT32 Long filename (LFN)v2.2.6
Previous scheme : `bd_C0:26:DA:01:DA:B1:1.smpkey.bin' FAT32 LFN scheme: `bd_C0_26_DA_01_DA_B1_1-smpkey.bin' Tested interoperability with native and java test application.
-rw-r--r--api/direct_bt/SMPKeyBin.hpp26
-rw-r--r--java/org/direct_bt/SMPKeyBin.java22
-rw-r--r--src/direct_bt/SMPKeyBin.cpp11
3 files changed, 51 insertions, 8 deletions
diff --git a/api/direct_bt/SMPKeyBin.hpp b/api/direct_bt/SMPKeyBin.hpp
index 9844d0e8..7b77444b 100644
--- a/api/direct_bt/SMPKeyBin.hpp
+++ b/api/direct_bt/SMPKeyBin.hpp
@@ -48,6 +48,16 @@ namespace direct_bt {
* implementation supports mixed mode for certain devices.
* E.g. LTK responder key only etc.
* </p>
+ * <p>
+ * Filename as retrieved by SMPKeyBin::getFileBasename()
+ * has the following form `bd_C0_26_DA_01_DA_B1_1-smpkey.bin`:
+ * <ul>
+ * <li>{@code 'bd_'} denotes prefix</li>
+ * <li>{@code 'C0_26_DA_01_DA_B1'} denotes the {@link EUI48} address</li>
+ * <li>{@code '_1'} denotes the {@link BDAddressType}</li>
+ * <li>{@code '-smpkey.bin'} denotes the suffix</li>
+ * </li>
+ * </p>
*/
class SMPKeyBin {
public:
@@ -276,12 +286,16 @@ class SMPKeyBin {
std::string toString() const noexcept;
- std::string getFileBasename() const noexcept {
- return "bd_"+addrAndType.address.toString()+":"+std::to_string(number(addrAndType.type))+".smpkey.bin";
- }
- static std::string getFileBasename(const BDAddressAndType& addrAndType_) {
- return "bd_"+addrAndType_.address.toString()+":"+std::to_string(number(addrAndType_.type))+".smpkey.bin";
- }
+ /**
+ * Returns the base filename, see SMPKeyBin API doc for naming scheme.
+ */
+ std::string getFileBasename() const noexcept;
+
+ /**
+ * Returns the base filename, see SMPKeyBin API doc for naming scheme.
+ */
+ static std::string getFileBasename(const BDAddressAndType& addrAndType_);
+
static std::string getFilename(const std::string& path, const BDAddressAndType& addrAndType_) {
return path + "/" + getFileBasename(addrAndType_);
}
diff --git a/java/org/direct_bt/SMPKeyBin.java b/java/org/direct_bt/SMPKeyBin.java
index d0fa80ba..b8dff758 100644
--- a/java/org/direct_bt/SMPKeyBin.java
+++ b/java/org/direct_bt/SMPKeyBin.java
@@ -46,6 +46,16 @@ import org.direct_bt.SMPKeyMask.KeyType;
* implementation supports mixed mode for certain devices.
* E.g. LTK responder key only etc.
* </p>
+ * <p>
+ * Filename as retrieved by {@link #getFileBasename(BDAddressAndType)} and {@link #getFileBasename()}
+ * has the following form '{@code bd_C0_26_DA_01_DA_B1_1-smpkey.bin}':
+ * <ul>
+ * <li>{@code 'bd_'} denotes prefix</li>
+ * <li>{@code 'C0_26_DA_01_DA_B1'} denotes the {@link EUI48} address</li>
+ * <li>{@code '_1'} denotes the {@link BDAddressType}</li>
+ * <li>{@code '-smpkey.bin'} denotes the suffix</li>
+ * </li>
+ * </p>
*/
public class SMPKeyBin {
public static final short VERSION = (short)0b0101010101010101 + (short)2; // bitpattern + version
@@ -325,11 +335,19 @@ public class SMPKeyBin {
( !hasLTKResp() || ltk_resp.isValid() );
}
+ /**
+ * Returns the base filename, see {@link SMPKeyBin} API doc for naming scheme.
+ */
final public String getFileBasename() {
- return "bd_"+addrAndType.address.toString()+":"+addrAndType.type.value+".smpkey.bin";
+ final String r = "bd_"+addrAndType.address.toString()+":"+addrAndType.type.value+"-smpkey.bin";
+ return r.replace(':', '_');
}
+ /**
+ * Returns the base filename, see {@link SMPKeyBin} API doc for naming scheme.
+ */
final public static String getFileBasename(final BDAddressAndType addrAndType_) {
- return "bd_"+addrAndType_.address.toString()+":"+addrAndType_.type.value+".smpkey.bin";
+ final String r = "bd_"+addrAndType_.address.toString()+":"+addrAndType_.type.value+"-smpkey.bin";
+ return r.replace(':', '_');
}
final public static String getFilename(final String path, final BDAddressAndType addrAndType_) {
return path + "/" + getFileBasename(addrAndType_);
diff --git a/src/direct_bt/SMPKeyBin.cpp b/src/direct_bt/SMPKeyBin.cpp
index e9fbbac2..252d747e 100644
--- a/src/direct_bt/SMPKeyBin.cpp
+++ b/src/direct_bt/SMPKeyBin.cpp
@@ -138,6 +138,17 @@ std::string SMPKeyBin::toString() const noexcept {
return res;
}
+std::string SMPKeyBin::getFileBasename() const noexcept {
+ std::string r("bd_"+addrAndType.address.toString()+":"+std::to_string(number(addrAndType.type))+"-smpkey.bin");
+ std::replace( r.begin(), r.end(), ':', '_');
+ return r;
+}
+std::string SMPKeyBin::getFileBasename(const BDAddressAndType& addrAndType_) {
+ std::string r("bd_"+addrAndType_.address.toString()+":"+std::to_string(number(addrAndType_.type))+"-smpkey.bin");
+ std::replace( r.begin(), r.end(), ':', '_');
+ return r;
+}
+
bool SMPKeyBin::remove_impl(const std::string& fname) {
#if USE_CXX17lib_FS
const fs::path fname2 = fname;