1 /******************************************************************************* 2 * Copyright (C) 2004-2008 Intel Corp. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * - Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. 9 * 10 * - Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * - Neither the name of Intel Corp. nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS 22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 *******************************************************************************/ 30 31 #ifdef HAVE_CONFIG_H 32 #include "config.h" 33 #endif 34 #include "ConfigConnection.h" 35 #include "Lock.h" 36 37 ConfigConnection::ConfigConnection(bool verbose) : 38 _initState(ConfigConnection::INIT_STATE_DISCONNECTED), 39 _pthiCommand(verbose, 5000), 40 _fwulCommand(verbose) 41 { 42 } 43 44 ConfigConnection::~ConfigConnection() 45 { 46 } 47 48 bool ConfigConnection::IsInitialized() 49 { 50 Lock il(_initLock); 51 return ((_initState == INIT_STATE_CONNECTED) ? true : false); 52 } 53 54 int ConfigConnection::IsAMTEnabled(bool useOpenPTHI) 55 { 56 FWU_GET_VERSION_MSG_REPLY verMsg; 57 FWU_GET_INFO_MSG_REPLY infoMsg; 58 HECI_STATUS heciRet; 59 int ret = _CFCON_AMT_UNKNOWN; 60 61 if (useOpenPTHI) { 62 CODE_VERSIONS ver; 63 AMT_STATUS ast = _pthiCommand.GetCodeVersions(ver); 64 if (PTHI_STATUS_EMPTY_RESPONSE == ast) { 65 return _CFCON_AMT_DISABLED; 66 } 67 if (AMT_STATUS_SUCCESS == ast) { 68 return _CFCON_AMT_ENABLED; 69 } 70 return ret; 71 } 72 73 if (_fwulCommand.FWULClient.Init()) { 74 heciRet = _fwulCommand.GetFWUVersionAndInfo(verMsg, infoMsg); 75 _fwulCommand.FWULClient.Deinit(); 76 if (HECI_STATUS_OK == heciRet) { 77 if (infoMsg.MessageType == FWU_GET_INFO_REPLY) { 78 return ((MEFWCAPS_MANAGEABILITY_SUPP_AMT 79 == infoMsg.ManageabilityMode) 80 ? _CFCON_AMT_ENABLED 81 : _CFCON_AMT_DISABLED); 82 } 83 ret = _CFCON_AMT_AT3; 84 } 85 } 86 87 return ret; 88 } 89 90 bool ConfigConnection::Init(bool checkEnabled) 91 { 92 { 93 Lock il(_initLock); 94 if (_initState == INIT_STATE_CONNECTING) { 95 return false; 96 } 97 _initState = INIT_STATE_CONNECTING; 98 } 99 100 if (!(_pthiCommand.PTHIClient.Init(1))) { 101 Deinit(); 102 return false; 103 } 104 105 if (checkEnabled) { 106 if (_CFCON_AMT_ENABLED != IsAMTEnabled(true)) { 107 Deinit(); 108 return false; 109 } 110 } 111 112 { 113 Lock il(_initLock); 114 if (_initState != INIT_STATE_CONNECTING) { 115 _pthiCommand.PTHIClient.Deinit(); 116 return false; 117 } 118 _initState = INIT_STATE_CONNECTED; 119 } 120 121 return true; 122 } 123 124 void ConfigConnection::Deinit() 125 { 126 Lock il(_initLock); 127 if (_initState != INIT_STATE_CONNECTING) { 128 _pthiCommand.PTHIClient.Deinit(); 129 } 130 _initState = INIT_STATE_DISCONNECTED; 131 } 132 133 #ifdef _REMOTE_SUPPORT 134 135 AMT_STATUS ConfigConnection::RequestEntDNSSuffixList(std::list<std::string> &dnsSuffixList) 136 { 137 Lock l(_requestLock); 138 139 { 140 Lock il(_initLock); 141 if (_initState != INIT_STATE_CONNECTED) { 142 return PTSDK_STATUS_INTERNAL_ERROR; 143 } 144 } 145 146 AMT_STATUS result = _pthiCommand.GetDNSSuffixList(dnsSuffixList); 147 148 if (result == AMT_STATUS_INTERNAL_ERROR) { 149 Lock il(_initLock); 150 if (!_pthiCommand.PTHIClient.IsInitialized()) { 151 _initState = INIT_STATE_DISCONNECTED; 152 } 153 } 154 155 return result; 156 } 157 158 AMT_STATUS ConfigConnection::SendEnterpriseAccess(bool access, ATAddress &localIp) 159 { 160 UINT8 hlocalIP[16]; 161 const struct sockaddr *addr = localIp.addr(); 162 163 Lock l(_requestLock); 164 165 { 166 Lock il(_initLock); 167 if (_initState != INIT_STATE_CONNECTED) { 168 return PTSDK_STATUS_INTERNAL_ERROR; 169 } 170 } 171 172 memset(hlocalIP, 0, sizeof(hlocalIP)); 173 memcpy(hlocalIP, addr->sa_data, localIp.size()); 174 175 AMT_STATUS result = _pthiCommand.SetEnterpriseAccess( 176 ((localIp.family() == AF_INET6) ? 1 : 0), 177 hlocalIP, 178 ((access) ? 1 : 0)); 179 180 if (result == AMT_STATUS_INTERNAL_ERROR) { 181 Lock il(_initLock); 182 if (!_pthiCommand.PTHIClient.IsInitialized()) { 183 _initState = INIT_STATE_DISCONNECTED; 184 } 185 } 186 187 return result; 188 } 189 190 #endif 191 192