• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025-2026 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ALLOWEDNSSAICONFIG_H
17 #define ALLOWEDNSSAICONFIG_H
18 
19 #include <cstdint>
20 #include <string>
21 #include <vector>
22 #include <iostream>
23 #include <nlohmann/json.hpp>
24 
25 namespace OHOS {
26 namespace NetManagerStandard {
27 
28 class Snssai {
29 public:
setSnssaiLen(uint8_t snssaiLen)30     void setSnssaiLen(uint8_t snssaiLen)
31     {
32         mSnssaiLen = snssaiLen;
33     }
34 
getSnssaiLen()35     uint8_t getSnssaiLen() const
36     {
37         return mSnssaiLen;
38     }
39 
setSst(uint8_t sst)40     void setSst(uint8_t sst)
41     {
42         mSst = sst;
43     }
44 
getSst()45     uint8_t getSst() const
46     {
47         return mSst;
48     }
49 
setSd(int sd)50     void setSd(int sd)
51     {
52         mSd = sd;
53     }
54 
getSd()55     int getSd() const
56     {
57         return mSd;
58     }
59 
setMappedSst(uint8_t mappedSst)60     void setMappedSst(uint8_t mappedSst)
61     {
62         mMappedSst = mappedSst;
63     }
64 
getMappedSst()65     uint8_t getMappedSst() const
66     {
67         return mMappedSst;
68     }
69 
setMappedSd(int mappedSd)70     void setMappedSd(int mappedSd)
71     {
72         mMappedSd = mappedSd;
73     }
74 
getMappedSd()75     int getMappedSd() const
76     {
77         return mMappedSd;
78     }
79 
setSnssai(const std::string & snssai)80     void setSnssai(const std::string& snssai)
81     {
82         mSnssai = snssai;
83     }
84 
getSnssai()85     const std::string& getSnssai() const
86     {
87         return mSnssai;
88     }
89 
to_json()90     nlohmann::json to_json() const
91     {
92         return nlohmann::json::object({
93             {"snssaiLen", mSnssaiLen},
94             {"sst", mSst},
95             {"sd", mSd},
96             {"mappedSst", mMappedSst},
97             {"mappedSd", mMappedSd},
98             {"snssai", mSnssai}
99         });
100     }
from_json(const nlohmann::json & jsonSnssai)101     void from_json(const nlohmann::json& jsonSnssai)
102     {
103         if (jsonSnssai.find("snssaiLen") != jsonSnssai.end()) {
104             mSnssaiLen = jsonSnssai.at("snssaiLen").get<uint8_t>();
105         }
106 
107         if (jsonSnssai.find("sst") != jsonSnssai.end()) {
108             mSst = jsonSnssai.at("sst").get<uint8_t>();
109         }
110 
111         if (jsonSnssai.find("sd") != jsonSnssai.end()) {
112             mSd = jsonSnssai.at("sd").get<int>();
113         }
114 
115         if (jsonSnssai.find("mappedSst") != jsonSnssai.end()) {
116             mMappedSst = jsonSnssai.at("mappedSst").get<uint8_t>();
117         }
118 
119         if (jsonSnssai.find("mappedSd") != jsonSnssai.end()) {
120             mMappedSd = jsonSnssai.at("mappedSd").get<int>();
121         }
122 
123         if (jsonSnssai.find("snssai") != jsonSnssai.end()) {
124             mSnssai = jsonSnssai.at("snssai").get<std::string>();
125         }
126     }
127 
128 private:
129     uint8_t mSnssaiLen; // Snssai的长度
130     uint8_t mSst; // Service Type
131     int mSd; // Service Domain
132     uint8_t mMappedSst; // Mapped Service Type
133     int mMappedSd; // Mapped Service Domain
134     std::string mSnssai; // Snssai的字符串表示
135 };
136 
137 class AllowedNssaiConfig {
138 public:
139     static AllowedNssaiConfig& GetInstance();
140     ~AllowedNssaiConfig() = default;
141     std::vector<Snssai> mAllowedNssais;
142     bool ParseSnssai(Snssai& snssai);
143     void DecodeAllowedNssai(std::vector<uint8_t> buffer);
144     bool DecodeSnssai(int& startIndex, uint8_t len, std::vector<uint8_t> buffer, Snssai& snssai);
145     void DumpAllowedNssai();
146     std::string FindSnssaiInAllowedNssai(const std::vector<Snssai>& snssais);
147     std::string isSnssaiInAllowedNssai(Snssai snssai);
148 private:
149     AllowedNssaiConfig() = default;
150 };
151 extern std::shared_ptr<AllowedNssaiConfig> sAllowedNssaiConfig_;
152 
153 } // namespace NetManagerStandard
154 } // namespace OHOS
155 
156 
157 #endif  // ALLOWEDNSSAICONFIG_H
158