static void display_cap(struct writer * w, struct lldpd_chassis *chassis, u_int8_t bit, char *symbol) { if (chassis->c_cap_available & bit) { tag_start(w, "capability", "Capability"); tag_attr (w, "type", "", symbol ); tag_attr (w, "enabled", "", (chassis->c_cap_enabled & bit)?"on":"off"); tag_end (w); } }
static void display_med_capability(struct writer *w, long int available, int cap, const char *symbol) { if (available & cap) { tag_start(w, "capability", "Capability"); tag_attr(w, "type", "", symbol); tag_attr(w, "available", "", "yes"); tag_end(w); } }
static void display_cap(struct writer * w, lldpctl_atom_t *chassis, u_int8_t bit, char *symbol) { if (lldpctl_atom_get_int(chassis, lldpctl_k_chassis_cap_available) & bit) { tag_start(w, "capability", "Capability"); tag_attr (w, "type", "", symbol ); tag_attr (w, "enabled", "", (lldpctl_atom_get_int(chassis, lldpctl_k_chassis_cap_enabled) & bit)? "on":"off"); tag_end (w); } }
static void display_med_capability(struct writer *w, struct lldpd_chassis *chassis, int cap) { if (chassis->c_med_cap_available & cap) { tag_start(w, "capability", "Capability"); tag_attr(w, "type", "", map_lookup(lldpmed_capabilit_map, cap)); tag_end(w); } }
void vs_list_files(const char* path, int stage) { const char* ptr = path; while (strncmp(ptr, "../", 3) == 0) ptr += 3; ptr = strchr(ptr, '/'); while (ptr != NULL) ptr = strchr(ptr + 1, '/'); ptr = strrchr(path, '/'); ptr = (ptr == NULL) ? (char*)path : ptr + 1; switch (stage) { case WST_OPENGROUP: if (strlen(path) > 0 && !matches(ptr, "..")) { tag_open("Filter"); tag_attr("Name=\"%s\"", ptr); tag_attr("Filter=\"\""); } break; case WST_CLOSEGROUP: if (strlen(path) > 0 && !matches(ptr, "..")) tag_close("Filter", 1); break; case WST_SOURCEFILE: tag_open("File"); tag_attr_open("RelativePath"); if (path[0] != '.') io_print(".\\"); io_print(path_translate(path, "windows")); tag_attr_close(); tag_close("File", 1); break; } }
void vs_list_files(const char* path, int stage) { int i; const char* pchHeader = prj_get_pch_header(); const char* pchSource = prj_get_pch_source(); const char* trimPrefix = prj_get_trimprefix(); const char* ptr = path; while (strncmp(ptr, "../", 3) == 0) ptr += 3; ptr = strchr(ptr, '/'); while (ptr != NULL) ptr = strchr(ptr + 1, '/'); ptr = strrchr(path, '/'); ptr = (ptr == NULL) ? (char*)path : ptr + 1; switch (stage) { case WST_OPENGROUP: if (strlen(path) > 0 && !matches(ptr, "..") && (!trimPrefix || strncmp(path, trimPrefix, strlen(trimPrefix)) == 0)) { tag_open("Filter"); tag_attr("Name=\"%s\"", ptr); tag_attr("Filter=\"\""); } break; case WST_CLOSEGROUP: if (strlen(path) > 0 && !matches(ptr, "..") && (!trimPrefix || strncmp(path, trimPrefix, strlen(trimPrefix)) == 0)) tag_close("Filter", 1); break; case WST_SOURCEFILE: tag_open("File"); tag_attr_open("RelativePath"); if (path[0] != '.') io_print(".\\"); io_print(path_translate(path, "windows")); tag_attr_close(); /* Add FileConfiguration section if this is a special PCH file, or if it's a custom-built .asm */ if (matches(path_getname(path), pchSource) || endsWith(path, ".asm") || (prj_is_kind("cxxtestgen") && endsWith(path, ".h"))) { for (i = 0; i < prj_get_numconfigs(); ++i) { prj_select_config(i); tag_open("FileConfiguration"); tag_attr("Name=\"%s|Win32\"", prj_get_cfgname()); if (endsWith(path, ".asm")) { tag_open("Tool"); tag_attr("Name=\"VCCustomBuildTool\""); tag_attr("Description=\"Assembling $(InputPath)\""); { // note: copy into our strings because path_* use static buffers. char nasm_path[512]; // PATH_MAX isn't defined char input_dir[512]; strcpy(nasm_path, path_translate(prj_get_nasmpath(), "windows")); // note: NASM chokes on -i"path" and says "no input file". // we therefore use the *relative* input directory, not VC's $(InputDir) - // this is more likely not to contain a space in directory name. strcpy(input_dir, path_translate(path_getdir(path) , "windows")); // required - NASM just concatenates include path and filename. strcat(input_dir, "\\"); tag_attr("CommandLine=\"%s -i %s -f win32 "$(InputPath)" -o "$(IntDir)\\$(InputName).obj"\"", nasm_path, input_dir); } tag_attr("Outputs=\"$(IntDir)\\$(InputName).obj\""); tag_close("Tool", 0); } else if (prj_is_kind("cxxtestgen") && endsWith(path, ".h")) { char *targetname = strdup(path_swapextension(path, ".h", ".cpp")); char *testoptions = strdup(prj_get_cxxtest_options()); // use relative file path instead of $(InputPath) to bypass cxxtestgen command line argument parsing weirdness const char *sourcename = path; tag_open("Tool"); tag_attr("Name=\"VCCustomBuildTool\""); tag_attr("Description=\"Generating %s\"", targetname); tag_attr("CommandLine=\"%s%s --part %s -o "%s" "%s"\"", endsWith(prj_get_cxxtestpath(), ".pl")?"perl ":"", path_translate(prj_get_cxxtestpath(), "windows"), testoptions, targetname, sourcename ); tag_attr("Outputs=\"%s\"", targetname); tag_close("Tool", 0); free(targetname); free(testoptions); } else /* (.asm doesn't need PCH) */ { tag_open("Tool"); tag_attr("Name=\"VCCLCompilerTool\""); tag_attr("UsePrecompiledHeader=\"1\""); tag_close("Tool", 0); } tag_close("FileConfiguration", 1); } } tag_close("File", 1); break; } }
int vs_write_cpp() { const char* str; int i, b; VsPkgData* data = (VsPkgData*)prj_get_data(); /* Open the file and write the header */ if (!io_openfile(path_join(prj_get_pkgpath(), prj_get_pkgname(), "vcproj"))) return 0; prj_select_config(0); io_print("<?xml version=\"1.0\" encoding=\"Windows-1252\"?>\n"); tag_open("VisualStudioProject"); tag_attr("ProjectType=\"Visual C++\""); switch (version) { case VS2002: str = "7.00"; break; case VS2003: str = "7.10"; break; case VS2005: str = "8.00"; break; case VS2008: str = "9.00"; break; } tag_attr("Version=\"%s\"", str); tag_attr("Name=\"%s\"", prj_get_pkgname()); tag_attr("ProjectGUID=\"{%s}\"", data->projGuid); if (version >= VS2005) tag_attr("RootNamespace=\"%s\"", prj_get_pkgname()); tag_attr("Keyword=\"%s\"", prj_has_flag("managed") ? "ManagedCProj" : "Win32Proj"); tag_open("Platforms"); tag_open("Platform"); tag_attr("Name=\"Win32\""); tag_close("Platform", 0); tag_close("Platforms", 1); if (version >= VS2005) { tag_open("ToolFiles"); tag_close("ToolFiles", 1); } /* Write configurations */ tag_open("Configurations"); for (i = 0; i < prj_get_numconfigs(); ++i) { int optimization, debug, runtime, symbols, configTypeId; const char* pchHeader = prj_get_pch_header(); prj_select_config(i); if (prj_is_kind("winexe") || prj_is_kind("exe") || prj_is_kind("cxxtestgen") || prj_is_kind("run")) { configTypeId = 1; } else if (prj_is_kind("dll")) { configTypeId = 2; } else if (prj_is_kind("lib")) { configTypeId = 4; } else if (prj_is_kind("aspnet")) { puts("** Error: C++ ASP.NET projects are not supported"); return 0; } else { printf("** Error: unknown package kind '%s'\n", prj_get_kind()); return 0; } if (prj_has_flag("optimize-speed")) optimization = 2; else if (prj_has_flag("optimize-size")) optimization = 1; else if (prj_has_flag("optimize")) optimization = 3; else optimization = 0; debug = (optimization ==0); if (prj_has_flag("static-runtime")) runtime = (debug) ? 1 : 0; else runtime = (debug) ? 3 : 2; if (prj_has_flag("no-symbols")) symbols = 0; else symbols = (prj_has_flag("managed") || prj_has_flag("no-edit-and-continue")) ? 3 : 4; tag_open("Configuration"); tag_attr("Name=\"%s|Win32\"", prj_get_cfgname()); tag_attr("OutputDirectory=\"%s\"", prj_get_outdir()); tag_attr("IntermediateDirectory=\"%s\"", prj_get_objdir()); tag_attr("ConfigurationType=\"%d\"", configTypeId); tag_attr("CharacterSet=\"%d\"", prj_has_flag("unicode") ? 1 : 2); if (prj_has_flag("managed")) tag_attr("ManagedExtensions=\"%s\"", S_TRUE); /* Write out tool blocks */ for (b = 0; blocks[version][b] != BlocksEnd; ++b) { tag_open("Tool"); switch (blocks[version][b]) { case VCPreBuildEventTool: tag_attr("Name=\"VCPreBuildEventTool\""); break; case VCCustomBuildTool: tag_attr("Name=\"VCCustomBuildTool\""); if (prj_is_kind("run")) { tag_attr("Description=\"Running CxxTest Test Suite\""); tag_attr_open("CommandLine"); print_list(prj_get_links(), "", "", " ", vs_filter_links); print_list(prj_get_buildoptions(), " ", "", "", NULL); tag_attr_close(); // This so that we're always run (and never "up-to-date") tag_attr("Outputs=\".\\dummy.file.thats.never.created\""); } else if (prj_is_kind("cxxtestgen")) { char *rootfile = strdup(prj_get_cxxtest_rootfile()); char *ctpath = strdup(path_translate(prj_get_cxxtestpath(), "windows")); char *options = strdup(prj_get_cxxtest_rootoptions()); tag_attr("Description=\"Generating test_root.cpp\""); tag_attr("CommandLine=\"%s%s --root %s -o "%s"\"", endsWith(prj_get_cxxtestpath(), ".pl")?"perl ":"", ctpath, options, rootfile); tag_attr("Outputs=\"%s\"", rootfile); free(options); free(ctpath); free(rootfile); } break; case VCXMLDataGeneratorTool: tag_attr("Name=\"VCXMLDataGeneratorTool\""); break; case VCManagedWrapperGeneratorTool: tag_attr("Name=\"VCManagedWrapperGeneratorTool\""); break; case VCAuxiliaryManagedWrapperGeneratorTool: tag_attr("Name=\"VCAuxiliaryManagedWrapperGeneratorTool\""); break; case VCWebServiceProxyGeneratorTool: tag_attr("Name=\"VCWebServiceProxyGeneratorTool\""); break; case VCMIDLTool: tag_attr("Name=\"VCMIDLTool\""); break; case VCManagedResourceCompilerTool: tag_attr("Name=\"VCManagedResourceCompilerTool\""); break; case VCResourceCompilerTool: tag_attr("Name=\"VCResourceCompilerTool\""); if (prj_get_numincpaths() > 0) { tag_attr_open("AdditionalIncludeDirectories"); print_list(prj_get_incpaths(), "", "", ";", NULL); tag_attr_close(); } break; case VCPreLinkEventTool: tag_attr("Name=\"VCPreLinkEventTool\""); break; case VCALinkTool: tag_attr("Name=\"VCALinkTool\""); break; case VCManifestTool: tag_attr("Name=\"VCManifestTool\""); break; case VCXDCMakeTool: tag_attr("Name=\"VCXDCMakeTool\""); break; case VCBscMakeTool: tag_attr("Name=\"VCBscMakeTool\""); break; case VCFxCopTool: tag_attr("Name=\"VCFxCopTool\""); break; case VCAppVerifierTool: tag_attr("Name=\"VCAppVerifierTool\""); break; case VCWebDeploymentTool: tag_attr("Name=\"VCWebDeploymentTool\""); break; case VCPostBuildEventTool: tag_attr("Name=\"VCPostBuildEventTool\""); break; case VCCLCompilerTool: tag_attr("Name=\"VCCLCompilerTool\""); if (prj_get_numbuildoptions() > 0) { tag_attr_open("AdditionalOptions"); print_list(prj_get_buildoptions(), "", "", " ", NULL); tag_attr_close(); } tag_attr("Optimization=\"%d\"", optimization); if (prj_has_flag("no-frame-pointer")) tag_attr("OmitFramePointers=\"%s\"", S_TRUE); if (prj_get_numincpaths() > 0) { tag_attr_open("AdditionalIncludeDirectories"); print_list(prj_get_incpaths(), "", "", ";", NULL); tag_attr_close(); } if (prj_has_flag("managed")) tag_attr("AdditionalUsingDirectories=\"%s\"", prj_get_bindir()); if (prj_get_numdefines() > 0) { tag_attr_open("PreprocessorDefinitions"); print_list(prj_get_defines(), "", "", ";", NULL); tag_attr_close(); } if (debug && !prj_has_flag("managed")) tag_attr("MinimalRebuild=\"%s\"", S_TRUE); if (prj_has_flag("no-exceptions")) tag_attr("ExceptionHandling=\"%s\"", S_FALSE); if (debug && !prj_has_flag("managed")) tag_attr("BasicRuntimeChecks=\"3\""); if (!debug) tag_attr("StringPooling=\"%s\"", S_TRUE); tag_attr("RuntimeLibrary=\"%d\"", runtime); tag_attr("EnableFunctionLevelLinking=\"%s\"", S_TRUE); if (version < VS2005 && !prj_has_flag("no-rtti")) tag_attr("RuntimeTypeInfo=\"%s\"", S_TRUE); if (version >= VS2005 && prj_has_flag("no-rtti")) tag_attr("RuntimeTypeInfo=\"%s\"", S_FALSE); if (version < VS2005 && prj_has_flag("native-wchar_t")) tag_attr("TreatWChar_tAsBuiltInType=\"%s\"", S_TRUE); if (version >= VS2005 && prj_has_flag("no-native-wchar_t")) tag_attr("TreatWChar_tAsBuiltInType=\"%s\"", S_FALSE); if (pchHeader) { tag_attr("UsePrecompiledHeader=\"%d\"", version < VS2005 ? 3 : 2); tag_attr("PrecompiledHeaderThrough=\"%s\"", pchHeader); } else tag_attr("UsePrecompiledHeader=\"%d\"", version < VS2005 ? 2 : 0); tag_attr("WarningLevel=\"%d\"", prj_has_flag("extra-warnings") ? 4 : 3); if (prj_has_flag("fatal-warnings")) tag_attr("WarnAsError=\"%s\"", S_TRUE); if (version < VS2008 && !prj_has_flag("managed")) tag_attr("Detect64BitPortabilityProblems=\"%s\"", prj_has_flag("no-64bit-checks") ? S_FALSE : S_TRUE); tag_attr("DebugInformationFormat=\"%d\"", symbols); break; case VCLinkerTool: if (!prj_is_kind("lib")) { tag_attr("Name=\"VCLinkerTool\""); if (prj_has_flag("no-import-lib")) tag_attr("IgnoreImportLibrary=\"%s\"", S_TRUE); if (prj_has_flag("use-library-dep-inputs") && version >= VS2005) tag_attr("UseLibraryDependencyInputs=\"%s\"", S_TRUE); if (prj_get_numlinkoptions() > 0) { tag_attr_open("AdditionalOptions"); print_list(prj_get_linkoptions(), " ", "", "", NULL); tag_attr_close(); } if (prj_get_numlinks() > 0) { tag_attr_open("AdditionalDependencies"); print_list(prj_get_links(), "", ".lib", " ", vs_filter_links); tag_attr_close(); } tag_attr("OutputFile=\"$(OutDir)/%s\"", path_getname(prj_get_target())); tag_attr("LinkIncremental=\"%d\"", debug ? 2 : 1); tag_attr_open("AdditionalLibraryDirectories"); io_print(prj_get_libdir()); print_list(prj_get_libpaths(), ";", "", "", NULL); tag_attr_close(); /* Look for a .def file for DLLs */ if (prj_find_filetype(".def") != NULL) tag_attr("ModuleDefinitionFile=\"%s\"", prj_find_filetype(".def")); if (prj_has_flag("no-manifest")) tag_attr("GenerateManifest=\"%s\"", S_FALSE); tag_attr("GenerateDebugInformation=\"%s\"", symbols ? S_TRUE : S_FALSE); if (symbols) tag_attr("ProgramDatabaseFile=\"$(OutDir)/%s.pdb\"", path_getbasename(prj_get_target())); tag_attr("SubSystem=\"%d\"", prj_is_kind("exe") ? 1 : 2); if (!debug) tag_attr("OptimizeReferences=\"2\""); if (!debug) tag_attr("EnableCOMDATFolding=\"2\""); if ((prj_is_kind("exe") || prj_is_kind("winexe")) && !prj_has_flag("no-main")) { tag_attr("EntryPointSymbol=\"mainCRTStartup\""); } else if (prj_is_kind("dll")) { tag_attr_open("ImportLibrary"); if (prj_has_flag("no-import-lib")) io_print(prj_get_objdir()); else io_print(prj_get_libdir()); io_print("/%s.lib", path_getbasename(prj_get_target())); tag_attr_close(); } tag_attr("TargetMachine=\"1\""); } else { tag_attr("Name=\"VCLibrarianTool\""); tag_attr("OutputFile=\"$(OutDir)/%s.lib\"", path_getbasename(prj_get_target())); } break; } tag_close("", 0); } tag_close("Configuration", 1); } tag_close("Configurations", 1); if (version > VS2002) { tag_open("References"); tag_close("References", 1); } tag_open("Files"); print_source_tree("", vs_list_files); /*if (prj_is_kind("cxxtestgen")) { char *rootfile = strdup(prj_get_cxxtest_rootfile()); char *ctpath = strdup(path_translate(prj_get_cxxtestpath(), "windows")); int i; tag_open("File"); tag_attr_open("RelativePath"); if (rootfile[0] != '.') io_print(".\\"); io_print(rootfile); tag_attr_close(); for (i = 0; i < prj_get_numconfigs(); ++i) { char *options; prj_select_config(i); options = strdup(prj_get_cxxtest_rootoptions()); tag_open("FileConfiguration"); tag_attr("Name=\"%s|Win32\"", prj_get_cfgname()); tag_open("Tool"); tag_attr("Name=\"VCCustomBuildTool\""); tag_attr("Description=\"Generating test_root.cpp\""); tag_attr("CommandLine=\"%s%s --root %s -o "%s"\"", endsWith(prj_get_cxxtestpath(), ".pl")?"perl ":"", ctpath, options, rootfile); tag_attr("Outputs=\"%s\"", rootfile); tag_close("Tool", 0); tag_close("FileConfiguration", 1); free(options); } tag_close("File", 1); free(ctpath); free(rootfile); }*/ tag_close("Files", 1); tag_open("Globals"); tag_close("Globals", 1); tag_close("VisualStudioProject", 1); io_closefile(); return 1; }
static void display_med(struct writer *w, lldpctl_atom_t *port) { lldpctl_atom_t *medpolicies, *medpolicy; lldpctl_atom_t *medlocations, *medlocation; lldpctl_atom_t *caelements, *caelement; long int cap = lldpctl_atom_get_int(port, lldpctl_k_chassis_med_cap); const char *type; if (lldpctl_atom_get_int(port, lldpctl_k_chassis_med_type) <= 0) return; tag_start(w, "lldp-med", "LLDP-MED"); tag_datatag(w, "device-type", "Device Type", lldpctl_atom_get_str(port, lldpctl_k_chassis_med_type)); display_med_capability(w, cap, LLDP_MED_CAP_CAP, "Capabilities"); display_med_capability(w, cap, LLDP_MED_CAP_POLICY, "Policy"); display_med_capability(w, cap, LLDP_MED_CAP_LOCATION, "Location"); display_med_capability(w, cap, LLDP_MED_CAP_MDI_PSE, "MDI/PSE"); display_med_capability(w, cap, LLDP_MED_CAP_MDI_PD, "MDI/PD"); display_med_capability(w, cap, LLDP_MED_CAP_IV, "Inventory"); /* LLDP MED policies */ medpolicies = lldpctl_atom_get(port, lldpctl_k_port_med_policies); lldpctl_atom_foreach(medpolicies, medpolicy) { if (lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_type) <= 0) continue; tag_start(w, "policy", "LLDP-MED Network Policy for"); tag_attr(w, "apptype", "", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_type)); tag_attr(w, "defined", "Defined", (lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_unknown) > 0)?"no":"yes"); if (lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_tagged) > 0) { int vid = lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_vid); tag_start(w, "vlan", "VLAN"); if (vid == 0) { tag_attr(w, "vid", "", "priority"); } else if (vid == 4095) { tag_attr(w, "vid", "", "reserved"); } else { tag_attr(w, "vid", "", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_vid)); } tag_end(w); } tag_datatag(w, "priority", "Priority", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_priority)); tag_datatag(w, "dscp", "DSCP Value", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_dscp)); tag_end(w); } lldpctl_atom_dec_ref(medpolicies); /* LLDP MED locations */ medlocations = lldpctl_atom_get(port, lldpctl_k_port_med_locations); lldpctl_atom_foreach(medlocations, medlocation) { int format = lldpctl_atom_get_int(medlocation, lldpctl_k_med_location_format); if (format <= 0) continue; tag_start(w, "location", "LLDP-MED Location Identification"); tag_attr(w, "type", "Type", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_format)); switch (format) { case LLDP_MED_LOCFORMAT_COORD: tag_attr(w, "geoid", "Geoid", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_geoid)); tag_datatag(w, "lat", "Latitude", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_latitude)); tag_datatag(w, "lon", "Longitude", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_longitude)); tag_start(w, "altitude", "Altitude"); tag_attr(w, "unit", "", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_altitude_unit)); tag_data(w, lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_altitude)); tag_end(w); break; case LLDP_MED_LOCFORMAT_CIVIC: tag_datatag(w, "country", "Country", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_country)); caelements = lldpctl_atom_get(medlocation, lldpctl_k_med_location_ca_elements); lldpctl_atom_foreach(caelements, caelement) { type = lldpctl_atom_get_str(caelement, lldpctl_k_med_civicaddress_type); tag_datatag(w, totag(type), type, lldpctl_atom_get_str(caelement, lldpctl_k_med_civicaddress_value)); } lldpctl_atom_dec_ref(caelements); break; case LLDP_MED_LOCFORMAT_ELIN: tag_datatag(w, "ecs", "ECS ELIN", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_elin)); break; }
static void display_med(struct writer *w, struct lldpd_chassis *chassis, struct lldpd_port *port) { int i; char *value; tag_start(w, "lldp-med", "LLDP-MED"); tag_datatag(w, "device-type", "Device Type", map_lookup(chassis_med_type_map, chassis->c_med_type)); display_med_capability(w, chassis, LLDPMED_CAP_CAP); display_med_capability(w, chassis, LLDPMED_CAP_POLICY); display_med_capability(w, chassis, LLDPMED_CAP_LOCATION); display_med_capability(w, chassis, LLDPMED_CAP_MDI_PSE); display_med_capability(w, chassis, LLDPMED_CAP_MDI_PD); display_med_capability(w, chassis, LLDPMED_CAP_IV); for (i = 0; i < LLDPMED_APPTYPE_LAST; i++) { if (i+1 == port->p_med_policy[i].type) { tag_start(w, "policy", "LLDP-MED Network Policy for"); tag_attr(w, "apptype", "AppType", u2str(port->p_med_policy[i].type)); tag_attr(w, "defined", "Defined", (port->p_med_policy[i].unknown)?"no":"yes"); tag_datatag(w, "descr", "", map_lookup(port_med_policy_map, port->p_med_policy[i].type)); if (port->p_med_policy[i].tagged) { tag_start(w, "vlan", "VLAN"); if (port->p_med_policy[i].vid == 0) { tag_attr(w, "vid", "", "priority"); } else if (port->p_med_policy[i].vid == 4095) { tag_attr(w, "vid", "", "reserved"); } else { tag_attr(w, "vid", "", u2str(port->p_med_policy[i].vid)); } tag_end(w); } tag_datatag(w, "priority", "Layer 2 Priority", u2str(port->p_med_policy[i].priority)); tag_datatag(w, "dscp", "DSCP Value", u2str(port->p_med_policy[i].dscp)); tag_end(w); } } for (i = 0; i < LLDPMED_LOCFORMAT_LAST; i++) { if (i+1 == port->p_med_location[i].format) { tag_start(w, "location", "LLDP-MED Location Identification"); switch(port->p_med_location[i].format) { case LLDPMED_LOCFORMAT_COORD: tag_attr(w, "type", "Type", "coordinates"); if (port->p_med_location[i].data_len != 16) { tag_datatag(w, "error", "Error", "bad data length"); } else { u_int64_t l; u_int8_t v; char * s; v = *(u_int8_t*)(port->p_med_location[i].data + 15); tag_attr(w, "geoid", "Geoid", map_lookup(port_med_geoid_map,v)); /* Latitude and longitude */ memcpy(&l, port->p_med_location[i].data, sizeof(u_int64_t)); l = (ntohll(l) & 0x03FFFFFFFF000000ULL) >> 24; display_latitude_or_longitude(w,0, l); memcpy(&l, port->p_med_location[i].data + 5, sizeof(u_int64_t)); l = (ntohll(l) & 0x03FFFFFFFF000000ULL) >> 24; display_latitude_or_longitude(w,1, l); /* Altitude */ memcpy(&l, port->p_med_location[i].data + 10, sizeof(u_int64_t)); l = (ntohll(l) & 0x3FFFFFFF000000ULL) >> 24; display_fixed_precision(l, 22, 8, 1, &s); tag_start(w, "altitude", "Altitude"); switch ((*(u_int8_t*)(port->p_med_location[i].data + 10)) & 0xf0) { case (1 << 4): tag_attr(w, "unit", "", "m"); break; case (2 << 4): tag_attr(w, "unit", "", "floor"); break; default: tag_attr(w, "unit", "", "unknown"); } tag_data(w,s); tag_end(w); } break; case LLDPMED_LOCFORMAT_CIVIC: tag_attr(w, "type", "Type", "address"); if ((port->p_med_location[i].data_len < 3) || (port->p_med_location[i].data_len - 1 != *(u_int8_t*)port->p_med_location[i].data)) { tag_datatag(w, "error", "Error", "bad data length"); } else { int l = 4, n, catype, calength; char country[3]; country[0] = ((char *)port->p_med_location[i].data)[2]; country[1] = ((char *)port->p_med_location[i].data)[3]; country[2] = 0; tag_datatag(w, "country", "Country", country); while ((n = (port-> p_med_location[i].data_len - l)) >= 2) { catype = *(u_int8_t*)(port-> p_med_location[i].data + l); calength = *(u_int8_t*)(port-> p_med_location[i].data + l + 1); if (n < 2 + calength) { tag_datatag(w, "error", "Error", "bad data length"); break; } if ((value = strndup((char *)(port-> p_med_location[i].data + l + 2), calength)) == NULL) { fatalx("not enough memory"); break; } tag_datatag(w, map_lookup(civic_address_type_tags,catype), map_lookup(civic_address_type_values,catype), value); free(value); l += 2 + calength; } } break; case LLDPMED_LOCFORMAT_ELIN: if ((value = strndup((char *)(port-> p_med_location[i].data), port->p_med_location[i].data_len)) == NULL) { fatalx( "not enough memory"); break; } tag_attr(w, "type", "Type", "elin"); tag_datatag(w, "ecs", "ECS ELIN", value); free(value); break; default: tag_attr(w, "type", "", "unknown"); tag_datatag(w, "unknown", "Data", dump(port->p_med_location[i].data, port->p_med_location[i].data_len, 20, ' ')); } tag_end(w); } }