Jun Furutani / libMiMic

Fork of libMiMic by Ryo Iizuka

Committer:
nyatla
Date:
Thu Aug 08 15:21:43 2013 +0000
Revision:
50:35e765380772
Parent:
37:fc4b4fd6a649
Child:
69:8c5f220441f5
bugfix; ????????????????; UPnP??????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyatla 37:fc4b4fd6a649 1 /*********************************************************************************
nyatla 37:fc4b4fd6a649 2 * PROJECT: MiMic
nyatla 37:fc4b4fd6a649 3 * --------------------------------------------------------------------------------
nyatla 37:fc4b4fd6a649 4 *
nyatla 37:fc4b4fd6a649 5 * This file is part of MiMic
nyatla 37:fc4b4fd6a649 6 * Copyright (C)2011 Ryo Iizuka
nyatla 37:fc4b4fd6a649 7 *
nyatla 37:fc4b4fd6a649 8 * MiMic is free software: you can redistribute it and/or modify
nyatla 37:fc4b4fd6a649 9 * it under the terms of the GNU Lesser General Public License as published
nyatla 37:fc4b4fd6a649 10 * by the Free Software Foundation, either version 3 of the License, or
nyatla 37:fc4b4fd6a649 11 * (at your option) any later version.
nyatla 37:fc4b4fd6a649 12 *
nyatla 37:fc4b4fd6a649 13 * This program is distributed in the hope that it will be useful,
nyatla 37:fc4b4fd6a649 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nyatla 37:fc4b4fd6a649 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nyatla 37:fc4b4fd6a649 16 * GNU General Public License for more details.
nyatla 37:fc4b4fd6a649 17 *
nyatla 37:fc4b4fd6a649 18 * You should have received a copy of the GNU Lesser General Public License
nyatla 37:fc4b4fd6a649 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
nyatla 37:fc4b4fd6a649 20 *
nyatla 37:fc4b4fd6a649 21 * For further information please contact.
nyatla 37:fc4b4fd6a649 22 * http://nyatla.jp/
nyatla 37:fc4b4fd6a649 23 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
nyatla 37:fc4b4fd6a649 24 *
nyatla 37:fc4b4fd6a649 25 *********************************************************************************/
nyatla 2:b96c1e90d120 26 #include "NyLPC_cNet.h"
nyatla 37:fc4b4fd6a649 27 #include "dhcp/NyLPC_cDhcpClient.h"
nyatla 50:35e765380772 28 #include "../uip/NyLPC_cUipService_protected.h"
nyatla 37:fc4b4fd6a649 29
nyatla 2:b96c1e90d120 30
nyatla 2:b96c1e90d120 31 const char* NyLPC_cNet_PlatformName;
nyatla 2:b96c1e90d120 32
nyatla 2:b96c1e90d120 33 static const char* PNAME_LPCXPRESSO1769="LPCXpresso1769";
nyatla 2:b96c1e90d120 34 static const char* PNAME_MBED="mbed";
nyatla 2:b96c1e90d120 35
nyatla 2:b96c1e90d120 36 void NyLPC_cNet_initialize(NyLPC_TcNet_t* i_inst)
nyatla 2:b96c1e90d120 37 {
nyatla 2:b96c1e90d120 38 //uipサービス初期化。いろいろ利用可能に。
nyatla 50:35e765380772 39 if(!NyLPC_TcUipService_isInitService()){
nyatla 50:35e765380772 40 NyLPC_cUipService_initialize();
nyatla 50:35e765380772 41 }
nyatla 2:b96c1e90d120 42 }
nyatla 2:b96c1e90d120 43
nyatla 2:b96c1e90d120 44 void NyLPC_cNet_start(NyLPC_TcNet_t* i_inst,const NyLPC_TcNetConfig_t* i_ref_config)
nyatla 2:b96c1e90d120 45 {
nyatla 37:fc4b4fd6a649 46 NyLPC_cUipService_start(&(i_ref_config->super));
nyatla 2:b96c1e90d120 47 //プラットフォーム名を推測(デバイス名の初めの1文字だけ見る。)
nyatla 2:b96c1e90d120 48 switch(*(NyLPC_cUipService_refDeviceName())){
nyatla 2:b96c1e90d120 49 case 'L':
nyatla 2:b96c1e90d120 50 NyLPC_cNet_PlatformName=PNAME_LPCXPRESSO1769;
nyatla 2:b96c1e90d120 51 break;
nyatla 2:b96c1e90d120 52 case 'D':
nyatla 2:b96c1e90d120 53 NyLPC_cNet_PlatformName=PNAME_MBED;
nyatla 2:b96c1e90d120 54 break;
nyatla 2:b96c1e90d120 55 default:
nyatla 2:b96c1e90d120 56 break;
nyatla 2:b96c1e90d120 57 }
nyatla 2:b96c1e90d120 58 return;
nyatla 37:fc4b4fd6a649 59 }
nyatla 37:fc4b4fd6a649 60
nyatla 37:fc4b4fd6a649 61 void NyLPC_cNet_stop(NyLPC_TcNet_t* i_inst)
nyatla 37:fc4b4fd6a649 62 {
nyatla 37:fc4b4fd6a649 63 NyLPC_cUipService_stop();
nyatla 37:fc4b4fd6a649 64 }
nyatla 37:fc4b4fd6a649 65
nyatla 37:fc4b4fd6a649 66 /**
nyatla 37:fc4b4fd6a649 67 * NyLPC_TcIPv4Config_tをDHCPで更新します。
nyatla 37:fc4b4fd6a649 68 * この関数をコールする時は、サービスは停止中でなければなりません。
nyatla 37:fc4b4fd6a649 69 * @param i_cfg
nyatla 37:fc4b4fd6a649 70 * 更新するi_cfg構造体。
nyatla 37:fc4b4fd6a649 71 * emac,default_mssは設定済である必要があります。他のフィールド値は不定で構いません。
nyatla 37:fc4b4fd6a649 72 * 更新されるフィールドは、ip,netmast,default_rootの3つです。
nyatla 37:fc4b4fd6a649 73 * @return
nyatla 37:fc4b4fd6a649 74 * 更新に成功した場合TRUE
nyatla 37:fc4b4fd6a649 75 */
nyatla 37:fc4b4fd6a649 76 NyLPC_TBool NyLPC_cNet_requestAddrDhcp(NyLPC_TcNet_t* i_net,NyLPC_TcIPv4Config_t* i_cfg,NyLPC_TInt16 i_repeat)
nyatla 37:fc4b4fd6a649 77 {
nyatla 37:fc4b4fd6a649 78 NyLPC_TBool ret;
nyatla 37:fc4b4fd6a649 79 NyLPC_TcDhcpClient_t sock;
nyatla 37:fc4b4fd6a649 80 //netを開始
nyatla 37:fc4b4fd6a649 81 NyLPC_cDhcpClient_initialize(&sock);
nyatla 37:fc4b4fd6a649 82 ret=NyLPC_cDhcpClient_requestAddr(&sock,i_cfg,i_repeat);
nyatla 37:fc4b4fd6a649 83 NyLPC_cDhcpClient_finalize(&sock);
nyatla 37:fc4b4fd6a649 84 return ret;
nyatla 37:fc4b4fd6a649 85 }
nyatla 37:fc4b4fd6a649 86 /**
nyatla 37:fc4b4fd6a649 87 * NyLPC_TcIPv4Config_tをAPIPAで更新します。
nyatla 37:fc4b4fd6a649 88 * この関数をコールする時は、サービスは停止中でなければなりません。
nyatla 37:fc4b4fd6a649 89 * @param i_cfg
nyatla 37:fc4b4fd6a649 90 * 更新するi_cfg構造体。
nyatla 37:fc4b4fd6a649 91 * emac,default_mssは設定済である必要があります。他のフィールド値は不定で構いません。
nyatla 37:fc4b4fd6a649 92 * 更新されるフィールドは、ip,netmast,default_rootの3つです。
nyatla 37:fc4b4fd6a649 93 * @return
nyatla 37:fc4b4fd6a649 94 * 更新に成功した場合TRUE
nyatla 37:fc4b4fd6a649 95 */
nyatla 37:fc4b4fd6a649 96 NyLPC_TBool NyLPC_cNet_requestAddrApipa(NyLPC_TcNet_t* i_net,NyLPC_TcIPv4Config_t* i_cfg,NyLPC_TInt16 i_repeat)
nyatla 37:fc4b4fd6a649 97 {
nyatla 37:fc4b4fd6a649 98 NyLPC_TBool ret;
nyatla 37:fc4b4fd6a649 99 NyLPC_TcApipa_t sock;
nyatla 37:fc4b4fd6a649 100 //netを開始
nyatla 37:fc4b4fd6a649 101 NyLPC_cApipa_initialize(&sock);
nyatla 37:fc4b4fd6a649 102 ret=NyLPC_cApipa_requestAddr(&sock,i_cfg,i_repeat);
nyatla 37:fc4b4fd6a649 103 NyLPC_cApipa_finalize(&sock);
nyatla 37:fc4b4fd6a649 104 return ret;
nyatla 37:fc4b4fd6a649 105 }